Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected diffs on aws_autoscaling_group since v2.63.0 #13469

Closed
dpiddockcmp opened this issue May 22, 2020 · 18 comments · Fixed by #13515
Closed

Unexpected diffs on aws_autoscaling_group since v2.63.0 #13469

dpiddockcmp opened this issue May 22, 2020 · 18 comments · Fixed by #13515
Assignees
Labels
bug Addresses a defect in current functionality. regression Pertains to a degraded workflow resulting from an upstream patch or internal enhancement. service/autoscaling Issues and PRs that pertain to the autoscaling service.
Milestone

Comments

@dpiddockcmp
Copy link
Contributor

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.12.25
+ provider.aws v2.63.0

Affected Resource(s)

  • aws_autoscaling_group

Terraform Configuration Files

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}

data "aws_vpc" "default" {
  default = true
}

data "aws_subnet_ids" "subs" {
  vpc_id = data.aws_vpc.default.id
}

resource "aws_launch_configuration" "as_conf" {
  name          = "web_config"
  image_id      = data.aws_ami.ubuntu.id
  instance_type = "t2.micro"
}

resource "aws_autoscaling_group" "bar" {
  name                 = "foobar3-terraform-test"
  max_size             = 0
  min_size             = 0
  desired_capacity     = 0
  launch_configuration = aws_launch_configuration.as_conf.name
  vpc_zone_identifier  = data.aws_subnet_ids.subs.ids

  tags = [
    {
      key                 = "foo"
      value               = "bar"
      propagate_at_launch = true
    },
    {
      key                 = "foo2"
      value               = "bar2"
      propagate_at_launch = true
    },
    {
      key                 = "2foo"
      value               = "2bar"
      propagate_at_launch = true
    },
  ]
}

Debug Output

Panic Output

Expected Behavior

No diff every run when the configuration has not changed.

Actual Behavior

Every plan produces the same diff:

  # aws_autoscaling_group.bar will be updated in-place
  ~ resource "aws_autoscaling_group" "bar" {
        arn                       = "arn:aws:autoscaling:us-east-1:111111111111:autoScalingGroup:5603abf2-a424-407b-b417-95bc90eb8c9f:autoScalingGroupName/foobar3-terraform-test"
        availability_zones        = [
            "us-east-1a",
            "us-east-1b",
            "us-east-1c",
            "us-east-1d",
            "us-east-1e",
            "us-east-1f",
        ]
        default_cooldown          = 300
        desired_capacity          = 0
        enabled_metrics           = []
        force_delete              = false
        health_check_grace_period = 300
        health_check_type         = "EC2"
        id                        = "foobar3-terraform-test"
        launch_configuration      = "web_config"
        load_balancers            = []
        max_instance_lifetime     = 0
        max_size                  = 0
        metrics_granularity       = "1Minute"
        min_size                  = 0
        name                      = "foobar3-terraform-test"
        protect_from_scale_in     = false
        service_linked_role_arn   = "arn:aws:iam::111111111111:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"
        suspended_processes       = []
      ~ tags                      = [
          - {
              - "key"                 = "2foo"
              - "propagate_at_launch" = "true"
              - "value"               = "2bar"
            },
            {
                "key"                 = "foo"
                "propagate_at_launch" = "true"
                "value"               = "bar"
            },
            {
                "key"                 = "foo2"
                "propagate_at_launch" = "true"
                "value"               = "bar2"
            },
          + {
              + "key"                 = "2foo"
              + "propagate_at_launch" = "true"
              + "value"               = "2bar"
            },
        ]
        target_group_arns         = []
        termination_policies      = []
        vpc_zone_identifier       = [
            "subnet-a",
            "subnet-b",
            "subnet-c",
            "subnet-d",
            "subnet-e",
            "subnet-f",
        ]
        wait_for_capacity_timeout = "10m"
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Downgrading to 2.62.0 produces a diff on the first apply so this new order is being stored in the state file.

Steps to Reproduce

  1. terraform apply

Important Factoids

Regression introduced in 2.63.0.

Does not happen for every state if you happen to have the tags in the "correct" order.

References

@ghost ghost added service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2 Issues and PRs that pertain to the ec2 service. labels May 22, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label May 22, 2020
@dayglojesus
Copy link

dayglojesus commented May 22, 2020

We are seeing this behaviour on ALL of our various ECS and EKS deployments as of this morning.
terraform-aws-modules/terraform-aws-eks#889 (comment)

@dayglojesus
Copy link

I should add, this behaviour affects Terraform 0.11.14 as well.

@esteban1983cl
Copy link

Same issue in Terraform 0.11.14

@ewbankkit
Copy link
Contributor

@ewbankkit
Copy link
Contributor

ewbankkit commented May 23, 2020

The Auto Scaling group's tags are created in the order specified in the HCL code:

2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws: 2020/05/23 17:08:02 [DEBUG] AutoScaling Group create configuration: {
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:   AutoScalingGroupName: "foobar3-terraform-test",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:   HealthCheckGracePeriod: 300,
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:   LaunchConfigurationName: "web_config",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:   MaxSize: 0,
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:   MinSize: 0,
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:   NewInstancesProtectedFromScaleIn: false,
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:   Tags: [{
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       Key: "foo",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       PropagateAtLaunch: true,
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       ResourceId: "foobar3-terraform-test",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       ResourceType: "auto-scaling-group",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       Value: "bar"
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:     },{
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       Key: "foo2",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       PropagateAtLaunch: true,
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       ResourceId: "foobar3-terraform-test",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       ResourceType: "auto-scaling-group",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       Value: "bar2"
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:     },{
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       Key: "2foo",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       PropagateAtLaunch: true,
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       ResourceId: "foobar3-terraform-test",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       ResourceType: "auto-scaling-group",
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:       Value: "2bar"
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:     }],
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws:   VPCZoneIdentifier: ",subnet-0f9d4a44"
2020-05-23T17:08:02.096-0400 [DEBUG] plugin.terraform-provider-aws: }

but when they are read back, they are in a different order:

2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws: 2020/05/23 17:08:03 [DEBUG] [aws-sdk-go] <DescribeAutoScalingGroupsResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:   <DescribeAutoScalingGroupsResult>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:     <AutoScalingGroups>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:       <member>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <HealthCheckType>EC2</HealthCheckType>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <Instances/>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <TerminationPolicies>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:           <member>Default</member>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         </TerminationPolicies>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <DefaultCooldown>300</DefaultCooldown>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <EnabledMetrics/>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <AutoScalingGroupARN>arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:bb771324-fd24-4beb-9a61-3ca596ea3e64:autoScalingGroupName/foobar3-terraform-test</AutoScalingGroupARN>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <AvailabilityZones>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:           <member>us-west-2b</member>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         </AvailabilityZones>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <MaxSize>0</MaxSize>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <TargetGroupARNs/>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <LaunchConfigurationName>web_config</LaunchConfigurationName>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <AutoScalingGroupName>foobar3-terraform-test</AutoScalingGroupName>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <HealthCheckGracePeriod>300</HealthCheckGracePeriod>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <NewInstancesProtectedFromScaleIn>false</NewInstancesProtectedFromScaleIn>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <CreatedTime>2020-05-23T21:08:04.361Z</CreatedTime>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <MinSize>0</MinSize>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <LoadBalancerNames/>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <Tags>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:           <member>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <ResourceId>foobar3-terraform-test</ResourceId>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <PropagateAtLaunch>true</PropagateAtLaunch>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <Value>2bar</Value>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <Key>2foo</Key>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <ResourceType>auto-scaling-group</ResourceType>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:           </member>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:           <member>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <ResourceId>foobar3-terraform-test</ResourceId>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <PropagateAtLaunch>true</PropagateAtLaunch>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <Value>bar</Value>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <Key>foo</Key>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <ResourceType>auto-scaling-group</ResourceType>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:           </member>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:           <member>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <ResourceId>foobar3-terraform-test</ResourceId>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <PropagateAtLaunch>true</PropagateAtLaunch>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <Value>bar2</Value>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <Key>foo2</Key>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:             <ResourceType>auto-scaling-group</ResourceType>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:           </member>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         </Tags>
2020-05-23T17:08:03.135-0400 [DEBUG] plugin.terraform-provider-aws:         <ServiceLinkedRoleARN>arn:aws:iam::123456789012:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling</ServiceLinkedRoleARN>
2020-05-23T17:08:03.136-0400 [DEBUG] plugin.terraform-provider-aws:         <SuspendedProcesses/>
2020-05-23T17:08:03.136-0400 [DEBUG] plugin.terraform-provider-aws:         <DesiredCapacity>0</DesiredCapacity>
2020-05-23T17:08:03.136-0400 [DEBUG] plugin.terraform-provider-aws:         <VPCZoneIdentifier>subnet-0f9d4a44</VPCZoneIdentifier>
2020-05-23T17:08:03.136-0400 [DEBUG] plugin.terraform-provider-aws:       </member>
2020-05-23T17:08:03.136-0400 [DEBUG] plugin.terraform-provider-aws:     </AutoScalingGroups>
2020-05-23T17:08:03.136-0400 [DEBUG] plugin.terraform-provider-aws:   </DescribeAutoScalingGroupsResult>
2020-05-23T17:08:03.136-0400 [DEBUG] plugin.terraform-provider-aws:   <ResponseMetadata>
2020-05-23T17:08:03.136-0400 [DEBUG] plugin.terraform-provider-aws:     <RequestId>c1cc9d77-4e9d-4108-8a54-6cc45c9f492b</RequestId>
2020-05-23T17:08:03.136-0400 [DEBUG] plugin.terraform-provider-aws:   </ResponseMetadata>
2020-05-23T17:08:03.136-0400 [DEBUG] plugin.terraform-provider-aws: </DescribeAutoScalingGroupsResponse>

The fix in #13360 means that these tags are now actually persisted in state.
Previously, e.g. in v2.62.0, there was an error on the d.Set("tags", ...) call

tags.0.propagate_at_launch: '' expected type 'string', got unconvertible type 'bool'

which prevented the tags from being written to state in the order returned in DescribeAutoScalingGroupsResponse.

Now that has been fixed, the tags ARE stored in state, hence the diff.

@dyegoe
Copy link

dyegoe commented May 26, 2020

Terraform v0.12.25
+ provider.aws v2.63.0

I could identify for aws_autoscaling_group the tags = should be sorted in alphabetical order using HCL to avoid the tags recreation.

@bflad bflad added bug Addresses a defect in current functionality. regression Pertains to a degraded workflow resulting from an upstream patch or internal enhancement. and removed needs-triage Waiting for first response or review from a maintainer. service/ec2 Issues and PRs that pertain to the ec2 service. labels May 26, 2020
@bflad bflad self-assigned this May 27, 2020
@bflad bflad added this to the v2.64.0 milestone May 27, 2020
bflad added a commit that referenced this issue May 27, 2020
…` argument

Reference: #13469

Now that we are properly setting this attribute into the Terraform state, it highlighted ordering issues, which was not previously caught by the acceptance testing for the resource.

Previously (after test configuration adjustment):

```
--- FAIL: TestAccAWSAutoScalingGroup_basic (147.82s)
    TestAccAWSAutoScalingGroup_basic: testing.go:684: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: aws_autoscaling_group.bar
...
          tags.#:                     "3" => "3"
          tags.0.key:                 "FromTags1" => "FromTags1"
          tags.0.propagate_at_launch: "true" => "true"
          tags.0.value:               "value1" => "value1"
          tags.1.key:                 "FromTags2" => "FromTags3"
          tags.1.propagate_at_launch: "true" => "true"
          tags.1.value:               "value2" => "value3"
          tags.2.key:                 "FromTags3" => "FromTags2"
          tags.2.propagate_at_launch: "true" => "true"
          tags.2.value:               "value3" => "value2"
...
```

Output from acceptance testing:

```
--- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups (187.12s)
--- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity (342.93s)
--- PASS: TestAccAWSAutoScalingGroup_autoGeneratedName (79.14s)
--- PASS: TestAccAWSAutoScalingGroup_basic (267.48s)
--- PASS: TestAccAWSAutoScalingGroup_classicVpcZoneIdentifier (78.67s)
--- PASS: TestAccAWSAutoScalingGroup_emptyAvailabilityZones (91.64s)
--- PASS: TestAccAWSAutoScalingGroup_enablingMetrics (207.54s)
--- PASS: TestAccAWSAutoScalingGroup_initialLifecycleHook (304.85s)
--- PASS: TestAccAWSAutoScalingGroup_launchTemplate (87.94s)
--- PASS: TestAccAWSAutoScalingGroup_LaunchTemplate_IAMInstanceProfile (99.20s)
--- PASS: TestAccAWSAutoScalingGroup_launchTemplate_update (175.02s)
--- PASS: TestAccAWSAutoScalingGroup_launchTempPartitionNum (90.52s)
--- PASS: TestAccAWSAutoScalingGroup_LoadBalancers (569.76s)
--- PASS: TestAccAWSAutoScalingGroup_MaxInstanceLifetime (87.50s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy (83.65s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandAllocationStrategy (56.61s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandBaseCapacity (160.95s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandPercentageAboveBaseCapacity (83.85s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotAllocationStrategy (116.76s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotInstancePools (112.29s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotMaxPrice (160.14s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_LaunchTemplateName (88.11s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_Version (116.78s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_InstanceType (123.93s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_WeightedCapacity (168.12s)
--- PASS: TestAccAWSAutoScalingGroup_namePrefix (78.08s)
--- PASS: TestAccAWSAutoScalingGroup_serviceLinkedRoleARN (53.32s)
--- PASS: TestAccAWSAutoScalingGroup_suspendingProcesses (242.59s)
--- PASS: TestAccAWSAutoScalingGroup_tags (287.70s)
--- PASS: TestAccAWSAutoScalingGroup_TargetGroupArns (316.34s)
--- PASS: TestAccAWSAutoScalingGroup_terminationPolicies (154.29s)
--- PASS: TestAccAWSAutoScalingGroup_VpcUpdates (175.10s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer (423.35s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup (428.41s)
--- PASS: TestAccAWSAutoScalingGroup_withMetrics (114.18s)
--- PASS: TestAccAWSAutoScalingGroup_withPlacementGroup (175.16s)
```
bflad added a commit that referenced this issue May 27, 2020
…` argument (#13515)

Reference: #13469

Now that we are properly setting this attribute into the Terraform state, it highlighted ordering issues, which was not previously caught by the acceptance testing for the resource.

Previously (after test configuration adjustment):

```
--- FAIL: TestAccAWSAutoScalingGroup_basic (147.82s)
    TestAccAWSAutoScalingGroup_basic: testing.go:684: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: aws_autoscaling_group.bar
...
          tags.#:                     "3" => "3"
          tags.0.key:                 "FromTags1" => "FromTags1"
          tags.0.propagate_at_launch: "true" => "true"
          tags.0.value:               "value1" => "value1"
          tags.1.key:                 "FromTags2" => "FromTags3"
          tags.1.propagate_at_launch: "true" => "true"
          tags.1.value:               "value2" => "value3"
          tags.2.key:                 "FromTags3" => "FromTags2"
          tags.2.propagate_at_launch: "true" => "true"
          tags.2.value:               "value3" => "value2"
...
```

Output from acceptance testing:

```
--- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups (187.12s)
--- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity (342.93s)
--- PASS: TestAccAWSAutoScalingGroup_autoGeneratedName (79.14s)
--- PASS: TestAccAWSAutoScalingGroup_basic (267.48s)
--- PASS: TestAccAWSAutoScalingGroup_classicVpcZoneIdentifier (78.67s)
--- PASS: TestAccAWSAutoScalingGroup_emptyAvailabilityZones (91.64s)
--- PASS: TestAccAWSAutoScalingGroup_enablingMetrics (207.54s)
--- PASS: TestAccAWSAutoScalingGroup_initialLifecycleHook (304.85s)
--- PASS: TestAccAWSAutoScalingGroup_launchTemplate (87.94s)
--- PASS: TestAccAWSAutoScalingGroup_LaunchTemplate_IAMInstanceProfile (99.20s)
--- PASS: TestAccAWSAutoScalingGroup_launchTemplate_update (175.02s)
--- PASS: TestAccAWSAutoScalingGroup_launchTempPartitionNum (90.52s)
--- PASS: TestAccAWSAutoScalingGroup_LoadBalancers (569.76s)
--- PASS: TestAccAWSAutoScalingGroup_MaxInstanceLifetime (87.50s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy (83.65s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandAllocationStrategy (56.61s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandBaseCapacity (160.95s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandPercentageAboveBaseCapacity (83.85s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotAllocationStrategy (116.76s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotInstancePools (112.29s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotMaxPrice (160.14s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_LaunchTemplateName (88.11s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_Version (116.78s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_InstanceType (123.93s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_WeightedCapacity (168.12s)
--- PASS: TestAccAWSAutoScalingGroup_namePrefix (78.08s)
--- PASS: TestAccAWSAutoScalingGroup_serviceLinkedRoleARN (53.32s)
--- PASS: TestAccAWSAutoScalingGroup_suspendingProcesses (242.59s)
--- PASS: TestAccAWSAutoScalingGroup_tags (287.70s)
--- PASS: TestAccAWSAutoScalingGroup_TargetGroupArns (316.34s)
--- PASS: TestAccAWSAutoScalingGroup_terminationPolicies (154.29s)
--- PASS: TestAccAWSAutoScalingGroup_VpcUpdates (175.10s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer (423.35s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup (428.41s)
--- PASS: TestAccAWSAutoScalingGroup_withMetrics (114.18s)
--- PASS: TestAccAWSAutoScalingGroup_withPlacementGroup (175.16s)
```
@bflad
Copy link
Contributor

bflad commented May 27, 2020

The fix for the tags ordering issue has been merged and will release with version 2.64.0 of the Terraform AWS Provider, likely tomorrow.

@ghost
Copy link

ghost commented May 29, 2020

This has been released in version 2.64.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@dud225
Copy link

dud225 commented May 29, 2020

The bug seems still present on v2.64.0

@dyegoe
Copy link

dyegoe commented May 29, 2020

Did you upgrade your AWS plugin? terraform init -upgrade

After re-order the tags, I ran terraforn plan using 2.64.0 and got no changes.

terraform {
  required_version = ">= 0.12.24"
  required_providers {
    aws      = ">= 2.64.0"
    template = ">= 2.1.2"
  }
}

But, if I force to use 2.63.0, I still got changes during the plan.

terraform {
  required_version = ">= 0.12.24"
  required_providers {
    aws      = "= 2.63.0"
    template = ">= 2.1.2"
  }
}

@dud225
Copy link

dud225 commented Jun 1, 2020

Hello
Yes I did upgrade.
AFAIU off #13515 the order shouldn't matter so no I haven't reordered the tags.

@dyegoe
Copy link

dyegoe commented Jun 1, 2020

Sorry, I wrote wrong.
I tried to say that I changed the order of the tags. I didn't sort it in alphabetical order.
Maybe you can post here more details, but so far, it worked for me

@FarshadHadei
Copy link

FarshadHadei commented Jun 3, 2020

We get the same unexpected diff again on 2.64.0 and Terraform 0.11.14, the bug seem to be present to me.

@dud225
Copy link

dud225 commented Jun 3, 2020

Yes I'm running TF 0.11.14 as well.

@FarshadHadei
Copy link

FarshadHadei commented Jun 3, 2020

when I use tag blocks in the aws_autoscaling_group resource, I get no diffs
If I use null data source, it gets me diff in every plan:

data "null_data_source" "tags" {
   count = "${length(keys(var.common_tags))}"
    
   inputs = {
    key                 = "${element(keys(var.common_tags), count.index)}"
    value               = "${element(values(var.common_tags), count.index)}"
    propagate_at_launch = true
    }
 }
resource "aws_autoscaling_group" "ecs_autoscaling_group" {
    tags = ["${data.null_data_source.tags.*.outputs}"]
}

@dud225
Copy link

dud225 commented Jun 4, 2020

Ah interesting, I'm also relying on null_data_source though the terraform-null-label module.

@FarshadHadei
Copy link

@bflad any input on this issue will be appreciated ^^

bflad added a commit that referenced this issue Jun 23, 2020
…gs` for Terraform 0.11 and earlier with boolean `propagate_at_launch` values

Reference: #13312
Reference: #13360
Reference: #13469
Reference: #13549
Reference: #13635

One of the major improvements internally with Terraform 0.12's type system is that providers and the core logic agree on a resource schema and its normalization during configuration parsing so the state and difference handling is more consistent. In Terraform 0.11 and earlier, a quirky behavior with raw boolean values is that they could be converted to string "0" and "1" values based on various factors such as passing through functions. With recent changes to the `aws_autoscaling_group` resource to fix its handling of the `tags` attribute (to prevent `d.Set()` errors and testing panics in the upcoming Terraform Plugin SDK 2.0.0), this behavior was highlighted as unexpected perpetual differences. This cannot be caught in the 0.12 shimmed acceptance testing framework and therefore is manually tested by the below configuration and reproduction steps.

**NOTE:** The `tags` argument will be deprecated and removed in a future major version of the Terraform AWS Provider since it was designed as a workaround for Terraform 0.11 and earlier configurations. There are very few, if any, other Terraform AWS Provider attributes represented as a set of maps. In Terraform 0.12 and later, the `tag` argument more appropriately represents Auto Scaling Group resource tags as configuration blocks with strongly typed nested arguments and can be dynamically built via the `dynamic` configuration language feature. That deprecation is out of scope for this changeset though and likely will not occur until after Terraform AWS Provider version 3.0.0.

Given the following Terraform 0.11 compatible configuration with raw boolean values:

```hcl
terraform {
  required_version = "0.11.14"
}

provider "aws" {
  region  = "us-east-2"
  version = "2.67.0"
}

locals {
  test = [
    {
      key                 = "localkey1"
      value               = "localvalue1"
      propagate_at_launch = true
    },
    {
      key                 = "localkey2"
      value               = "localvalue2"
      propagate_at_launch = true
    },
  ]
}

data "aws_ami" "test" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn-ami-hvm-*-x86_64-gp2"]
  }
}

data "aws_availability_zones" "available" {
  state = "available"

  filter {
    name   = "opt-in-status"
    values = ["opt-in-not-required"]
  }
}

resource "aws_launch_template" "test" {
  name_prefix   = "test"
  image_id      = "${data.aws_ami.test.id}"
  instance_type = "t2.micro"
}

resource "aws_autoscaling_group" "test" {
  availability_zones = ["${data.aws_availability_zones.available.names[0]}"]
  desired_capacity   = 0
  max_size           = 0
  min_size           = 0
  tags               = ["${concat(list(map("key", "resourcekey1", "value", "resourcevalue1", "propagate_at_launch", true)), local.test)}"]

  launch_template {
    id      = "${aws_launch_template.test.id}"
    version = "${aws_launch_template.test.default_version}"
  }
}

output "tags" {
  value = "${aws_autoscaling_group.test.tags}"
}

```

Applying twice has a perpetual difference:

```console
$ terraform0.11.14 init

Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "aws" (2.67.0)...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

$ terraform0.11.14 apply
data.aws_ami.test: Refreshing state...
data.aws_availability_zones.available: Refreshing state...

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  + aws_autoscaling_group.test
      id:                                  <computed>
      arn:                                 <computed>
      availability_zones.#:                "1"
      availability_zones.4293815384:       "us-east-2a"
      default_cooldown:                    <computed>
      desired_capacity:                    "0"
      force_delete:                        "false"
      health_check_grace_period:           "300"
      health_check_type:                   <computed>
      launch_template.#:                   "1"
      launch_template.0.id:                "${aws_launch_template.test.id}"
      launch_template.0.name:              <computed>
      launch_template.0.version:           "${aws_launch_template.test.default_version}"
      load_balancers.#:                    <computed>
      max_size:                            "0"
      metrics_granularity:                 "1Minute"
      min_size:                            "0"
      name:                                <computed>
      protect_from_scale_in:               "false"
      service_linked_role_arn:             <computed>
      tags.#:                              "3"
      tags.2825254636.%:                   "3"
      tags.2825254636.key:                 "localkey1"
      tags.2825254636.propagate_at_launch: "1"
      tags.2825254636.value:               "localvalue1"
      tags.2888644505.%:                   "3"
      tags.2888644505.key:                 "resourcekey1"
      tags.2888644505.propagate_at_launch: "1"
      tags.2888644505.value:               "resourcevalue1"
      tags.3299348900.%:                   "3"
      tags.3299348900.key:                 "localkey2"
      tags.3299348900.propagate_at_launch: "1"
      tags.3299348900.value:               "localvalue2"
      target_group_arns.#:                 <computed>
      vpc_zone_identifier.#:               <computed>
      wait_for_capacity_timeout:           "10m"

  + aws_launch_template.test
      id:                                  <computed>
      arn:                                 <computed>
      default_version:                     <computed>
      image_id:                            "ami-083ebc5a49573896a"
      instance_type:                       "t2.micro"
      latest_version:                      "0"
      metadata_options.#:                  <computed>
      name:                                <computed>
      name_prefix:                         "test"

Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_launch_template.test: Creating...
  arn:                "" => "<computed>"
  default_version:    "" => "<computed>"
  image_id:           "" => "ami-083ebc5a49573896a"
  instance_type:      "" => "t2.micro"
  latest_version:     "" => "<computed>"
  metadata_options.#: "" => "<computed>"
  name:               "" => "<computed>"
  name_prefix:        "" => "test"
aws_launch_template.test: Creation complete after 0s (ID: lt-0d8e6f4f94a683778)
aws_autoscaling_group.test: Creating...
  arn:                                 "" => "<computed>"
  availability_zones.#:                "" => "1"
  availability_zones.4293815384:       "" => "us-east-2a"
  default_cooldown:                    "" => "<computed>"
  desired_capacity:                    "" => "0"
  force_delete:                        "" => "false"
  health_check_grace_period:           "" => "300"
  health_check_type:                   "" => "<computed>"
  launch_template.#:                   "" => "1"
  launch_template.0.id:                "" => "lt-0d8e6f4f94a683778"
  launch_template.0.name:              "" => "<computed>"
  launch_template.0.version:           "" => "1"
  load_balancers.#:                    "" => "<computed>"
  max_size:                            "" => "0"
  metrics_granularity:                 "" => "1Minute"
  min_size:                            "" => "0"
  name:                                "" => "<computed>"
  protect_from_scale_in:               "" => "false"
  service_linked_role_arn:             "" => "<computed>"
  tags.#:                              "" => "3"
  tags.2825254636.%:                   "" => "3"
  tags.2825254636.key:                 "" => "localkey1"
  tags.2825254636.propagate_at_launch: "" => "1"
  tags.2825254636.value:               "" => "localvalue1"
  tags.2888644505.%:                   "" => "3"
  tags.2888644505.key:                 "" => "resourcekey1"
  tags.2888644505.propagate_at_launch: "" => "1"
  tags.2888644505.value:               "" => "resourcevalue1"
  tags.3299348900.%:                   "" => "3"
  tags.3299348900.key:                 "" => "localkey2"
  tags.3299348900.propagate_at_launch: "" => "1"
  tags.3299348900.value:               "" => "localvalue2"
  target_group_arns.#:                 "" => "<computed>"
  vpc_zone_identifier.#:               "" => "<computed>"
  wait_for_capacity_timeout:           "" => "10m"
aws_autoscaling_group.test: Creation complete after 2s (ID: tf-asg-20200623194008467200000003)

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Outputs:

tags = [
    {
        key = localkey2,
        propagate_at_launch = 1,
        value = localvalue2
    },
    {
        key = localkey1,
        propagate_at_launch = 1,
        value = localvalue1
    },
    {
        key = resourcekey1,
        propagate_at_launch = 1,
        value = resourcevalue1
    }
]

$ terraform0.11.14 apply
data.aws_ami.test: Refreshing state...
data.aws_availability_zones.available: Refreshing state...
aws_launch_template.test: Refreshing state... (ID: lt-0d8e6f4f94a683778)
aws_autoscaling_group.test: Refreshing state... (ID: tf-asg-20200623194008467200000003)

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  ~ aws_autoscaling_group.test
      tags.2131493069.%:                   "3" => "0"
      tags.2131493069.key:                 "localkey2" => ""
      tags.2131493069.propagate_at_launch: "true" => ""
      tags.2131493069.value:               "localvalue2" => ""
      tags.2825254636.%:                   "0" => "3"
      tags.2825254636.key:                 "" => "localkey1"
      tags.2825254636.propagate_at_launch: "" => "1"
      tags.2825254636.value:               "" => "localvalue1"
      tags.2888644505.%:                   "0" => "3"
      tags.2888644505.key:                 "" => "resourcekey1"
      tags.2888644505.propagate_at_launch: "" => "1"
      tags.2888644505.value:               "" => "resourcevalue1"
      tags.3299348900.%:                   "0" => "3"
      tags.3299348900.key:                 "" => "localkey2"
      tags.3299348900.propagate_at_launch: "" => "1"
      tags.3299348900.value:               "" => "localvalue2"
      tags.3593646732.%:                   "3" => "0"
      tags.3593646732.key:                 "localkey1" => ""
      tags.3593646732.propagate_at_launch: "true" => ""
      tags.3593646732.value:               "localvalue1" => ""
      tags.3707627218.%:                   "3" => "0"
      tags.3707627218.key:                 "resourcekey1" => ""
      tags.3707627218.propagate_at_launch: "true" => ""
      tags.3707627218.value:               "resourcevalue1" => ""

Plan: 0 to add, 1 to change, 0 to destroy.
```

Building this version of the provider, the difference is no longer present:

```console
$ cp ~/go/bin/terraform-provider-aws .terraform/plugins/darwin_amd64/terraform-provider-aws_v2.67.0_x4; terraform0.11.14 init; terraform0.11.14 apply

Initializing provider plugins...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
data.aws_availability_zones.available: Refreshing state...
data.aws_ami.test: Refreshing state...
aws_launch_template.test: Refreshing state... (ID: lt-0d8e6f4f94a683778)
aws_autoscaling_group.test: Refreshing state... (ID: tf-asg-20200623194008467200000003)

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

tags = [
    {
        key = localkey1,
        propagate_at_launch = 1,
        value = localvalue1
    },
    {
        key = resourcekey1,
        propagate_at_launch = 1,
        value = resourcevalue1
    },
    {
        key = localkey2,
        propagate_at_launch = 1,
        value = localvalue2
    }
]
```

Output from acceptance testing (Terraform 0.12 compatible):

```
--- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups (176.05s)
--- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity (342.40s)
--- PASS: TestAccAWSAutoScalingGroup_autoGeneratedName (89.91s)
--- PASS: TestAccAWSAutoScalingGroup_basic (259.25s)
--- PASS: TestAccAWSAutoScalingGroup_classicVpcZoneIdentifier (93.45s)
--- PASS: TestAccAWSAutoScalingGroup_emptyAvailabilityZones (92.72s)
--- PASS: TestAccAWSAutoScalingGroup_enablingMetrics (174.98s)
--- PASS: TestAccAWSAutoScalingGroup_initialLifecycleHook (271.36s)
--- PASS: TestAccAWSAutoScalingGroup_launchTemplate (62.35s)
--- PASS: TestAccAWSAutoScalingGroup_LaunchTemplate_IAMInstanceProfile (61.69s)
--- PASS: TestAccAWSAutoScalingGroup_launchTemplate_update (143.24s)
--- PASS: TestAccAWSAutoScalingGroup_launchTempPartitionNum (77.30s)
--- PASS: TestAccAWSAutoScalingGroup_LoadBalancers (695.77s)
--- PASS: TestAccAWSAutoScalingGroup_MaxInstanceLifetime (80.89s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy (108.93s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandAllocationStrategy (49.98s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandBaseCapacity (82.14s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_OnDemandPercentageAboveBaseCapacity (96.59s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotAllocationStrategy (83.60s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotInstancePools (90.32s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_SpotMaxPrice (112.90s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstancesDistribution_UpdateToZeroOnDemandBaseCapacity (73.62s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_LaunchTemplateName (86.69s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_LaunchTemplateSpecification_Version (85.84s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_InstanceType (85.29s)
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_WeightedCapacity (205.06s)
--- PASS: TestAccAWSAutoScalingGroup_namePrefix (45.70s)
--- PASS: TestAccAWSAutoScalingGroup_serviceLinkedRoleARN (83.67s)
--- PASS: TestAccAWSAutoScalingGroup_suspendingProcesses (267.51s)
--- PASS: TestAccAWSAutoScalingGroup_tags (299.92s)
--- PASS: TestAccAWSAutoScalingGroup_TargetGroupArns (249.92s)
--- PASS: TestAccAWSAutoScalingGroup_terminationPolicies (151.45s)
--- PASS: TestAccAWSAutoScalingGroup_VpcUpdates (236.40s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer (389.18s)
--- PASS: TestAccAWSAutoScalingGroup_WithLoadBalancer_ToTargetGroup (384.27s)
--- PASS: TestAccAWSAutoScalingGroup_withMetrics (96.85s)
--- PASS: TestAccAWSAutoScalingGroup_withPlacementGroup (200.69s)
```
@ghost
Copy link

ghost commented Jun 27, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Jun 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. regression Pertains to a degraded workflow resulting from an upstream patch or internal enhancement. service/autoscaling Issues and PRs that pertain to the autoscaling service.
Projects
None yet
8 participants