Skip to content

Commit

Permalink
resource/aws_autoscaling_group: Finalize availability_zones and vpc_z…
Browse files Browse the repository at this point in the history
…one_identifier ConflictsWith

Reference: #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)
```
  • Loading branch information
bflad committed Jul 14, 2020
1 parent effd988 commit ea86e6d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
12 changes: 1 addition & 11 deletions aws/diff_suppress_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 5 additions & 6 deletions aws/resource_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 0 additions & 1 deletion aws/resource_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions website/docs/guides/version-3-upgrade.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/autoscaling_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`.
Expand Down

0 comments on commit ea86e6d

Please sign in to comment.