Merge pull request #11522 from hashicorp/b-fix-asg-schedule-acctests

provider/aws: Fix acceptance tests for autoscaling schedule
This commit is contained in:
Jake Champlin 2017-01-30 15:47:34 -05:00 committed by GitHub
commit 3c0fdc4764
2 changed files with 42 additions and 19 deletions

View File

@ -20,48 +20,48 @@ func resourceAwsAutoscalingSchedule() *schema.Resource {
Delete: resourceAwsAutoscalingScheduleDelete, Delete: resourceAwsAutoscalingScheduleDelete,
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"arn": &schema.Schema{ "arn": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"scheduled_action_name": &schema.Schema{ "scheduled_action_name": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
}, },
"autoscaling_group_name": &schema.Schema{ "autoscaling_group_name": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
}, },
"start_time": &schema.Schema{ "start_time": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true, Computed: true,
ValidateFunc: validateASGScheduleTimestamp, ValidateFunc: validateASGScheduleTimestamp,
}, },
"end_time": &schema.Schema{ "end_time": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true, Computed: true,
ValidateFunc: validateASGScheduleTimestamp, ValidateFunc: validateASGScheduleTimestamp,
}, },
"recurrence": &schema.Schema{ "recurrence": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"min_size": &schema.Schema{ "min_size": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"max_size": &schema.Schema{ "max_size": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"desired_capacity": &schema.Schema{ "desired_capacity": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Computed: true, Computed: true,

View File

@ -3,6 +3,7 @@ package aws
import ( import (
"fmt" "fmt"
"testing" "testing"
"time"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscaling" "github.com/aws/aws-sdk-go/service/autoscaling"
@ -13,16 +14,26 @@ import (
func TestAccAWSAutoscalingSchedule_basic(t *testing.T) { func TestAccAWSAutoscalingSchedule_basic(t *testing.T) {
var schedule autoscaling.ScheduledUpdateGroupAction var schedule autoscaling.ScheduledUpdateGroupAction
rName := fmt.Sprintf("tf-test-%d", acctest.RandInt()) rName := fmt.Sprintf("tf-test-%d", acctest.RandInt())
n := time.Now().UTC()
d, err := time.ParseDuration("2h")
if err != nil {
t.Fatalf("err parsing time duration: %s", err)
}
s, err := time.ParseDuration("1h")
if err != nil {
t.Fatalf("err parsing time duration: %s", err)
}
start := n.Add(s).Format(awsAutoscalingScheduleTimeLayout)
end := n.Add(d).Format(awsAutoscalingScheduleTimeLayout)
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy, CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSAutoscalingScheduleConfig(rName), Config: testAccAWSAutoscalingScheduleConfig(rName, start, end),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule), testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule),
), ),
@ -34,13 +45,25 @@ func TestAccAWSAutoscalingSchedule_basic(t *testing.T) {
func TestAccAWSAutoscalingSchedule_disappears(t *testing.T) { func TestAccAWSAutoscalingSchedule_disappears(t *testing.T) {
var schedule autoscaling.ScheduledUpdateGroupAction var schedule autoscaling.ScheduledUpdateGroupAction
rName := fmt.Sprintf("tf-test-%d", acctest.RandInt()) rName := fmt.Sprintf("tf-test-%d", acctest.RandInt())
n := time.Now().UTC()
d, err := time.ParseDuration("2h")
if err != nil {
t.Fatalf("err parsing time duration: %s", err)
}
s, err := time.ParseDuration("1h")
if err != nil {
t.Fatalf("err parsing time duration: %s", err)
}
start := n.Add(s).Format(awsAutoscalingScheduleTimeLayout)
end := n.Add(d).Format(awsAutoscalingScheduleTimeLayout)
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy, CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSAutoscalingScheduleConfig(rName), Config: testAccAWSAutoscalingScheduleConfig(rName, start, end),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule), testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule),
testAccCheckScalingScheduleDisappears(&schedule), testAccCheckScalingScheduleDisappears(&schedule),
@ -74,7 +97,7 @@ func TestAccAWSAutoscalingSchedule_recurrence(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy, CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSAutoscalingScheduleConfig_recurrence(rName), Config: testAccAWSAutoscalingScheduleConfig_recurrence(rName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule), testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule),
@ -159,7 +182,7 @@ func testAccCheckAWSAutoscalingScheduleDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccAWSAutoscalingScheduleConfig(r string) string { func testAccAWSAutoscalingScheduleConfig(r, start, end string) string {
return fmt.Sprintf(` return fmt.Sprintf(`
resource "aws_launch_configuration" "foobar" { resource "aws_launch_configuration" "foobar" {
name = "%s" name = "%s"
@ -189,10 +212,10 @@ resource "aws_autoscaling_schedule" "foobar" {
min_size = 0 min_size = 0
max_size = 1 max_size = 1
desired_capacity = 0 desired_capacity = 0
start_time = "2016-12-11T18:00:00Z" start_time = "%s"
end_time = "2016-12-12T06:00:00Z" end_time = "%s"
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}" autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
}`, r, r) }`, r, r, start, end)
} }
func testAccAWSAutoscalingScheduleConfig_recurrence(r string) string { func testAccAWSAutoscalingScheduleConfig_recurrence(r string) string {