Merge pull request #5101 from tpounds/fix-read-aws-asg-termination-policies
provider/aws: Fix reading auto scaling group termination policies
This commit is contained in:
commit
b5e6a4fac7
|
@ -255,7 +255,16 @@ func resourceAwsAutoscalingGroupRead(d *schema.ResourceData, meta interface{}) e
|
||||||
d.Set("name", g.AutoScalingGroupName)
|
d.Set("name", g.AutoScalingGroupName)
|
||||||
d.Set("tag", g.Tags)
|
d.Set("tag", g.Tags)
|
||||||
d.Set("vpc_zone_identifier", strings.Split(*g.VPCZoneIdentifier, ","))
|
d.Set("vpc_zone_identifier", strings.Split(*g.VPCZoneIdentifier, ","))
|
||||||
d.Set("termination_policies", g.TerminationPolicies)
|
|
||||||
|
// If no termination polices are explicitly configured and the upstream state
|
||||||
|
// is only using the "Default" policy, clear the state to make it consistent
|
||||||
|
// with the default AWS create API behavior.
|
||||||
|
_, ok := d.GetOk("termination_policies")
|
||||||
|
if !ok && len(g.TerminationPolicies) == 1 && *g.TerminationPolicies[0] == "Default" {
|
||||||
|
d.Set("termination_policies", []interface{}{})
|
||||||
|
} else {
|
||||||
|
d.Set("termination_policies", flattenStringList(g.TerminationPolicies))
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -316,18 +325,11 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{})
|
||||||
if d.HasChange("termination_policies") {
|
if d.HasChange("termination_policies") {
|
||||||
// If the termination policy is set to null, we need to explicitly set
|
// If the termination policy is set to null, we need to explicitly set
|
||||||
// it back to "Default", or the API won't reset it for us.
|
// it back to "Default", or the API won't reset it for us.
|
||||||
// This means GetOk() will fail us on the zero check.
|
if v, ok := d.GetOk("termination_policies"); ok && len(v.([]interface{})) > 0 {
|
||||||
v := d.Get("termination_policies")
|
|
||||||
if len(v.([]interface{})) > 0 {
|
|
||||||
opts.TerminationPolicies = expandStringList(v.([]interface{}))
|
opts.TerminationPolicies = expandStringList(v.([]interface{}))
|
||||||
} else {
|
} else {
|
||||||
// Policies is a slice of string pointers, so build one.
|
|
||||||
// Maybe there's a better idiom for this?
|
|
||||||
log.Printf("[DEBUG] Explictly setting null termination policy to 'Default'")
|
log.Printf("[DEBUG] Explictly setting null termination policy to 'Default'")
|
||||||
pol := "Default"
|
opts.TerminationPolicies = aws.StringSlice([]string{"Default"})
|
||||||
s := make([]*string, 1, 1)
|
|
||||||
s[0] = &pol
|
|
||||||
opts.TerminationPolicies = s
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,51 @@ func TestAccAWSAutoScalingGroup_autoGeneratedName(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSAutoScalingGroup_terminationPolicies(t *testing.T) {
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSAutoScalingGroupConfig_terminationPoliciesEmpty,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_autoscaling_group.bar", "termination_policies.#", "0"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSAutoScalingGroupConfig_terminationPoliciesUpdate,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_autoscaling_group.bar", "termination_policies.#", "1"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_autoscaling_group.bar", "termination_policies.0", "OldestInstance"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSAutoScalingGroupConfig_terminationPoliciesExplicitDefault,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_autoscaling_group.bar", "termination_policies.#", "1"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_autoscaling_group.bar", "termination_policies.0", "Default"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSAutoScalingGroupConfig_terminationPoliciesEmpty,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_autoscaling_group.bar", "termination_policies.#", "0"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAWSAutoScalingGroup_tags(t *testing.T) {
|
func TestAccAWSAutoScalingGroup_tags(t *testing.T) {
|
||||||
var group autoscaling.Group
|
var group autoscaling.Group
|
||||||
|
|
||||||
|
@ -415,6 +460,56 @@ resource "aws_autoscaling_group" "bar" {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testAccAWSAutoScalingGroupConfig_terminationPoliciesEmpty = `
|
||||||
|
resource "aws_launch_configuration" "foobar" {
|
||||||
|
image_id = "ami-21f78e11"
|
||||||
|
instance_type = "t1.micro"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_autoscaling_group" "bar" {
|
||||||
|
availability_zones = ["us-west-2a"]
|
||||||
|
max_size = 0
|
||||||
|
min_size = 0
|
||||||
|
desired_capacity = 0
|
||||||
|
|
||||||
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const testAccAWSAutoScalingGroupConfig_terminationPoliciesExplicitDefault = `
|
||||||
|
resource "aws_launch_configuration" "foobar" {
|
||||||
|
image_id = "ami-21f78e11"
|
||||||
|
instance_type = "t1.micro"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_autoscaling_group" "bar" {
|
||||||
|
availability_zones = ["us-west-2a"]
|
||||||
|
max_size = 0
|
||||||
|
min_size = 0
|
||||||
|
desired_capacity = 0
|
||||||
|
termination_policies = ["Default"]
|
||||||
|
|
||||||
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const testAccAWSAutoScalingGroupConfig_terminationPoliciesUpdate = `
|
||||||
|
resource "aws_launch_configuration" "foobar" {
|
||||||
|
image_id = "ami-21f78e11"
|
||||||
|
instance_type = "t1.micro"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_autoscaling_group" "bar" {
|
||||||
|
availability_zones = ["us-west-2a"]
|
||||||
|
max_size = 0
|
||||||
|
min_size = 0
|
||||||
|
desired_capacity = 0
|
||||||
|
termination_policies = ["OldestInstance"]
|
||||||
|
|
||||||
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
const testAccAWSAutoScalingGroupConfig = `
|
const testAccAWSAutoScalingGroupConfig = `
|
||||||
resource "aws_launch_configuration" "foobar" {
|
resource "aws_launch_configuration" "foobar" {
|
||||||
image_id = "ami-21f78e11"
|
image_id = "ami-21f78e11"
|
||||||
|
|
Loading…
Reference in New Issue