Skip to content

Commit ea45958

Browse files
committed
Merge pull request hashicorp#4674 from stack72/carl-youngblood/master
Fix recurrence on `aws_autoscaling_schedule` resource
2 parents e94ee6b + 5c68858 commit ea45958

2 files changed

Lines changed: 63 additions & 4 deletions

File tree

builtin/providers/aws/resource_aws_autoscaling_schedule.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func resourceAwsAutoscalingScheduleCreate(d *schema.ResourceData, meta interface
9393
params.EndTime = aws.Time(t)
9494
}
9595

96-
if attr, ok := d.GetOk("recurrance"); ok {
96+
if attr, ok := d.GetOk("recurrence"); ok {
9797
params.Recurrence = aws.String(attr.(string))
9898
}
9999

@@ -131,9 +131,15 @@ func resourceAwsAutoscalingScheduleRead(d *schema.ResourceData, meta interface{}
131131
d.Set("desired_capacity", sa.DesiredCapacity)
132132
d.Set("min_size", sa.MinSize)
133133
d.Set("max_size", sa.MaxSize)
134-
d.Set("recurrance", sa.Recurrence)
135-
d.Set("start_time", sa.StartTime.Format(awsAutoscalingScheduleTimeLayout))
136-
d.Set("end_time", sa.EndTime.Format(awsAutoscalingScheduleTimeLayout))
134+
d.Set("recurrence", sa.Recurrence)
135+
136+
if sa.StartTime != nil {
137+
d.Set("start_time", sa.StartTime.Format(awsAutoscalingScheduleTimeLayout))
138+
}
139+
140+
if sa.EndTime != nil {
141+
d.Set("end_time", sa.EndTime.Format(awsAutoscalingScheduleTimeLayout))
142+
}
137143

138144
return nil
139145
}

builtin/providers/aws/resource_aws_autoscaling_schedule_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ func TestAccAWSAutoscalingSchedule_basic(t *testing.T) {
2828
})
2929
}
3030

31+
func TestAccAWSAutoscalingSchedule_recurrence(t *testing.T) {
32+
var schedule autoscaling.ScheduledUpdateGroupAction
33+
34+
resource.Test(t, resource.TestCase{
35+
PreCheck: func() { testAccPreCheck(t) },
36+
Providers: testAccProviders,
37+
CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy,
38+
Steps: []resource.TestStep{
39+
resource.TestStep{
40+
Config: testAccAWSAutoscalingScheduleConfig_recurrence,
41+
Check: resource.ComposeTestCheckFunc(
42+
testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule),
43+
resource.TestCheckResourceAttr("aws_autoscaling_schedule.foobar", "recurrence", "0 8 * * *"),
44+
),
45+
},
46+
},
47+
})
48+
}
49+
3150
func testAccCheckScalingScheduleExists(n string, policy *autoscaling.ScheduledUpdateGroupAction) resource.TestCheckFunc {
3251
return func(s *terraform.State) error {
3352
rs, ok := s.RootModule().Resources[n]
@@ -115,3 +134,37 @@ resource "aws_autoscaling_schedule" "foobar" {
115134
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
116135
}
117136
`)
137+
138+
var testAccAWSAutoscalingScheduleConfig_recurrence = fmt.Sprintf(`
139+
resource "aws_launch_configuration" "foobar" {
140+
name = "terraform-test-foobar5"
141+
image_id = "ami-21f78e11"
142+
instance_type = "t1.micro"
143+
}
144+
145+
resource "aws_autoscaling_group" "foobar" {
146+
availability_zones = ["us-west-2a"]
147+
name = "terraform-test-foobar5"
148+
max_size = 1
149+
min_size = 1
150+
health_check_grace_period = 300
151+
health_check_type = "ELB"
152+
force_delete = true
153+
termination_policies = ["OldestInstance"]
154+
launch_configuration = "${aws_launch_configuration.foobar.name}"
155+
tag {
156+
key = "Foo"
157+
value = "foo-bar"
158+
propagate_at_launch = true
159+
}
160+
}
161+
162+
resource "aws_autoscaling_schedule" "foobar" {
163+
scheduled_action_name = "foobar"
164+
min_size = 0
165+
max_size = 1
166+
desired_capacity = 0
167+
recurrence = "0 8 * * *"
168+
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
169+
}
170+
`)

0 commit comments

Comments
 (0)