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

resource/aws_instance: Fix incorrect behavior of volume_tags (#12225) #12226

Closed
wants to merge 1 commit into from

Conversation

klebediev
Copy link
Contributor

@klebediev klebediev commented Mar 2, 2020

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment 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 pull request followers and do not help prioritize the request

Closes #12225 #5878 #5609

Release note for CHANGELOG:

 - resource/aws_instance: Fix incorrect behavior of volume_tags (#12225)

Output from acceptance testing:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSInstance_volumeTags'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSInstance_volumeTags -timeout 120m
=== RUN   TestAccAWSInstance_volumeTags
=== PAUSE TestAccAWSInstance_volumeTags
=== RUN   TestAccAWSInstance_volumeTagsComputed
=== PAUSE TestAccAWSInstance_volumeTagsComputed
=== CONT  TestAccAWSInstance_volumeTags
=== CONT  TestAccAWSInstance_volumeTagsComputed
--- PASS: TestAccAWSInstance_volumeTagsComputed (153.89s)
--- PASS: TestAccAWSInstance_volumeTags (213.60s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	216.162s
...

@klebediev klebediev requested a review from a team March 2, 2020 20:31
@ghost ghost added needs-triage Waiting for first response or review from a maintainer. size/M Managed by automation to categorize the size of a PR. service/ec2 Issues and PRs that pertain to the ec2 service. labels Mar 2, 2020
@klebediev klebediev force-pushed the bugfix/volume-tags branch 2 times, most recently from a6d7d62 to d1c237b Compare March 3, 2020 17:19
@ewbankkit
Copy link
Contributor

ewbankkit commented Mar 3, 2020

Closes #5080, #770, #729, #884.
Similar PR #9156.

@klebediev
Copy link
Contributor Author

What could I do to speed up review of this PR?
The bug exists for years, aws_instance resource is one of the most frequently used, I believe.
Before latest provider versions this workaround worked, but not the case now.

@klebediev klebediev force-pushed the bugfix/volume-tags branch from d1c237b to 50679f9 Compare March 9, 2020 20:17
@ghost ghost added the tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. label Mar 9, 2020
@klebediev klebediev force-pushed the bugfix/volume-tags branch 2 times, most recently from 0d52ee9 to 3291d66 Compare March 10, 2020 05:06
@@ -818,7 +818,7 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error setting tags: %s", err)
}

volumeTags, err := readVolumeTags(conn, d.Id())
volumeTags, err := readRootVolumeTags(d, instance, conn)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main idea: work with root volume only, ignore tag changes for all other ebs_block_devices.
It's stated in the docs:

Currently, changes to the ebs_block_device configuration of existing resources cannot be automatically detected by Terraform. To manage changes and attachments of an EBS block to an instance, use the aws_ebs_volume and aws_volume_attachment resources instead.

I believe, technically it's impossible to describe change for N volumes by single diff of volume_tags.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a developer here, but maybe update
https://www.terraform.io/docs/providers/aws/r/instance.html#volume_tags

(Optional) A map of tags to assign to the devices created by the instance at launch time.
to
(Optional) A map of tags to assign to the root devices. For other ebs block devices, use the tag feature of the aws_ebs_volume resource

@klebediev
Copy link
Contributor Author

Added unit-test

@klebediev
Copy link
Contributor Author

All aws_instance acc tests have passed.
Pls lmk what else could I do to speed up review of this PR

✘-1 ~/myrepos/terraform-provider-aws [bugfix/volume-tags|✔]
14:27 $ TF_ACC=1 go test ./aws -v -count 1 -parallel 4 -run="TestAccAWSInstance_" -timeout 120m
=== RUN   TestAccAWSInstance_inDefaultVpcBySgName
=== PAUSE TestAccAWSInstance_inDefaultVpcBySgName
=== RUN   TestAccAWSInstance_inDefaultVpcBySgId
=== PAUSE TestAccAWSInstance_inDefaultVpcBySgId
=== RUN   TestAccAWSInstance_inEc2Classic
=== PAUSE TestAccAWSInstance_inEc2Classic
=== RUN   TestAccAWSInstance_basic
=== PAUSE TestAccAWSInstance_basic
=== RUN   TestAccAWSInstance_EbsBlockDevice_KmsKeyArn
=== PAUSE TestAccAWSInstance_EbsBlockDevice_KmsKeyArn
=== RUN   TestAccAWSInstance_RootBlockDevice_KmsKeyArn
=== PAUSE TestAccAWSInstance_RootBlockDevice_KmsKeyArn
=== RUN   TestAccAWSInstance_userDataBase64
=== PAUSE TestAccAWSInstance_userDataBase64
=== RUN   TestAccAWSInstance_GP2IopsDevice
=== PAUSE TestAccAWSInstance_GP2IopsDevice
=== RUN   TestAccAWSInstance_GP2WithIopsValue
=== PAUSE TestAccAWSInstance_GP2WithIopsValue
=== RUN   TestAccAWSInstance_blockDevices
=== PAUSE TestAccAWSInstance_blockDevices
=== RUN   TestAccAWSInstance_rootInstanceStore
=== PAUSE TestAccAWSInstance_rootInstanceStore
=== RUN   TestAccAWSInstance_noAMIEphemeralDevices
=== PAUSE TestAccAWSInstance_noAMIEphemeralDevices
=== RUN   TestAccAWSInstance_sourceDestCheck
=== PAUSE TestAccAWSInstance_sourceDestCheck
=== RUN   TestAccAWSInstance_disableApiTermination
=== PAUSE TestAccAWSInstance_disableApiTermination
=== RUN   TestAccAWSInstance_vpc
=== PAUSE TestAccAWSInstance_vpc
=== RUN   TestAccAWSInstance_placementGroup
=== PAUSE TestAccAWSInstance_placementGroup
=== RUN   TestAccAWSInstance_ipv6_supportAddressCount
=== PAUSE TestAccAWSInstance_ipv6_supportAddressCount
=== RUN   TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError
=== PAUSE TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError
=== RUN   TestAccAWSInstance_ipv6_supportAddressCountWithIpv4
=== PAUSE TestAccAWSInstance_ipv6_supportAddressCountWithIpv4
=== RUN   TestAccAWSInstance_multipleRegions
=== PAUSE TestAccAWSInstance_multipleRegions
=== RUN   TestAccAWSInstance_NetworkInstanceSecurityGroups
=== PAUSE TestAccAWSInstance_NetworkInstanceSecurityGroups
=== RUN   TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups
=== PAUSE TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups
=== RUN   TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs
=== PAUSE TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs
=== RUN   TestAccAWSInstance_tags
=== PAUSE TestAccAWSInstance_tags
=== RUN   TestAccAWSInstance_volumeTags
=== PAUSE TestAccAWSInstance_volumeTags
=== RUN   TestAccAWSInstance_volumeTagsComputed
=== PAUSE TestAccAWSInstance_volumeTagsComputed
=== RUN   TestAccAWSInstance_instanceProfileChange
=== PAUSE TestAccAWSInstance_instanceProfileChange
=== RUN   TestAccAWSInstance_withIamInstanceProfile
=== PAUSE TestAccAWSInstance_withIamInstanceProfile
=== RUN   TestAccAWSInstance_privateIP
=== PAUSE TestAccAWSInstance_privateIP
=== RUN   TestAccAWSInstance_associatePublicIPAndPrivateIP
=== PAUSE TestAccAWSInstance_associatePublicIPAndPrivateIP
=== RUN   TestAccAWSInstance_keyPairCheck
=== PAUSE TestAccAWSInstance_keyPairCheck
=== RUN   TestAccAWSInstance_rootBlockDeviceMismatch
=== PAUSE TestAccAWSInstance_rootBlockDeviceMismatch
=== RUN   TestAccAWSInstance_forceNewAndTagsDrift
=== PAUSE TestAccAWSInstance_forceNewAndTagsDrift
=== RUN   TestAccAWSInstance_changeInstanceType
=== PAUSE TestAccAWSInstance_changeInstanceType
=== RUN   TestAccAWSInstance_primaryNetworkInterface
=== PAUSE TestAccAWSInstance_primaryNetworkInterface
=== RUN   TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck
=== PAUSE TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck
=== RUN   TestAccAWSInstance_addSecondaryInterface
=== PAUSE TestAccAWSInstance_addSecondaryInterface
=== RUN   TestAccAWSInstance_addSecurityGroupNetworkInterface
=== PAUSE TestAccAWSInstance_addSecurityGroupNetworkInterface
=== RUN   TestAccAWSInstance_associatePublic_defaultPrivate
=== PAUSE TestAccAWSInstance_associatePublic_defaultPrivate
=== RUN   TestAccAWSInstance_associatePublic_defaultPublic
=== PAUSE TestAccAWSInstance_associatePublic_defaultPublic
=== RUN   TestAccAWSInstance_associatePublic_explicitPublic
=== PAUSE TestAccAWSInstance_associatePublic_explicitPublic
=== RUN   TestAccAWSInstance_associatePublic_explicitPrivate
=== PAUSE TestAccAWSInstance_associatePublic_explicitPrivate
=== RUN   TestAccAWSInstance_associatePublic_overridePublic
=== PAUSE TestAccAWSInstance_associatePublic_overridePublic
=== RUN   TestAccAWSInstance_associatePublic_overridePrivate
=== PAUSE TestAccAWSInstance_associatePublic_overridePrivate
=== RUN   TestAccAWSInstance_getPasswordData_falseToTrue
=== PAUSE TestAccAWSInstance_getPasswordData_falseToTrue
=== RUN   TestAccAWSInstance_getPasswordData_trueToFalse
=== PAUSE TestAccAWSInstance_getPasswordData_trueToFalse
=== RUN   TestAccAWSInstance_CreditSpecification_Empty_NonBurstable
=== PAUSE TestAccAWSInstance_CreditSpecification_Empty_NonBurstable
=== RUN   TestAccAWSInstance_CreditSpecification_UnspecifiedToEmpty_NonBurstable
=== PAUSE TestAccAWSInstance_CreditSpecification_UnspecifiedToEmpty_NonBurstable
=== RUN   TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard
=== PAUSE TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard
=== RUN   TestAccAWSInstance_creditSpecification_standardCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecification_standardCpuCredits
=== RUN   TestAccAWSInstance_creditSpecification_unlimitedCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecification_unlimitedCpuCredits
=== RUN   TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2
=== PAUSE TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2
=== RUN   TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3
=== PAUSE TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3
=== RUN   TestAccAWSInstance_creditSpecification_updateCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecification_updateCpuCredits
=== RUN   TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable
=== PAUSE TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable
=== RUN   TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited
=== PAUSE TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited
=== RUN   TestAccAWSInstance_creditSpecificationT3_standardCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecificationT3_standardCpuCredits
=== RUN   TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits
=== RUN   TestAccAWSInstance_creditSpecificationT3_updateCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecificationT3_updateCpuCredits
=== RUN   TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint
=== PAUSE TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint
=== RUN   TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint
=== PAUSE TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint
=== RUN   TestAccAWSInstance_disappears
=== PAUSE TestAccAWSInstance_disappears
=== RUN   TestAccAWSInstance_UserData_EmptyStringToUnspecified
=== PAUSE TestAccAWSInstance_UserData_EmptyStringToUnspecified
=== RUN   TestAccAWSInstance_UserData_UnspecifiedToEmptyString
=== PAUSE TestAccAWSInstance_UserData_UnspecifiedToEmptyString
=== RUN   TestAccAWSInstance_hibernation
=== PAUSE TestAccAWSInstance_hibernation
=== CONT  TestAccAWSInstance_inDefaultVpcBySgName
=== CONT  TestAccAWSInstance_changeInstanceType
=== CONT  TestAccAWSInstance_creditSpecification_unlimitedCpuCredits
=== CONT  TestAccAWSInstance_associatePublic_overridePublic
--- PASS: TestAccAWSInstance_inDefaultVpcBySgName (151.66s)
=== CONT  TestAccAWSInstance_creditSpecification_standardCpuCredits
--- PASS: TestAccAWSInstance_changeInstanceType (209.21s)
=== CONT  TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard
--- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits (240.33s)
=== CONT  TestAccAWSInstance_CreditSpecification_UnspecifiedToEmpty_NonBurstable
--- PASS: TestAccAWSInstance_associatePublic_overridePublic (296.78s)
=== CONT  TestAccAWSInstance_CreditSpecification_Empty_NonBurstable
--- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits (229.40s)
=== CONT  TestAccAWSInstance_getPasswordData_trueToFalse
--- PASS: TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard (182.07s)
=== CONT  TestAccAWSInstance_getPasswordData_falseToTrue
--- PASS: TestAccAWSInstance_CreditSpecification_UnspecifiedToEmpty_NonBurstable (253.27s)
=== CONT  TestAccAWSInstance_associatePublic_overridePrivate
--- PASS: TestAccAWSInstance_CreditSpecification_Empty_NonBurstable (207.52s)
=== CONT  TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError
--- PASS: TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError (61.35s)
=== CONT  TestAccAWSInstance_forceNewAndTagsDrift
--- PASS: TestAccAWSInstance_getPasswordData_falseToTrue (193.21s)
=== CONT  TestAccAWSInstance_rootBlockDeviceMismatch
--- PASS: TestAccAWSInstance_getPasswordData_trueToFalse (264.32s)
=== CONT  TestAccAWSInstance_keyPairCheck
--- PASS: TestAccAWSInstance_associatePublic_overridePrivate (174.17s)
=== CONT  TestAccAWSInstance_associatePublicIPAndPrivateIP
--- PASS: TestAccAWSInstance_rootBlockDeviceMismatch (146.20s)
=== CONT  TestAccAWSInstance_privateIP
--- PASS: TestAccAWSInstance_keyPairCheck (126.06s)
=== CONT  TestAccAWSInstance_withIamInstanceProfile
--- PASS: TestAccAWSInstance_forceNewAndTagsDrift (261.86s)
=== CONT  TestAccAWSInstance_instanceProfileChange
--- PASS: TestAccAWSInstance_associatePublicIPAndPrivateIP (182.90s)
=== CONT  TestAccAWSInstance_volumeTagsComputed
--- PASS: TestAccAWSInstance_privateIP (172.96s)
=== CONT  TestAccAWSInstance_volumeTags
--- PASS: TestAccAWSInstance_withIamInstanceProfile (165.69s)
=== CONT  TestAccAWSInstance_tags
--- FAIL: TestAccAWSInstance_instanceProfileChange (199.42s)
    testing.go:654: Step 2 error: errors during apply:

        Error: error associating instance with instance profile: IncorrectState: ResultDetail: { Code=InstanceIdentityProfileNotFound, Message=InstanceIdentityProfile not found for the key: XXXXXXXXXXX/tf-testacc-instance-zpencexrtc7s, RequestId=edb3bfdd-477e-404a-8a76-344c472ca54b, ServerName=aws-ars-64108.pdx4.amazon.com, ServerIpAddress=10.222.9.82, DirectRequestPort=8819 }
        	status code: 400, request id: edb3bfdd-477e-404a-8a76-344c472ca54b

          on /var/folders/70/cl7fhhd51zj6_5kxr2dl3fwr0000gn/T/tf-test260028335/main.tf line 27:
          (source code not available)


=== CONT  TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs
--- PASS: TestAccAWSInstance_volumeTagsComputed (219.66s)
=== CONT  TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups
--- PASS: TestAccAWSInstance_tags (174.62s)
=== CONT  TestAccAWSInstance_NetworkInstanceSecurityGroups
--- PASS: TestAccAWSInstance_volumeTags (267.74s)
=== CONT  TestAccAWSInstance_multipleRegions
--- PASS: TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs (188.16s)
=== CONT  TestAccAWSInstance_ipv6_supportAddressCountWithIpv4
--- PASS: TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups (218.48s)
=== CONT  TestAccAWSInstance_creditSpecificationT3_updateCpuCredits
--- PASS: TestAccAWSInstance_NetworkInstanceSecurityGroups (193.10s)
=== CONT  TestAccAWSInstance_hibernation
--- PASS: TestAccAWSInstance_multipleRegions (264.45s)
=== CONT  TestAccAWSInstance_UserData_UnspecifiedToEmptyString
--- PASS: TestAccAWSInstance_ipv6_supportAddressCountWithIpv4 (227.15s)
=== CONT  TestAccAWSInstance_UserData_EmptyStringToUnspecified
--- PASS: TestAccAWSInstance_creditSpecificationT3_updateCpuCredits (330.34s)
=== CONT  TestAccAWSInstance_disappears
--- PASS: TestAccAWSInstance_hibernation (352.35s)
=== CONT  TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint
--- PASS: TestAccAWSInstance_UserData_EmptyStringToUnspecified (227.95s)
=== CONT  TestAccAWSInstance_blockDevices
--- PASS: TestAccAWSInstance_disappears (178.07s)
=== CONT  TestAccAWSInstance_ipv6_supportAddressCount
--- PASS: TestAccAWSInstance_UserData_UnspecifiedToEmptyString (374.58s)
=== CONT  TestAccAWSInstance_placementGroup
--- PASS: TestAccAWSInstance_blockDevices (143.56s)
=== CONT  TestAccAWSInstance_vpc
--- PASS: TestAccAWSInstance_placementGroup (257.67s)
=== CONT  TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint
=== CONT  TestAccAWSInstance_associatePublic_explicitPublic
--- PASS: TestAccAWSInstance_ipv6_supportAddressCount (272.27s)
--- FAIL: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint (469.80s)
    testing.go:715: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: errors during follow-up refresh: Error fetching Availability Zones: SerializationError: failed decoding EC2 Query response
        	status code: 200, request id:
        caused by: read tcp 192.168.1.101:64063->54.240.253.45:443: read: connection reset by peer

        State: <no state>
=== CONT  TestAccAWSInstance_associatePublic_defaultPublic
--- PASS: TestAccAWSInstance_vpc (356.69s)
=== CONT  TestAccAWSInstance_addSecondaryInterface
--- PASS: TestAccAWSInstance_associatePublic_explicitPublic (179.84s)
=== CONT  TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable
--- PASS: TestAccAWSInstance_associatePublic_defaultPublic (172.68s)
=== CONT  TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits
--- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint (373.86s)
=== CONT  TestAccAWSInstance_creditSpecificationT3_standardCpuCredits
--- PASS: TestAccAWSInstance_addSecondaryInterface (287.57s)
=== CONT  TestAccAWSInstance_primaryNetworkInterface
--- PASS: TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable (213.16s)
=== CONT  TestAccAWSInstance_RootBlockDevice_KmsKeyArn
--- PASS: TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits (236.47s)
=== CONT  TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited
--- PASS: TestAccAWSInstance_primaryNetworkInterface (182.90s)
=== CONT  TestAccAWSInstance_creditSpecification_updateCpuCredits
--- PASS: TestAccAWSInstance_RootBlockDevice_KmsKeyArn (208.33s)
=== CONT  TestAccAWSInstance_disableApiTermination
--- PASS: TestAccAWSInstance_creditSpecificationT3_standardCpuCredits (246.67s)
=== CONT  TestAccAWSInstance_associatePublic_explicitPrivate
--- PASS: TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited (154.89s)
=== CONT  TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2
--- PASS: TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2 (166.30s)
=== CONT  TestAccAWSInstance_sourceDestCheck
--- PASS: TestAccAWSInstance_associatePublic_explicitPrivate (182.83s)
=== CONT  TestAccAWSInstance_noAMIEphemeralDevices
--- PASS: TestAccAWSInstance_creditSpecification_updateCpuCredits (312.42s)
=== CONT  TestAccAWSInstance_GP2WithIopsValue
--- PASS: TestAccAWSInstance_noAMIEphemeralDevices (109.71s)
=== CONT  TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3
--- PASS: TestAccAWSInstance_disableApiTermination (399.05s)
=== CONT  TestAccAWSInstance_basic
--- PASS: TestAccAWSInstance_GP2WithIopsValue (152.45s)
=== CONT  TestAccAWSInstance_inEc2Classic
--- SKIP: TestAccAWSInstance_inEc2Classic (2.54s)
    provider_test.go:361: This test can only run in EC2 Classic, platforms available in us-west-2: ["VPC"]
=== CONT  TestAccAWSInstance_EbsBlockDevice_KmsKeyArn
--- PASS: TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3 (174.84s)
=== CONT  TestAccAWSInstance_GP2IopsDevice
--- PASS: TestAccAWSInstance_sourceDestCheck (339.95s)
=== CONT  TestAccAWSInstance_userDataBase64
--- PASS: TestAccAWSInstance_EbsBlockDevice_KmsKeyArn (166.66s)
=== CONT  TestAccAWSInstance_rootInstanceStore
--- PASS: TestAccAWSInstance_GP2IopsDevice (125.03s)
=== CONT  TestAccAWSInstance_addSecurityGroupNetworkInterface
--- PASS: TestAccAWSInstance_basic (257.08s)
=== CONT  TestAccAWSInstance_inDefaultVpcBySgId
--- PASS: TestAccAWSInstance_userDataBase64 (186.93s)
=== CONT  TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck
--- PASS: TestAccAWSInstance_rootInstanceStore (120.60s)
=== CONT  TestAccAWSInstance_associatePublic_defaultPrivate
--- PASS: TestAccAWSInstance_inDefaultVpcBySgId (153.84s)
--- PASS: TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck (171.40s)
--- PASS: TestAccAWSInstance_addSecurityGroupNetworkInterface (277.11s)
--- PASS: TestAccAWSInstance_associatePublic_defaultPrivate (165.72s)
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	3564.231s
FAIL
✘-1 ~/myrepos/terraform-provider-aws [bugfix/volume-tags|✔]
15:27 $ TF_ACC=1 go test ./aws -v -count 1 -parallel 4 -run="TestAccAWSInstance_instanceProfileChange" -timeout 120m
=== RUN   TestAccAWSInstance_instanceProfileChange
=== PAUSE TestAccAWSInstance_instanceProfileChange
=== CONT  TestAccAWSInstance_instanceProfileChange
--- PASS: TestAccAWSInstance_instanceProfileChange (334.54s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	336.547s
✔ ~/myrepos/terraform-provider-aws [bugfix/volume-tags|✔]
15:53 $ TF_ACC=1 go test ./aws -v -count 1 -parallel 4 -run="TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint" -timeout 120m
=== RUN   TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint
=== PAUSE TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint
=== CONT  TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint
--- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint (318.79s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	322.859s
✔ ~/myrepos/terraform-provider-aws [bugfix/volume-tags|✔]
16:06 $

@klebediev
Copy link
Contributor Author

@ewbankkit [sorry for mentioning], who might review this?
My project is affected by the bug, we would love to fix it asap.

@klebediev
Copy link
Contributor Author

@bflad (sorry for mentioning, I see you are the top contributor) might pls somebody take a look at this tiny pr fixing a bug affecting aws_instance resource after ~2m 🙏🏻 ? thanks

@dariosusman
Copy link

Shouldn't volume_tags be more useful within the root_block_device and/or ebs_block_device?

@feeblefakie
Copy link

I want this to be really merged. We are masking the issue by using ignore but that is not very good.

@klebediev
Copy link
Contributor Author

After 6 months is there anybody to review this PR? 😯

@VladislavAnd
Copy link

Until the PR isn't merged I suggest you use workaround:
Remove volume_tags from your aws_instance and add the following aws_ec2_tag:

resource "aws_ec2_tag" "root_volume_tags" {
  resource_id = aws_instance.this.root_block_device[0].volume_id
  key         = "Name"
  value       = "VALUE"
}  

@jpbuecken
Copy link

jpbuecken commented Sep 3, 2020

Until the PR isn't merged I suggest you use workaround:
Remove volume_tags from your aws_instance and add the following aws_ec2_tag:

resource "aws_ec2_tag" "root_volume_tags" {
  resource_id = aws_instance.this.root_block_device[0].volume_id
  key         = "Name"
  value       = "VALUE"
}  

It is not a nice workaround, since we need one resource per tag. A resource aws_ec2_tags that would allow a map would be a more sufficient workaround. .

@VladislavAnd
Copy link

It is not a nice workaround, since we need one resource per tag. A resource aws_ec2_tags that would allow a map would be a more sufficient workaround. .

You can use foreach. Yes, it is still one resource per tag, but all of them are managed by terraform.

resource "aws_ec2_tag" "root_volume_tags" {
  for_each = {
    Name   = "VALUE"
    ANOTHER_TAG = "ANOTHER_VALUE"
  }

  resource_id = aws_instance.this.root_block_device[0].volume_id
  key         = each.key
  value       = each.value
}

@YakDriver
Copy link
Member

@klebediev Thank you for your work on this! 👍 Are you willing to work on it with me over the next few days? First thing is that because of the time, it needs the conflicts to be resolved. After that, you and I can dig into it.

@YakDriver YakDriver added partition/aws-us-gov Pertains to the aws-us-gov partition. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 10, 2020
@klebediev
Copy link
Contributor Author

hi @YakDriver , rebased, conflicts resolved, acceptance tests are still fine.

13:19 $ TF_ACC=1 go test ./aws -v -count 1 -parallel 4 -run="TestAccAWSInstance_" -timeout 120m
=== RUN   TestAccAWSInstance_inDefaultVpcBySgName
=== PAUSE TestAccAWSInstance_inDefaultVpcBySgName
=== RUN   TestAccAWSInstance_inDefaultVpcBySgId
=== PAUSE TestAccAWSInstance_inDefaultVpcBySgId
=== RUN   TestAccAWSInstance_inEc2Classic
=== PAUSE TestAccAWSInstance_inEc2Classic
=== RUN   TestAccAWSInstance_basic
=== PAUSE TestAccAWSInstance_basic
=== RUN   TestAccAWSInstance_atLeastOneOtherEbsVolume
=== PAUSE TestAccAWSInstance_atLeastOneOtherEbsVolume
=== RUN   TestAccAWSInstance_EbsBlockDevice_KmsKeyArn
=== PAUSE TestAccAWSInstance_EbsBlockDevice_KmsKeyArn
=== RUN   TestAccAWSInstance_EbsBlockDevice_InvalidIopsForVolumeType
=== PAUSE TestAccAWSInstance_EbsBlockDevice_InvalidIopsForVolumeType
=== RUN   TestAccAWSInstance_RootBlockDevice_KmsKeyArn
=== PAUSE TestAccAWSInstance_RootBlockDevice_KmsKeyArn
=== RUN   TestAccAWSInstance_userDataBase64
=== PAUSE TestAccAWSInstance_userDataBase64
=== RUN   TestAccAWSInstance_GP2IopsDevice
=== PAUSE TestAccAWSInstance_GP2IopsDevice
=== RUN   TestAccAWSInstance_GP2WithIopsValue
=== PAUSE TestAccAWSInstance_GP2WithIopsValue
=== RUN   TestAccAWSInstance_blockDevices
=== PAUSE TestAccAWSInstance_blockDevices
=== RUN   TestAccAWSInstance_rootInstanceStore
=== PAUSE TestAccAWSInstance_rootInstanceStore
=== RUN   TestAccAWSInstance_noAMIEphemeralDevices
=== PAUSE TestAccAWSInstance_noAMIEphemeralDevices
=== RUN   TestAccAWSInstance_sourceDestCheck
=== PAUSE TestAccAWSInstance_sourceDestCheck
=== RUN   TestAccAWSInstance_disableApiTermination
=== PAUSE TestAccAWSInstance_disableApiTermination
=== RUN   TestAccAWSInstance_vpc
=== PAUSE TestAccAWSInstance_vpc
=== RUN   TestAccAWSInstance_outpost
=== PAUSE TestAccAWSInstance_outpost
=== RUN   TestAccAWSInstance_placementGroup
=== PAUSE TestAccAWSInstance_placementGroup
=== RUN   TestAccAWSInstance_ipv6_supportAddressCount
=== PAUSE TestAccAWSInstance_ipv6_supportAddressCount
=== RUN   TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError
=== PAUSE TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError
=== RUN   TestAccAWSInstance_ipv6_supportAddressCountWithIpv4
=== PAUSE TestAccAWSInstance_ipv6_supportAddressCountWithIpv4
=== RUN   TestAccAWSInstance_multipleRegions
=== PAUSE TestAccAWSInstance_multipleRegions
=== RUN   TestAccAWSInstance_NetworkInstanceSecurityGroups
=== PAUSE TestAccAWSInstance_NetworkInstanceSecurityGroups
=== RUN   TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups
=== PAUSE TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups
=== RUN   TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs
=== PAUSE TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs
=== RUN   TestAccAWSInstance_tags
=== PAUSE TestAccAWSInstance_tags
=== RUN   TestAccAWSInstance_volumeTags
=== PAUSE TestAccAWSInstance_volumeTags
=== RUN   TestAccAWSInstance_volumeTagsComputed
=== PAUSE TestAccAWSInstance_volumeTagsComputed
=== RUN   TestAccAWSInstance_instanceProfileChange
=== PAUSE TestAccAWSInstance_instanceProfileChange
=== RUN   TestAccAWSInstance_withIamInstanceProfile
=== PAUSE TestAccAWSInstance_withIamInstanceProfile
=== RUN   TestAccAWSInstance_privateIP
=== PAUSE TestAccAWSInstance_privateIP
=== RUN   TestAccAWSInstance_associatePublicIPAndPrivateIP
=== PAUSE TestAccAWSInstance_associatePublicIPAndPrivateIP
=== RUN   TestAccAWSInstance_Empty_PrivateIP
=== PAUSE TestAccAWSInstance_Empty_PrivateIP
=== RUN   TestAccAWSInstance_keyPairCheck
=== PAUSE TestAccAWSInstance_keyPairCheck
=== RUN   TestAccAWSInstance_rootBlockDeviceMismatch
=== PAUSE TestAccAWSInstance_rootBlockDeviceMismatch
=== RUN   TestAccAWSInstance_forceNewAndTagsDrift
=== PAUSE TestAccAWSInstance_forceNewAndTagsDrift
=== RUN   TestAccAWSInstance_changeInstanceType
=== PAUSE TestAccAWSInstance_changeInstanceType
=== RUN   TestAccAWSInstance_EbsRootDevice_basic
=== PAUSE TestAccAWSInstance_EbsRootDevice_basic
=== RUN   TestAccAWSInstance_EbsRootDevice_ModifySize
=== PAUSE TestAccAWSInstance_EbsRootDevice_ModifySize
=== RUN   TestAccAWSInstance_EbsRootDevice_ModifyType
=== PAUSE TestAccAWSInstance_EbsRootDevice_ModifyType
=== RUN   TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io1
=== PAUSE TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io1
=== RUN   TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io2
=== PAUSE TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io2
=== RUN   TestAccAWSInstance_EbsRootDevice_ModifyDeleteOnTermination
=== PAUSE TestAccAWSInstance_EbsRootDevice_ModifyDeleteOnTermination
=== RUN   TestAccAWSInstance_EbsRootDevice_ModifyAll
=== PAUSE TestAccAWSInstance_EbsRootDevice_ModifyAll
=== RUN   TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifySize
=== PAUSE TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifySize
=== RUN   TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifyDeleteOnTermination
=== PAUSE TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifyDeleteOnTermination
=== RUN   TestAccAWSInstance_EbsRootDevice_MultipleDynamicEBSBlockDevices
=== PAUSE TestAccAWSInstance_EbsRootDevice_MultipleDynamicEBSBlockDevices
=== RUN   TestAccAWSInstance_primaryNetworkInterface
=== PAUSE TestAccAWSInstance_primaryNetworkInterface
=== RUN   TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck
=== PAUSE TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck
=== RUN   TestAccAWSInstance_addSecondaryInterface
=== PAUSE TestAccAWSInstance_addSecondaryInterface
=== RUN   TestAccAWSInstance_addSecurityGroupNetworkInterface
=== PAUSE TestAccAWSInstance_addSecurityGroupNetworkInterface
=== RUN   TestAccAWSInstance_NewNetworkInterface_PublicIPAndSecondaryPrivateIPs
=== PAUSE TestAccAWSInstance_NewNetworkInterface_PublicIPAndSecondaryPrivateIPs
=== RUN   TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPs
=== PAUSE TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPs
=== RUN   TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPsUpdate
=== PAUSE TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPsUpdate
=== RUN   TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPs
=== PAUSE TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPs
=== RUN   TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPsUpdate
=== PAUSE TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPsUpdate
=== RUN   TestAccAWSInstance_associatePublic_defaultPrivate
=== PAUSE TestAccAWSInstance_associatePublic_defaultPrivate
=== RUN   TestAccAWSInstance_associatePublic_defaultPublic
=== PAUSE TestAccAWSInstance_associatePublic_defaultPublic
=== RUN   TestAccAWSInstance_associatePublic_explicitPublic
=== PAUSE TestAccAWSInstance_associatePublic_explicitPublic
=== RUN   TestAccAWSInstance_associatePublic_explicitPrivate
=== PAUSE TestAccAWSInstance_associatePublic_explicitPrivate
=== RUN   TestAccAWSInstance_associatePublic_overridePublic
=== PAUSE TestAccAWSInstance_associatePublic_overridePublic
=== RUN   TestAccAWSInstance_associatePublic_overridePrivate
=== PAUSE TestAccAWSInstance_associatePublic_overridePrivate
=== RUN   TestAccAWSInstance_getPasswordData_falseToTrue
=== PAUSE TestAccAWSInstance_getPasswordData_falseToTrue
=== RUN   TestAccAWSInstance_getPasswordData_trueToFalse
=== PAUSE TestAccAWSInstance_getPasswordData_trueToFalse
=== RUN   TestAccAWSInstance_CreditSpecification_Empty_NonBurstable
=== PAUSE TestAccAWSInstance_CreditSpecification_Empty_NonBurstable
=== RUN   TestAccAWSInstance_CreditSpecification_UnspecifiedToEmpty_NonBurstable
=== PAUSE TestAccAWSInstance_CreditSpecification_UnspecifiedToEmpty_NonBurstable
=== RUN   TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard
=== PAUSE TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard
=== RUN   TestAccAWSInstance_creditSpecification_standardCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecification_standardCpuCredits
=== RUN   TestAccAWSInstance_creditSpecification_unlimitedCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecification_unlimitedCpuCredits
=== RUN   TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2
=== PAUSE TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2
=== RUN   TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3
=== PAUSE TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3
=== RUN   TestAccAWSInstance_creditSpecification_updateCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecification_updateCpuCredits
=== RUN   TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable
=== PAUSE TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable
=== RUN   TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited
=== PAUSE TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited
=== RUN   TestAccAWSInstance_creditSpecificationT3_standardCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecificationT3_standardCpuCredits
=== RUN   TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits
=== RUN   TestAccAWSInstance_creditSpecificationT3_updateCpuCredits
=== PAUSE TestAccAWSInstance_creditSpecificationT3_updateCpuCredits
=== RUN   TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint
=== PAUSE TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint
=== RUN   TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint
=== PAUSE TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint
=== RUN   TestAccAWSInstance_disappears
=== PAUSE TestAccAWSInstance_disappears
=== RUN   TestAccAWSInstance_UserData_EmptyStringToUnspecified
=== PAUSE TestAccAWSInstance_UserData_EmptyStringToUnspecified
=== RUN   TestAccAWSInstance_UserData_UnspecifiedToEmptyString
=== PAUSE TestAccAWSInstance_UserData_UnspecifiedToEmptyString
=== RUN   TestAccAWSInstance_hibernation
=== PAUSE TestAccAWSInstance_hibernation
=== RUN   TestAccAWSInstance_metadataOptions
=== PAUSE TestAccAWSInstance_metadataOptions
=== CONT  TestAccAWSInstance_inDefaultVpcBySgName
=== CONT  TestAccAWSInstance_EbsRootDevice_ModifyDeleteOnTermination
=== CONT  TestAccAWSInstance_multipleRegions
=== CONT  TestAccAWSInstance_Empty_PrivateIP
--- PASS: TestAccAWSInstance_inDefaultVpcBySgName (107.85s)
=== CONT  TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io2
--- PASS: TestAccAWSInstance_Empty_PrivateIP (121.26s)
=== CONT  TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io1
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyDeleteOnTermination (121.99s)
=== CONT  TestAccAWSInstance_EbsRootDevice_ModifyType
--- PASS: TestAccAWSInstance_multipleRegions (165.57s)
=== CONT  TestAccAWSInstance_EbsRootDevice_ModifySize
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io1 (138.93s)
=== CONT  TestAccAWSInstance_EbsRootDevice_basic
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyType (141.14s)
=== CONT  TestAccAWSInstance_changeInstanceType
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifySize (140.91s)
=== CONT  TestAccAWSInstance_forceNewAndTagsDrift
--- PASS: TestAccAWSInstance_EbsRootDevice_basic (82.00s)
=== CONT  TestAccAWSInstance_rootBlockDeviceMismatch
    provider_test.go:557: skipping tests; AWS_DEFAULT_REGION (us-east-1) does not equal us-west-2
--- SKIP: TestAccAWSInstance_rootBlockDeviceMismatch (1.48s)
=== CONT  TestAccAWSInstance_keyPairCheck
=== CONT  TestAccAWSInstance_forceNewAndTagsDrift
    resource_aws_instance_test.go:1454: [INFO] Got non-empty plan, as expected
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io2 (257.58s)
=== CONT  TestAccAWSInstance_volumeTagsComputed
--- PASS: TestAccAWSInstance_keyPairCheck (98.90s)
=== CONT  TestAccAWSInstance_associatePublicIPAndPrivateIP
--- PASS: TestAccAWSInstance_changeInstanceType (184.96s)
=== CONT  TestAccAWSInstance_privateIP
--- PASS: TestAccAWSInstance_forceNewAndTagsDrift (193.34s)
=== CONT  TestAccAWSInstance_getPasswordData_falseToTrue
--- PASS: TestAccAWSInstance_volumeTagsComputed (178.47s)
=== CONT  TestAccAWSInstance_associatePublic_overridePrivate
--- PASS: TestAccAWSInstance_privateIP (109.90s)
=== CONT  TestAccAWSInstance_withIamInstanceProfile
--- PASS: TestAccAWSInstance_associatePublicIPAndPrivateIP (120.91s)
=== CONT  TestAccAWSInstance_associatePublic_overridePublic
--- PASS: TestAccAWSInstance_associatePublic_overridePrivate (104.02s)
=== CONT  TestAccAWSInstance_instanceProfileChange
--- PASS: TestAccAWSInstance_getPasswordData_falseToTrue (154.38s)
=== CONT  TestAccAWSInstance_associatePublic_explicitPrivate
=== CONT  TestAccAWSInstance_creditSpecificationT3_standardCpuCredits
--- PASS: TestAccAWSInstance_associatePublic_overridePublic (114.12s)
--- PASS: TestAccAWSInstance_withIamInstanceProfile (152.30s)
=== CONT  TestAccAWSInstance_associatePublic_explicitPublic
--- PASS: TestAccAWSInstance_associatePublic_explicitPrivate (125.01s)
=== CONT  TestAccAWSInstance_metadataOptions
--- PASS: TestAccAWSInstance_associatePublic_explicitPublic (115.38s)
=== CONT  TestAccAWSInstance_associatePublic_defaultPublic
--- PASS: TestAccAWSInstance_creditSpecificationT3_standardCpuCredits (172.13s)
=== CONT  TestAccAWSInstance_hibernation
--- PASS: TestAccAWSInstance_instanceProfileChange (253.99s)
=== CONT  TestAccAWSInstance_associatePublic_defaultPrivate
--- PASS: TestAccAWSInstance_associatePublic_defaultPublic (126.58s)
=== CONT  TestAccAWSInstance_getPasswordData_trueToFalse
--- PASS: TestAccAWSInstance_metadataOptions (183.89s)
=== CONT  TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited
--- PASS: TestAccAWSInstance_associatePublic_defaultPrivate (103.92s)
=== CONT  TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable
--- PASS: TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited (124.44s)
=== CONT  TestAccAWSInstance_creditSpecification_updateCpuCredits
--- PASS: TestAccAWSInstance_hibernation (264.60s)
=== CONT  TestAccAWSInstance_UserData_UnspecifiedToEmptyString
--- PASS: TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable (133.18s)
=== CONT  TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPsUpdate
--- PASS: TestAccAWSInstance_getPasswordData_trueToFalse (203.95s)
=== CONT  TestAccAWSInstance_UserData_EmptyStringToUnspecified
--- PASS: TestAccAWSInstance_UserData_UnspecifiedToEmptyString (140.60s)
=== CONT  TestAccAWSInstance_disappears
--- PASS: TestAccAWSInstance_creditSpecification_updateCpuCredits (186.52s)
=== CONT  TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint
--- PASS: TestAccAWSInstance_UserData_EmptyStringToUnspecified (130.41s)
=== CONT  TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint
--- PASS: TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPsUpdate (215.48s)
=== CONT  TestAccAWSInstance_creditSpecificationT3_updateCpuCredits
=== CONT  TestAccAWSInstance_disappears
    resource_aws_instance_test.go:3006: [INFO] Got non-empty plan, as expected
--- PASS: TestAccAWSInstance_disappears (110.73s)
=== CONT  TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits
--- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint (215.86s)
=== CONT  TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPs
--- PASS: TestAccAWSInstance_creditSpecificationT3_updateCpuCredits (187.36s)
=== CONT  TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck
--- PASS: TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits (178.11s)
=== CONT  TestAccAWSInstance_primaryNetworkInterface
--- PASS: TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck (120.76s)
=== CONT  TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPsUpdate
--- PASS: TestAccAWSInstance_primaryNetworkInterface (120.21s)
=== CONT  TestAccAWSInstance_EbsRootDevice_MultipleDynamicEBSBlockDevices
--- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint (439.18s)
=== CONT  TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPs
--- PASS: TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPs (328.51s)
=== CONT  TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifyDeleteOnTermination
--- PASS: TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPsUpdate (172.60s)
=== CONT  TestAccAWSInstance_NewNetworkInterface_PublicIPAndSecondaryPrivateIPs
--- PASS: TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPs (126.01s)
=== CONT  TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifySize
--- PASS: TestAccAWSInstance_EbsRootDevice_MultipleDynamicEBSBlockDevices (204.78s)
=== CONT  TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3
--- PASS: TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifyDeleteOnTermination (120.94s)
=== CONT  TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2
--- PASS: TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3 (114.38s)
=== CONT  TestAccAWSInstance_creditSpecification_unlimitedCpuCredits
--- PASS: TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifySize (150.63s)
=== CONT  TestAccAWSInstance_creditSpecification_standardCpuCredits
--- PASS: TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2 (115.49s)
=== CONT  TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard
--- PASS: TestAccAWSInstance_NewNetworkInterface_PublicIPAndSecondaryPrivateIPs (262.47s)
=== CONT  TestAccAWSInstance_addSecurityGroupNetworkInterface
--- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits (138.31s)
=== CONT  TestAccAWSInstance_CreditSpecification_Empty_NonBurstable
--- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits (148.35s)
=== CONT  TestAccAWSInstance_addSecondaryInterface
--- PASS: TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard (105.19s)
=== CONT  TestAccAWSInstance_EbsBlockDevice_InvalidIopsForVolumeType
--- PASS: TestAccAWSInstance_EbsBlockDevice_InvalidIopsForVolumeType (12.33s)
=== CONT  TestAccAWSInstance_blockDevices
--- PASS: TestAccAWSInstance_CreditSpecification_Empty_NonBurstable (136.24s)
=== CONT  TestAccAWSInstance_GP2WithIopsValue
--- PASS: TestAccAWSInstance_GP2WithIopsValue (11.76s)
=== CONT  TestAccAWSInstance_ipv6_supportAddressCountWithIpv4
--- PASS: TestAccAWSInstance_addSecurityGroupNetworkInterface (181.78s)
=== CONT  TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError
--- PASS: TestAccAWSInstance_blockDevices (105.18s)
=== CONT  TestAccAWSInstance_EbsRootDevice_ModifyAll
--- PASS: TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError (25.01s)
=== CONT  TestAccAWSInstance_ipv6_supportAddressCount
--- PASS: TestAccAWSInstance_addSecondaryInterface (178.15s)
=== CONT  TestAccAWSInstance_basic
--- PASS: TestAccAWSInstance_ipv6_supportAddressCountWithIpv4 (115.32s)
=== CONT  TestAccAWSInstance_placementGroup
--- PASS: TestAccAWSInstance_ipv6_supportAddressCount (104.01s)
=== CONT  TestAccAWSInstance_outpost
    data_source_aws_outposts_outposts_test.go:66: skipping since no Outposts Outpost found
--- SKIP: TestAccAWSInstance_outpost (2.90s)
=== CONT  TestAccAWSInstance_CreditSpecification_UnspecifiedToEmpty_NonBurstable
--- PASS: TestAccAWSInstance_basic (104.62s)
=== CONT  TestAccAWSInstance_vpc
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyAll (154.24s)
=== CONT  TestAccAWSInstance_disableApiTermination
--- PASS: TestAccAWSInstance_placementGroup (104.11s)
=== CONT  TestAccAWSInstance_sourceDestCheck
--- PASS: TestAccAWSInstance_CreditSpecification_UnspecifiedToEmpty_NonBurstable (117.51s)
=== CONT  TestAccAWSInstance_inEc2Classic
    provider_test.go:492: This test can only run in EC2 Classic, platforms available in us-east-1: ["VPC"]
--- SKIP: TestAccAWSInstance_inEc2Classic (1.56s)
=== CONT  TestAccAWSInstance_noAMIEphemeralDevices
--- PASS: TestAccAWSInstance_vpc (119.54s)
=== CONT  TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs
=== CONT  TestAccAWSInstance_disableApiTermination
    resource_aws_instance_test.go:743: After applying this test step and performing a `terraform refresh`, the plan was not empty.
        stdout


        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_instance.test will be created
          + resource "aws_instance" "test" {
              + ami                          = "ami-0aa598aa110a431df"
              + arn                          = (known after apply)
              + associate_public_ip_address  = (known after apply)
              + availability_zone            = (known after apply)
              + cpu_core_count               = (known after apply)
              + cpu_threads_per_core         = (known after apply)
              + disable_api_termination      = true
              + get_password_data            = false
              + host_id                      = (known after apply)
              + id                           = (known after apply)
              + instance_state               = (known after apply)
              + instance_type                = "m1.small"
              + ipv6_address_count           = (known after apply)
              + ipv6_addresses               = (known after apply)
              + key_name                     = (known after apply)
              + outpost_arn                  = (known after apply)
              + password_data                = (known after apply)
              + placement_group              = (known after apply)
              + primary_network_interface_id = (known after apply)
              + private_dns                  = (known after apply)
              + private_ip                   = (known after apply)
              + public_dns                   = (known after apply)
              + public_ip                    = (known after apply)
              + secondary_private_ips        = (known after apply)
              + security_groups              = (known after apply)
              + source_dest_check            = true
              + subnet_id                    = (known after apply)
              + tenancy                      = (known after apply)
              + volume_tags                  = (known after apply)
              + vpc_security_group_ids       = (known after apply)

              + ebs_block_device {
                  + delete_on_termination = (known after apply)
                  + device_name           = (known after apply)
                  + encrypted             = (known after apply)
                  + iops                  = (known after apply)
                  + kms_key_id            = (known after apply)
                  + snapshot_id           = (known after apply)
                  + volume_id             = (known after apply)
                  + volume_size           = (known after apply)
                  + volume_type           = (known after apply)
                }

              + ephemeral_block_device {
                  + device_name  = (known after apply)
                  + no_device    = (known after apply)
                  + virtual_name = (known after apply)
                }

              + metadata_options {
                  + http_endpoint               = (known after apply)
                  + http_put_response_hop_limit = (known after apply)
                  + http_tokens                 = (known after apply)
                }

              + network_interface {
                  + delete_on_termination = (known after apply)
                  + device_index          = (known after apply)
                  + network_interface_id  = (known after apply)
                }

              + root_block_device {
                  + delete_on_termination = (known after apply)
                  + device_name           = (known after apply)
                  + encrypted             = (known after apply)
                  + iops                  = (known after apply)
                  + kms_key_id            = (known after apply)
                  + volume_id             = (known after apply)
                  + volume_size           = (known after apply)
                  + volume_type           = (known after apply)
                }
            }

          # aws_subnet.test will be created
          + resource "aws_subnet" "test" {
              + arn                             = (known after apply)
              + assign_ipv6_address_on_creation = false
              + availability_zone               = "us-west-2a"
              + availability_zone_id            = (known after apply)
              + cidr_block                      = "10.1.1.0/24"
              + id                              = (known after apply)
              + ipv6_cidr_block_association_id  = (known after apply)
              + map_public_ip_on_launch         = false
              + owner_id                        = (known after apply)
              + tags                            = {
                  + "Name" = "tf-testacc-instance-8cd8o1i0nlfs"
                }
              + vpc_id                          = (known after apply)
            }

          # aws_vpc.test will be created
          + resource "aws_vpc" "test" {
              + arn                              = (known after apply)
              + assign_generated_ipv6_cidr_block = false
              + cidr_block                       = "10.1.0.0/16"
              + default_network_acl_id           = (known after apply)
              + default_route_table_id           = (known after apply)
              + default_security_group_id        = (known after apply)
              + dhcp_options_id                  = (known after apply)
              + enable_classiclink               = (known after apply)
              + enable_classiclink_dns_support   = (known after apply)
              + enable_dns_hostnames             = (known after apply)
              + enable_dns_support               = true
              + id                               = (known after apply)
              + instance_tenancy                 = "default"
              + ipv6_association_id              = (known after apply)
              + ipv6_cidr_block                  = (known after apply)
              + main_route_table_id              = (known after apply)
              + owner_id                         = (known after apply)
              + tags                             = {
                  + "Name" = "tf-testacc-instance-8cd8o1i0nlfs"
                }
            }

        Plan: 3 to add, 0 to change, 0 to destroy.
--- FAIL: TestAccAWSInstance_disableApiTermination (100.17s)
=== CONT  TestAccAWSInstance_rootInstanceStore
=== CONT  TestAccAWSInstance_sourceDestCheck
    resource_aws_instance_test.go:684: Check 1/2 error: InvalidInstanceID.NotFound: The instance ID 'i-04d9c8aa6addb3040' does not exist
        	status code: 400, request id: 4dbbb3e5-27e0-4f71-806b-b07fb5cdea6c
--- FAIL: TestAccAWSInstance_sourceDestCheck (105.54s)
=== CONT  TestAccAWSInstance_volumeTags
--- PASS: TestAccAWSInstance_noAMIEphemeralDevices (100.88s)
=== CONT  TestAccAWSInstance_atLeastOneOtherEbsVolume
--- PASS: TestAccAWSInstance_rootInstanceStore (121.54s)
=== CONT  TestAccAWSInstance_tags
--- PASS: TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs (150.99s)
=== CONT  TestAccAWSInstance_GP2IopsDevice
--- PASS: TestAccAWSInstance_GP2IopsDevice (116.74s)
=== CONT  TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups
--- PASS: TestAccAWSInstance_tags (154.05s)
=== CONT  TestAccAWSInstance_NetworkInstanceSecurityGroups
--- PASS: TestAccAWSInstance_volumeTags (222.03s)
=== CONT  TestAccAWSInstance_RootBlockDevice_KmsKeyArn
--- PASS: TestAccAWSInstance_atLeastOneOtherEbsVolume (238.67s)
=== CONT  TestAccAWSInstance_inDefaultVpcBySgId
2020/09/11 14:08:07 [WARN] Truncating attribute path of 0 diagnostics for TypeSet
--- PASS: TestAccAWSInstance_RootBlockDevice_KmsKeyArn (128.13s)
=== CONT  TestAccAWSInstance_EbsBlockDevice_KmsKeyArn
--- PASS: TestAccAWSInstance_NetworkInstanceSecurityGroups (150.49s)
=== CONT  TestAccAWSInstance_userDataBase64
--- PASS: TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups (172.57s)
--- PASS: TestAccAWSInstance_inDefaultVpcBySgId (122.79s)
--- PASS: TestAccAWSInstance_EbsBlockDevice_KmsKeyArn (131.31s)
--- PASS: TestAccAWSInstance_userDataBase64 (173.97s)
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	3146.574s
FAIL
✘-1 ~/myrepos/terraform-provider-aws [bugfix/volume-tags ↓·1↑·3446|✚ 1]
14:12 $ export AWS_DEFAULT_REGION=us-west-2
✔ ~/myrepos/terraform-provider-aws [bugfix/volume-tags ↓·1↑·3446|✚ 1]
14:15 $ TF_ACC=1 go test ./aws -v -count 1 -parallel 4 -run="TestAccAWSInstance_disableApiTermination" -timeout 120m
=== RUN   TestAccAWSInstance_disableApiTermination
=== PAUSE TestAccAWSInstance_disableApiTermination
=== CONT  TestAccAWSInstance_disableApiTermination
--- PASS: TestAccAWSInstance_disableApiTermination (224.10s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	226.445s
✔ ~/myrepos/terraform-provider-aws [bugfix/volume-tags ↓·1↑·3446|✚ 1]
14:19 $ TF_ACC=1 go test ./aws -v -count 1 -parallel 4 -run="TestAccAWSInstance_sourceDestCheck" -timeout 120m
=== RUN   TestAccAWSInstance_sourceDestCheck
=== PAUSE TestAccAWSInstance_sourceDestCheck
=== CONT  TestAccAWSInstance_sourceDestCheck
--- PASS: TestAccAWSInstance_sourceDestCheck (290.01s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	292.056s

@klebediev
Copy link
Contributor Author

klebediev commented Sep 11, 2020

Are you willing to work on it with me over the next few days?

Yes, I'm ready

@YakDriver YakDriver added the breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. label Sep 14, 2020
@YakDriver
Copy link
Member

@klebediev The biggest challenge is that this appears to be a breaking change. If it is, we'll have to wait until at least v4.0.0.

Is this a breaking change?

Although test TestAccAWSInstance_volumeTags passes with this PR, if we check each of the volumes, are the tags right? What if the resource was imported and Terraform doesn't know about the configuration? How will volume tags be updated? There's some mess with that that's concerning.

What's the best way forward?

Your PR is an awesome, narrowly-tailored fix to the problem. That is much appreciated and 99% of the time that's the perfect thing. However, stepping back, this might be the 1% when we need a broader fix. The issue really comes from the way the AWS SDK/API works. It would be fantastic to be able to put a clean and functional abstraction around it.

Really volume_tags needs to go away altogether so that tags can be managed per volume. That will impact people who are currently relying volume_tags. But, also volume_tags seems to be the direction that the AWS SDK/API pushes the implementation: https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#RunInstancesInput

@klebediev
Copy link
Contributor Author

Thanks for reviewing @YakDriver !

I do agree the source of this mess with volume_tags is AWS API.

Regarding this issue, It's not possible to describe tags attached to multiple volumes by a single parameter.
The idea of this PR is: manage tags for all volumes on Create, but manage tags for root volume only on Update/Import.

Pretty much similar to the approach used for ebs_block_devices:

Currently, changes to the ebs_block_device configuration of existing resources cannot be automatically detected by Terraform. To manage changes and attachments of an EBS block to an instance, use the aws_ebs_volume and aws_volume_attachment resources instead.

link

Does this sound sane?
Anything else (except waiting for 4.0 😄 ) I could do to help with resolving the issue?

@ToonSpinISAAC
Copy link

@YakDriver I don't see why this being a breaking change should be a reason not to push it. The reason I say that is that I feel this is not a change, but a bug, because right now it's not working as documented, and it's not a problem in the documentation.

I'm not saying the bug originates in Terraform per se, but I do feel that this is not a change but a fix, and that pushing this change doesn't break things, but that things are broken now and will remain broken until this change is pushed.

For this reason I'd like to ask you not to hold off as this is in fact keeping us from tagging our root volumes properly.

@YakDriver
Copy link
Member

@klebediev @ToonSpinISAAC Thanks for your comments. To be sure, I agree that it is currently broken! However, it is broken for configurations using aws_ebs_volume with aws_volume_attachment. For configurations just using volume_tags with no aws_volume_attachment, it is working. Please correct me if I'm wrong.

There is much you can do to help!

Group 1: Using aws_volume_attachment

We all agree that configurations in this category are not working as intended.

Group 2: Not using aws_volume_attachment

I do not believe that the acceptance tests as they stand now will reveal volume_tags problems with this fix. Please prove me right or wrong! Provide configurations (no need to write a test, just the HCL will work) either showing that:

  1. Configurations using volume_tags without aws_volume_attachment are currently broken, or
  2. Configurations using volume_tags without aws_volume_attachment won't be broken by this PR's changes

If you have time to help with this, I very much appreciate it.

@klebediev
Copy link
Contributor Author

Configurations using volume_tags without aws_volume_attachment are currently broken

Easy. Actually the simplest configuration without aws_volume_attachment is broken. For example:

provider "aws" {
  region = "us-east-1"
}

data "aws_ami" "ubuntu" {
  most_recent = true

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

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

  owners = ["099720109477"] # Canonical
}

resource "aws_instance" "web" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t3.micro"

  tags = {
    Name = "tfbug-tst"
  }

  volume_tags = {
    "foo" = "bar"
    "abc" = "xyz"
  }

  ebs_block_device {
    device_name = "/dev/xvdf"
    volume_size = 1
  }
}
terraform apply
# then go to AWS Console, modify tag  `abc` -> `xyzzzzzz` for root EBS device
terraform apply
# Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

As single parameter is used to describe changes for multiple volumes we can "invent" more and more test cases. There will be issues with importing etc

@klebediev
Copy link
Contributor Author

btw what's funny this PR will properly handle above particular situation 😄

@YakDriver
Copy link
Member

YakDriver commented Sep 17, 2020

@klebediev I will discuss this further internally. I see that the problem is worse than anticipated and your fix so far appears better than the current situation in all ways. My thinking is shifting to this being an incremental improvement rather than a breaking change. Really now the time-consuming thing will be to figure out the problems with the fix and if any of those are worse than as-is. What problems are there with your fix? How can it be tricked to still break?

@klebediev
Copy link
Contributor Author

thanks @YakDriver
The only 'degradation' I see comparing to master is: when there is no volume_tags drift => tags attached to all volumes 'belonging' to the instance will be updated on volume_tags update in tf resource whereas in case of my fix only root volume tags will be updated and all other volume tags will be intact.
But, if we apply this to combination of aws_instance + aws_ebs_volume + aws_volume_attachment things won't work properly at all (this combination doesn't work properly even without volume_tags update: just 2 sequential terraform applyes without changes would be enough to see the issue)

@klebediev
Copy link
Contributor Author

We use volume_tags to tag root volume, the same as @ToonSpinISAAC mentioned, whereas all other attached volumes are managed via aws_ebs_volume + aws_volume_attachment combination because of limitations of ebs_block_device parameter:

Currently, changes to the ebs_block_device configuration of existing resources cannot be automatically detected by Terraform. To manage changes and attachments of an EBS block to an instance, use the aws_ebs_volume and aws_volume_attachment resources instead.

@YakDriver
Copy link
Member

We have merged a fix to the volume_tags issue in #15474. We have added tests to cover the issues observed. Please note that using volume_tags in aws_instance is not compatible with using tags in aws_ebs_volume. You need to use one or the other. Prior to this fix, even following this rule, you would encounter errors. Along with the fix, we've added tags to the root_block_device and ebs_block_device configuration blocks in aws_instance.

Now that the fix is in place, if you find any problems with volume_tags, let us know by opening a new issue.

@ghost
Copy link

ghost commented Feb 13, 2021

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 as resolved and limited conversation to collaborators Feb 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. partition/aws-us-gov Pertains to the aws-us-gov partition. service/ec2 Issues and PRs that pertain to the ec2 service. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

r/aws_instance: volume_tags works incorrectly with aws_volume_attachment resources
9 participants