provider/aws: Fix issue in upgrading AutoScaling Policy (#6440)
* provider/aws: Fix issue in upgrading AutoScaling Policy min_adjustment_steps - Update depreciation message on min_adjustment_step
This commit is contained in:
parent
83f87e3741
commit
068f6f606d
|
@ -61,7 +61,7 @@ func resourceAwsAutoscalingPolicy() *schema.Resource {
|
||||||
"min_adjustment_step": &schema.Schema{
|
"min_adjustment_step": &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Deprecated: "Use min_adjustment_magnitude instead.",
|
Deprecated: "Use min_adjustment_magnitude instead, otherwise you may see a perpetual diff on this resource.",
|
||||||
ConflictsWith: []string{"min_adjustment_magnitude"},
|
ConflictsWith: []string{"min_adjustment_magnitude"},
|
||||||
},
|
},
|
||||||
"scaling_adjustment": &schema.Schema{
|
"scaling_adjustment": &schema.Schema{
|
||||||
|
@ -126,7 +126,7 @@ func resourceAwsAutoscalingPolicyRead(d *schema.ResourceData, meta interface{})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] Read Scaling Policy: ASG: %s, SP: %s, Obj: %#v", d.Get("autoscaling_group_name"), d.Get("name"), p)
|
log.Printf("[DEBUG] Read Scaling Policy: ASG: %s, SP: %s, Obj: %s", d.Get("autoscaling_group_name"), d.Get("name"), p)
|
||||||
|
|
||||||
d.Set("adjustment_type", p.AdjustmentType)
|
d.Set("adjustment_type", p.AdjustmentType)
|
||||||
d.Set("autoscaling_group_name", p.AutoScalingGroupName)
|
d.Set("autoscaling_group_name", p.AutoScalingGroupName)
|
||||||
|
@ -134,8 +134,12 @@ func resourceAwsAutoscalingPolicyRead(d *schema.ResourceData, meta interface{})
|
||||||
d.Set("estimated_instance_warmup", p.EstimatedInstanceWarmup)
|
d.Set("estimated_instance_warmup", p.EstimatedInstanceWarmup)
|
||||||
d.Set("metric_aggregation_type", p.MetricAggregationType)
|
d.Set("metric_aggregation_type", p.MetricAggregationType)
|
||||||
d.Set("policy_type", p.PolicyType)
|
d.Set("policy_type", p.PolicyType)
|
||||||
|
if p.MinAdjustmentMagnitude != nil {
|
||||||
d.Set("min_adjustment_magnitude", p.MinAdjustmentMagnitude)
|
d.Set("min_adjustment_magnitude", p.MinAdjustmentMagnitude)
|
||||||
|
d.Set("min_adjustment_step", 0)
|
||||||
|
} else {
|
||||||
d.Set("min_adjustment_step", p.MinAdjustmentStep)
|
d.Set("min_adjustment_step", p.MinAdjustmentStep)
|
||||||
|
}
|
||||||
d.Set("arn", p.PolicyARN)
|
d.Set("arn", p.PolicyARN)
|
||||||
d.Set("name", p.PolicyName)
|
d.Set("name", p.PolicyName)
|
||||||
d.Set("scaling_adjustment", p.ScalingAdjustment)
|
d.Set("scaling_adjustment", p.ScalingAdjustment)
|
||||||
|
@ -175,6 +179,7 @@ func resourceAwsAutoscalingPolicyDelete(d *schema.ResourceData, meta interface{}
|
||||||
AutoScalingGroupName: aws.String(d.Get("autoscaling_group_name").(string)),
|
AutoScalingGroupName: aws.String(d.Get("autoscaling_group_name").(string)),
|
||||||
PolicyName: aws.String(d.Get("name").(string)),
|
PolicyName: aws.String(d.Get("name").(string)),
|
||||||
}
|
}
|
||||||
|
log.Printf("[DEBUG] Deleting Autoscaling Policy opts: %s", params)
|
||||||
if _, err := autoscalingconn.DeletePolicy(¶ms); err != nil {
|
if _, err := autoscalingconn.DeletePolicy(¶ms); err != nil {
|
||||||
return fmt.Errorf("Autoscaling Scaling Policy: %s ", err)
|
return fmt.Errorf("Autoscaling Scaling Policy: %s ", err)
|
||||||
}
|
}
|
||||||
|
@ -225,10 +230,10 @@ func getAwsAutoscalingPutScalingPolicyInput(d *schema.ResourceData) (autoscaling
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("min_adjustment_magnitude"); ok {
|
if v, ok := d.GetOk("min_adjustment_magnitude"); ok {
|
||||||
|
// params.MinAdjustmentMagnitude = aws.Int64(int64(d.Get("min_adjustment_magnitude").(int)))
|
||||||
params.MinAdjustmentMagnitude = aws.Int64(int64(v.(int)))
|
params.MinAdjustmentMagnitude = aws.Int64(int64(v.(int)))
|
||||||
}
|
} else if v, ok := d.GetOk("min_adjustment_step"); ok {
|
||||||
|
// params.MinAdjustmentStep = aws.Int64(int64(d.Get("min_adjustment_step").(int)))
|
||||||
if v, ok := d.GetOk("min_adjustment_step"); ok {
|
|
||||||
params.MinAdjustmentStep = aws.Int64(int64(v.(int)))
|
params.MinAdjustmentStep = aws.Int64(int64(v.(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"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"
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -41,6 +42,38 @@ func TestAccAWSAutoscalingPolicy_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSAutoscalingPolicy_upgrade(t *testing.T) {
|
||||||
|
var policy autoscaling.ScalingPolicy
|
||||||
|
|
||||||
|
name := acctest.RandString(5)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSAutoscalingPolicyDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSAutoscalingPolicyConfig_upgrade_614(name),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckScalingPolicyExists("aws_autoscaling_policy.foobar_simple", &policy),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "min_adjustment_step", "0"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "min_adjustment_magnitude", "1"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSAutoscalingPolicyConfig_upgrade_615(name),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckScalingPolicyExists("aws_autoscaling_policy.foobar_simple", &policy),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "min_adjustment_step", "0"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "min_adjustment_magnitude", "1"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckScalingPolicyExists(n string, policy *autoscaling.ScalingPolicy) resource.TestCheckFunc {
|
func testAccCheckScalingPolicyExists(n string, policy *autoscaling.ScalingPolicy) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -137,3 +170,79 @@ resource "aws_autoscaling_policy" "foobar_step" {
|
||||||
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
|
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
func testAccAWSAutoscalingPolicyConfig_upgrade_614(name string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "aws_launch_configuration" "foobar" {
|
||||||
|
name = "tf-test-%s"
|
||||||
|
image_id = "ami-21f78e11"
|
||||||
|
instance_type = "t1.micro"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_autoscaling_group" "foobar" {
|
||||||
|
availability_zones = ["us-west-2a"]
|
||||||
|
name = "terraform-test-%s"
|
||||||
|
max_size = 5
|
||||||
|
min_size = 1
|
||||||
|
health_check_grace_period = 300
|
||||||
|
health_check_type = "ELB"
|
||||||
|
force_delete = true
|
||||||
|
termination_policies = ["OldestInstance"]
|
||||||
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
||||||
|
|
||||||
|
tag {
|
||||||
|
key = "Foo"
|
||||||
|
value = "foo-bar"
|
||||||
|
propagate_at_launch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_autoscaling_policy" "foobar_simple" {
|
||||||
|
name = "foobar_simple_%s"
|
||||||
|
adjustment_type = "PercentChangeInCapacity"
|
||||||
|
cooldown = 300
|
||||||
|
policy_type = "SimpleScaling"
|
||||||
|
scaling_adjustment = 2
|
||||||
|
min_adjustment_step = 1
|
||||||
|
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
|
||||||
|
}
|
||||||
|
`, name, name, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccAWSAutoscalingPolicyConfig_upgrade_615(name string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "aws_launch_configuration" "foobar" {
|
||||||
|
name = "tf-test-%s"
|
||||||
|
image_id = "ami-21f78e11"
|
||||||
|
instance_type = "t1.micro"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_autoscaling_group" "foobar" {
|
||||||
|
availability_zones = ["us-west-2a"]
|
||||||
|
name = "terraform-test-%s"
|
||||||
|
max_size = 5
|
||||||
|
min_size = 1
|
||||||
|
health_check_grace_period = 300
|
||||||
|
health_check_type = "ELB"
|
||||||
|
force_delete = true
|
||||||
|
termination_policies = ["OldestInstance"]
|
||||||
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
||||||
|
|
||||||
|
tag {
|
||||||
|
key = "Foo"
|
||||||
|
value = "foo-bar"
|
||||||
|
propagate_at_launch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_autoscaling_policy" "foobar_simple" {
|
||||||
|
name = "foobar_simple_%s"
|
||||||
|
adjustment_type = "PercentChangeInCapacity"
|
||||||
|
cooldown = 300
|
||||||
|
policy_type = "SimpleScaling"
|
||||||
|
scaling_adjustment = 2
|
||||||
|
min_adjustment_magnitude = 1
|
||||||
|
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
|
||||||
|
}
|
||||||
|
`, name, name, name)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue