diff --git a/builtin/providers/aws/resource_aws_autoscaling_schedule.go b/builtin/providers/aws/resource_aws_autoscaling_schedule.go index 5b43db46d..5a6a89291 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_schedule.go +++ b/builtin/providers/aws/resource_aws_autoscaling_schedule.go @@ -20,48 +20,48 @@ func resourceAwsAutoscalingSchedule() *schema.Resource { Delete: resourceAwsAutoscalingScheduleDelete, Schema: map[string]*schema.Schema{ - "arn": &schema.Schema{ + "arn": { Type: schema.TypeString, Computed: true, }, - "scheduled_action_name": &schema.Schema{ + "scheduled_action_name": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "autoscaling_group_name": &schema.Schema{ + "autoscaling_group_name": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "start_time": &schema.Schema{ + "start_time": { Type: schema.TypeString, Optional: true, Computed: true, ValidateFunc: validateASGScheduleTimestamp, }, - "end_time": &schema.Schema{ + "end_time": { Type: schema.TypeString, Optional: true, Computed: true, ValidateFunc: validateASGScheduleTimestamp, }, - "recurrence": &schema.Schema{ + "recurrence": { Type: schema.TypeString, Optional: true, Computed: true, }, - "min_size": &schema.Schema{ + "min_size": { Type: schema.TypeInt, Optional: true, Computed: true, }, - "max_size": &schema.Schema{ + "max_size": { Type: schema.TypeInt, Optional: true, Computed: true, }, - "desired_capacity": &schema.Schema{ + "desired_capacity": { Type: schema.TypeInt, Optional: true, Computed: true, diff --git a/builtin/providers/aws/resource_aws_autoscaling_schedule_test.go b/builtin/providers/aws/resource_aws_autoscaling_schedule_test.go index 7a220f24d..190934128 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_schedule_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_schedule_test.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "testing" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/autoscaling" @@ -13,16 +14,26 @@ import ( func TestAccAWSAutoscalingSchedule_basic(t *testing.T) { var schedule autoscaling.ScheduledUpdateGroupAction - 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{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccAWSAutoscalingScheduleConfig(rName), + { + Config: testAccAWSAutoscalingScheduleConfig(rName, start, end), Check: resource.ComposeTestCheckFunc( testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule), ), @@ -34,13 +45,25 @@ func TestAccAWSAutoscalingSchedule_basic(t *testing.T) { func TestAccAWSAutoscalingSchedule_disappears(t *testing.T) { var schedule autoscaling.ScheduledUpdateGroupAction 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{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccAWSAutoscalingScheduleConfig(rName), + { + Config: testAccAWSAutoscalingScheduleConfig(rName, start, end), Check: resource.ComposeTestCheckFunc( testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule), testAccCheckScalingScheduleDisappears(&schedule), @@ -74,7 +97,7 @@ func TestAccAWSAutoscalingSchedule_recurrence(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccAWSAutoscalingScheduleConfig_recurrence(rName), Check: resource.ComposeTestCheckFunc( testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule), @@ -159,7 +182,7 @@ func testAccCheckAWSAutoscalingScheduleDestroy(s *terraform.State) error { return nil } -func testAccAWSAutoscalingScheduleConfig(r string) string { +func testAccAWSAutoscalingScheduleConfig(r, start, end string) string { return fmt.Sprintf(` resource "aws_launch_configuration" "foobar" { name = "%s" @@ -189,10 +212,10 @@ resource "aws_autoscaling_schedule" "foobar" { min_size = 0 max_size = 1 desired_capacity = 0 - start_time = "2016-12-11T18:00:00Z" - end_time = "2016-12-12T06:00:00Z" + start_time = "%s" + end_time = "%s" autoscaling_group_name = "${aws_autoscaling_group.foobar.name}" -}`, r, r) +}`, r, r, start, end) } func testAccAWSAutoscalingScheduleConfig_recurrence(r string) string {