From ea86e6d2d320d9e30748311c710c0138ab38c406 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 14 Jul 2020 09:26:00 -0400 Subject: [PATCH] resource/aws_autoscaling_group: Finalize availability_zones and vpc_zone_identifier ConflictsWith Reference: https://github.com/terraform-providers/terraform-provider-aws/pull/12927 Output from acceptance testing: ``` --- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups (149.76s) --- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity (305.03s) --- PASS: TestAccAWSAutoScalingGroup_autoGeneratedName (48.42s) --- PASS: TestAccAWSAutoScalingGroup_basic (263.71s) --- PASS: TestAccAWSAutoScalingGroup_classicVpcZoneIdentifier (110.01s) --- PASS: TestAccAWSAutoScalingGroup_enablingMetrics (201.08s) --- PASS: TestAccAWSAutoScalingGroup_initialLifecycleHook (343.64s) --- PASS: TestAccAWSAutoScalingGroup_launchTemplate (40.12s) --- PASS: TestAccAWSAutoScalingGroup_LaunchTemplate_IAMInstanceProfile (61.25s) --- PASS: TestAccAWSAutoScalingGroup_launchTemplate_update (139.49s) --- PASS: TestAccAWSAutoScalingGroup_launchTempPartitionNum (45.25s) --- PASS: TestAccAWSAutoScalingGroup_LoadBalancers (703.48s) --- PASS: TestAccAWSAutoScalingGroup_MaxInstanceLifetime (79.42s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy (266.34s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandAllocationStrategy (106.47s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandBaseCapacity (79.45s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandPercentageAboveBaseCapacity (48.15s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotAllocationStrategy (96.45s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotInstancePools (72.86s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotMaxPrice (77.33s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_UpdateToZeroOnDemandBaseCapacity (45.55s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_LaunchTemplateName (52.49s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_Version (73.51s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_InstanceType (76.41s) --- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_WeightedCapacity (161.24s) --- PASS: TestAccAWSAutoScalingGroup_namePrefix (55.45s) --- PASS: TestAccAWSAutoScalingGroup_serviceLinkedRoleARN (48.37s) --- PASS: TestAccAWSAutoScalingGroup_suspendingProcesses (206.53s) --- PASS: TestAccAWSAutoScalingGroup_tags (261.72s) --- PASS: TestAccAWSAutoScalingGroup_TargetGroupArns (185.94s) --- PASS: TestAccAWSAutoScalingGroup_terminationPolicies (133.73s) --- PASS: TestAccAWSAutoScalingGroup_VpcUpdates (76.21s) --- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer (339.36s) --- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup (332.66s) --- PASS: TestAccAWSAutoScalingGroup_withMetrics (129.58s) --- PASS: TestAccAWSAutoScalingGroup_withPlacementGroup (168.23s) ``` --- aws/diff_suppress_funcs.go | 12 +----------- aws/resource_aws_autoscaling_group.go | 11 +++++------ aws/resource_aws_autoscaling_group_test.go | 1 - website/docs/guides/version-3-upgrade.html.md | 7 +++++++ website/docs/r/autoscaling_group.html.markdown | 4 ++-- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/aws/diff_suppress_funcs.go b/aws/diff_suppress_funcs.go index c228103184d8..7597f8013081 100644 --- a/aws/diff_suppress_funcs.go +++ b/aws/diff_suppress_funcs.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/jen20/awspolicyequivalence" + awspolicy "github.com/jen20/awspolicyequivalence" ) func suppressEquivalentAwsPolicyDiffs(k, old, new string, d *schema.ResourceData) bool { @@ -97,16 +97,6 @@ func suppressOpenIdURL(k, old, new string, d *schema.ResourceData) bool { return oldUrl.String() == newUrl.String() } -func suppressAutoscalingGroupAvailabilityZoneDiffs(k, old, new string, d *schema.ResourceData) bool { - // If VPC zone identifiers are provided then there is no need to explicitly - // specify availability zones. - if _, ok := d.GetOk("vpc_zone_identifier"); ok { - return true - } - - return false -} - func suppressCloudFormationTemplateBodyDiffs(k, old, new string, d *schema.ResourceData) bool { normalizedOld, err := normalizeCloudFormationTemplate(old) diff --git a/aws/resource_aws_autoscaling_group.go b/aws/resource_aws_autoscaling_group.go index c680d0c5cd7c..c0a8f246c1b3 100644 --- a/aws/resource_aws_autoscaling_group.go +++ b/aws/resource_aws_autoscaling_group.go @@ -250,12 +250,11 @@ func resourceAwsAutoscalingGroup() *schema.Resource { }, "availability_zones": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - DiffSuppressFunc: suppressAutoscalingGroupAvailabilityZoneDiffs, + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + ConflictsWith: []string{"vpc_zone_identifier"}, }, "placement_group": { diff --git a/aws/resource_aws_autoscaling_group_test.go b/aws/resource_aws_autoscaling_group_test.go index 7d842aa3293c..aa04db7a0151 100644 --- a/aws/resource_aws_autoscaling_group_test.go +++ b/aws/resource_aws_autoscaling_group_test.go @@ -2573,7 +2573,6 @@ resource "aws_launch_configuration" "foobar" { } resource "aws_autoscaling_group" "bar" { - availability_zones = ["${aws_subnet.foo.availability_zone}"] vpc_zone_identifier = ["${aws_subnet.foo.id}"] max_size = 2 min_size = 2 diff --git a/website/docs/guides/version-3-upgrade.html.md b/website/docs/guides/version-3-upgrade.html.md index c2fec8b3afed..6e6ba2374c73 100644 --- a/website/docs/guides/version-3-upgrade.html.md +++ b/website/docs/guides/version-3-upgrade.html.md @@ -20,6 +20,7 @@ Upgrade topics: - [Provider Authentication Updates](#provider-authentication-updates) - [Data Source: aws_availability_zones](#data-source-aws_availability_zones) - [Data Source: aws_lambda_invocation](#data-source-aws_lambda_invocation) +- [Resource: aws_autoscaling_group](#resource-aws_autoscaling_group) - [Resource: aws_dx_gateway](#resource-aws_dx_gateway) - [Resource: aws_elastic_transcoder_preset](#resource-aws_elastic_transcoder_preset) - [Resource: aws_emr_cluster](#resource-aws_emr_cluster) @@ -152,6 +153,12 @@ output "lambda_result" { } ``` +## Resource: aws_autoscaling_group + +### availability_zones and vpc_zone_identifier Arguments Now Report Plan-Time Conflict + +Specifying both the `availability_zones` and `vpc_zone_identifier` arguments previously led to confusing behavior and errors. Now this issue is reported at plan-time. Use the `null` value instead of `[]` (empty list) in conditionals to ensure this validation does not unexpectedly trigger. + ## Resource: aws_dx_gateway ### Removal of Automatic aws_dx_gateway_association Import diff --git a/website/docs/r/autoscaling_group.html.markdown b/website/docs/r/autoscaling_group.html.markdown index a7c850754461..e80090df56ca 100644 --- a/website/docs/r/autoscaling_group.html.markdown +++ b/website/docs/r/autoscaling_group.html.markdown @@ -168,7 +168,7 @@ The following arguments are supported: * `max_size` - (Required) The maximum size of the auto scale group. * `min_size` - (Required) The minimum size of the auto scale group. (See also [Waiting for Capacity](#waiting-for-capacity) below.) -* `availability_zones` - (Required only for EC2-Classic) A list of one or more availability zones for the group. This parameter conflicts with `vpc_zone_identifier`. +* `availability_zones` - (Optional) A list of one or more availability zones for the group. Used for EC2-Classic and default subnets when not specified with `vpc_zone_identifier` argument. Conflicts with `vpc_zone_identifier`. * `default_cooldown` - (Optional) The amount of time, in seconds, after a scaling activity completes before another scaling activity can start. * `launch_configuration` - (Optional) The name of the launch configuration to use. * `launch_template` - (Optional) Nested argument with Launch template specification to use to launch instances. Defined below. @@ -192,7 +192,7 @@ The following arguments are supported: behavior and potentially leaves resources dangling. * `load_balancers` (Optional) A list of elastic load balancer names to add to the autoscaling group names. Only valid for classic load balancers. For ALBs, use `target_group_arns` instead. -* `vpc_zone_identifier` (Optional) A list of subnet IDs to launch resources in. +* `vpc_zone_identifier` (Optional) A list of subnet IDs to launch resources in. Subnets automatically determine which availability zones the group will reside. Conflicts with `availability_zones`. * `target_group_arns` (Optional) A list of `aws_alb_target_group` ARNs, for use with Application or Network Load Balancing. * `termination_policies` (Optional) A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `OldestLaunchTemplate`, `AllocationStrategy`, `Default`. * `suspended_processes` - (Optional) A list of processes to suspend for the AutoScaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`.