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: Add tags parameter to root_block_device, ebs_block_device blocks (#12225) #15474

Merged
merged 9 commits into from
Jan 13, 2021

Conversation

klebediev
Copy link
Contributor

@klebediev klebediev commented Oct 4, 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, closes #17074, closes #5878, closes #5609, closes #5080, closes #770, closes #729, closes #884, closes #9156, closes #12226, closes #9033
Similar PR #12226 #9156

Release note for CHANGELOG:

 - resource/aws_instance: Add `tags` parameter to `root_block_device`, `ebs_block_device` blocks. 

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSInstance_.*olumeTags'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSInstance_.*olumeTags -timeout 120m
=== RUN   TestAccAWSInstance_volumeTags
=== PAUSE TestAccAWSInstance_volumeTags
=== RUN   TestAccAWSInstance_rootVolumeTags
=== PAUSE TestAccAWSInstance_rootVolumeTags
=== RUN   TestAccAWSInstance_volumeTagsComputed
=== PAUSE TestAccAWSInstance_volumeTagsComputed
=== RUN   TestAccAWSInstance_rootVolumeTagsEbsAttached
=== PAUSE TestAccAWSInstance_rootVolumeTagsEbsAttached
=== CONT  TestAccAWSInstance_volumeTags
=== CONT  TestAccAWSInstance_volumeTagsComputed
=== CONT  TestAccAWSInstance_rootVolumeTagsEbsAttached
=== CONT  TestAccAWSInstance_rootVolumeTags
--- PASS: TestAccAWSInstance_volumeTagsComputed (173.91s)
--- PASS: TestAccAWSInstance_rootVolumeTagsEbsAttached (219.93s)
--- PASS: TestAccAWSInstance_rootVolumeTags (279.90s)
--- PASS: TestAccAWSInstance_volumeTags (289.16s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	291.061s

@klebediev klebediev requested a review from a team October 4, 2020 08:31
@ghost ghost added size/L Managed by automation to categorize the size of a PR. service/ec2 Issues and PRs that pertain to the ec2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. documentation Introduces or discusses updates to documentation. labels Oct 4, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Oct 4, 2020
@klebediev klebediev force-pushed the feature/add-root-volume-tags branch 4 times, most recently from 383aba4 to 069f1e1 Compare October 4, 2020 10:04
@YakDriver YakDriver self-assigned this Oct 7, 2020
@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 Oct 7, 2020
@YakDriver
Copy link
Member

YakDriver commented Oct 7, 2020

@klebediev I apologize if I was unclear. Please review #12225 (comment).

Rather than root_volume_tags, the ebs_block_device and root_block_device blocks should have tags. The schema would look something like this:

			"ebs_block_device": {
				Type:     schema.TypeSet,
				Optional: true,
				Computed: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						// other existing code...

						"snapshot_id": {
							Type:     schema.TypeString,
							Optional: true,
							Computed: true,
							ForceNew: true,
						},

						"tags": tagsSchema(),

						"volume_size": {
							Type:     schema.TypeInt,
							Optional: true,
							Computed: true,
							ForceNew: true,
						},

						// other existing code...
					},
				},
				// other existing code...
			},

			// "ephemeral_block_device"... can these be tagged? may need tags here too

			"root_block_device": {
				Type:     schema.TypeList,
				Optional: true,
				Computed: true,
				MaxItems: 1,
				Elem: &schema.Resource{
					// "You can only modify the volume size, volume type, and Delete on
					// Termination flag on the block device mapping entry for the root
					// device volume." - bit.ly/ec2bdmap
					Schema: map[string]*schema.Schema{
						// other existing code...
						"iops": {
							Type:             schema.TypeInt,
							Optional:         true,
							Computed:         true,
							DiffSuppressFunc: iopsDiffSuppressFunc,
						},

						"tags": tagsSchema(),

						"volume_size": {
							Type:     schema.TypeInt,
							Optional: true,
							Computed: true,
						},
						// other existing code...
					},
				},
			},

Hopefully, this example makes it more clear! Let me know if you have questions.

Copy link
Member

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

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

Instead of root_volume_tags, please add tags within the ebs_block_device and root_block_device blocks.

@YakDriver YakDriver added the waiting-response Maintainers are waiting on response from community or contributor. label Oct 7, 2020
@klebediev
Copy link
Contributor Author

ohh.. my fault, you were clear, but for some reason I was reading wrong comment (right above that you referred to)
okay, I'll be able to start working on this in several days

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Oct 7, 2020
@YakDriver
Copy link
Member

@klebediev Thanks for your work on this! We look forward to your update. If anything changes on your end with your schedule, let us know!

@YakDriver YakDriver added the waiting-response Maintainers are waiting on response from community or contributor. label Oct 7, 2020
@klebediev klebediev force-pushed the feature/add-root-volume-tags branch 2 times, most recently from 73bc62e to 224bf72 Compare October 13, 2020 14:07
@klebediev klebediev marked this pull request as draft October 13, 2020 14:50
@klebediev klebediev force-pushed the feature/add-root-volume-tags branch 2 times, most recently from 649938c to f0cc4ab Compare October 17, 2020 21:42
@klebediev
Copy link
Contributor Author

$ TF_ACC=1 go test ./aws -v -count 1 -parallel 8 -run="TestAccAWSInstance_.*olumeTags" -timeout 120m
=== RUN   TestAccAWSInstance_volumeTags
=== PAUSE TestAccAWSInstance_volumeTags
=== RUN   TestAccAWSInstance_volumeTagsWithAttachedVolume
=== PAUSE TestAccAWSInstance_volumeTagsWithAttachedVolume
=== RUN   TestAccAWSInstance_blockDeviceVolumeTags
=== PAUSE TestAccAWSInstance_blockDeviceVolumeTags
=== CONT  TestAccAWSInstance_volumeTags
=== CONT  TestAccAWSInstance_blockDeviceVolumeTags
=== CONT  TestAccAWSInstance_volumeTagsWithAttachedVolume
--- PASS: TestAccAWSInstance_volumeTagsWithAttachedVolume (195.39s)
--- PASS: TestAccAWSInstance_blockDeviceVolumeTags (219.62s)
--- PASS: TestAccAWSInstance_volumeTags (296.43s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	299.135s

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Oct 18, 2020
@klebediev
Copy link
Contributor Author

Can't say I like how it's implemented (it's a bit tricky to deal with 2 or more parameters controlling the same functionality), but at least it works in all cases except importing when volume_tags set: in this case terraform apply is required after terraform import.
So far it's the best behavior I was able to achieve.
Kind of micro-breaking change I had to introduce: volume_tags switched to Computed: false

@YakDriver might you take a quick look at this and advise if this could be implemented better

Copy link
Member

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

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

--- PASS: TestAccAWSInstance_addSecondaryInterface (181.43s)
--- PASS: TestAccAWSInstance_addSecurityGroupNetworkInterface (190.56s)
--- PASS: TestAccAWSInstance_associatePublic_defaultPrivate (89.09s)
--- PASS: TestAccAWSInstance_associatePublic_defaultPublic (224.23s)
--- PASS: TestAccAWSInstance_associatePublic_explicitPrivate (100.27s)
--- PASS: TestAccAWSInstance_associatePublic_explicitPublic (214.61s)
--- PASS: TestAccAWSInstance_associatePublic_overridePrivate (99.56s)
--- PASS: TestAccAWSInstance_associatePublic_overridePublic (109.78s)
--- PASS: TestAccAWSInstance_associatePublicIPAndPrivateIP (114.88s)
--- PASS: TestAccAWSInstance_atLeastOneOtherEbsVolume (164.65s)
--- PASS: TestAccAWSInstance_basic (91.43s)
--- PASS: TestAccAWSInstance_blockDevices (93.37s)
--- PASS: TestAccAWSInstance_blockDeviceTags_ebsAndRoot (127.19s)
--- PASS: TestAccAWSInstance_blockDeviceTags_volumeTags (179.42s)
--- PASS: TestAccAWSInstance_blockDeviceTags_withAttachedVolume (173.43s)
--- PASS: TestAccAWSInstance_changeInstanceType (170.63s)
--- PASS: TestAccAWSInstance_CreditSpecification_Empty_NonBurstable (315.86s)
--- PASS: TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable (114.38s)
--- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits (144.36s)
--- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint (454.12s)
--- PASS: TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2 (110.36s)
--- PASS: TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3 (338.63s)
--- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits (138.75s)
--- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint (225.89s)
--- PASS: TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard (122.18s)
--- PASS: TestAccAWSInstance_CreditSpecification_UnspecifiedToEmpty_NonBurstable (136.87s)
--- PASS: TestAccAWSInstance_creditSpecification_updateCpuCredits (176.97s)
--- PASS: TestAccAWSInstance_creditSpecificationT3_standardCpuCredits (122.82s)
--- PASS: TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits (144.93s)
--- PASS: TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited (324.56s)
--- PASS: TestAccAWSInstance_creditSpecificationT3_updateCpuCredits (136.49s)
--- PASS: TestAccAWSInstance_dedicatedInstance (111.88s)
--- PASS: TestAccAWSInstance_disableApiTermination (147.33s)
--- PASS: TestAccAWSInstance_disappears (68.70s)
--- PASS: TestAccAWSInstance_EbsBlockDevice_InvalidIopsForVolumeType (8.29s)
--- PASS: TestAccAWSInstance_EbsBlockDevice_InvalidThroughputForVolumeType (7.43s)
--- PASS: TestAccAWSInstance_EbsBlockDevice_KmsKeyArn (109.12s)
--- PASS: TestAccAWSInstance_EbsRootDevice_basic (138.20s)
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyAll (143.95s)
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyDeleteOnTermination (120.57s)
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io1 (172.28s)
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyIOPS_Io2 (130.38s)
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifySize (132.30s)
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyThroughput_Gp3 (152.25s)
--- PASS: TestAccAWSInstance_EbsRootDevice_ModifyType (141.72s)
--- PASS: TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifyDeleteOnTermination (108.78s)
--- PASS: TestAccAWSInstance_EbsRootDevice_MultipleBlockDevices_ModifySize (172.46s)
--- PASS: TestAccAWSInstance_EbsRootDevice_MultipleDynamicEBSBlockDevices (213.17s)
--- PASS: TestAccAWSInstance_Empty_PrivateIP (104.27s)
--- PASS: TestAccAWSInstance_enclaveOptions (216.43s)
--- PASS: TestAccAWSInstance_forceNewAndTagsDrift (162.62s)
--- PASS: TestAccAWSInstance_getPasswordData_falseToTrue (153.69s)
--- PASS: TestAccAWSInstance_getPasswordData_trueToFalse (186.56s)
--- PASS: TestAccAWSInstance_GP2IopsDevice (156.85s)
--- PASS: TestAccAWSInstance_GP2WithIopsValue (7.61s)
--- PASS: TestAccAWSInstance_hibernation (199.64s)
--- PASS: TestAccAWSInstance_inDefaultVpcBySgId (92.83s)
--- PASS: TestAccAWSInstance_inDefaultVpcBySgName (103.11s)
--- PASS: TestAccAWSInstance_inEc2Classic (78.07s)
--- PASS: TestAccAWSInstance_instanceProfileChange (223.90s)
--- PASS: TestAccAWSInstance_ipv6_supportAddressCount (99.40s)
--- PASS: TestAccAWSInstance_ipv6_supportAddressCountWithIpv4 (100.63s)
--- PASS: TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError (15.70s)
--- PASS: TestAccAWSInstance_keyPairCheck (101.77s)
--- PASS: TestAccAWSInstance_metadataOptions (178.23s)
--- PASS: TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups (142.18s)
--- PASS: TestAccAWSInstance_NetworkInstanceSecurityGroups (119.27s)
--- PASS: TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs (119.96s)
--- PASS: TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPs (100.96s)
--- PASS: TestAccAWSInstance_NewNetworkInterface_EmptyPrivateIPAndSecondaryPrivateIPsUpdate (165.49s)
--- PASS: TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPs (319.49s)
--- PASS: TestAccAWSInstance_NewNetworkInterface_PrivateIPAndSecondaryPrivateIPsUpdate (166.89s)
--- PASS: TestAccAWSInstance_NewNetworkInterface_PublicIPAndSecondaryPrivateIPs (423.94s)
--- PASS: TestAccAWSInstance_noAMIEphemeralDevices (62.00s)
--- PASS: TestAccAWSInstance_placementGroup (323.68s)
--- PASS: TestAccAWSInstance_primaryNetworkInterface (154.91s)
--- PASS: TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck (156.34s)
--- PASS: TestAccAWSInstance_privateIP (209.27s)
--- PASS: TestAccAWSInstance_RootBlockDevice_KmsKeyArn (82.50s)
--- PASS: TestAccAWSInstance_rootBlockDeviceMismatch (83.04s)
--- PASS: TestAccAWSInstance_rootInstanceStore (100.11s)
--- PASS: TestAccAWSInstance_sourceDestCheck (169.24s)
--- PASS: TestAccAWSInstance_tags (111.91s)
--- PASS: TestAccAWSInstance_UserData_EmptyStringToUnspecified (130.54s)
--- PASS: TestAccAWSInstance_UserData_UnspecifiedToEmptyString (133.43s)
--- PASS: TestAccAWSInstance_userDataBase64 (113.53s)
--- PASS: TestAccAWSInstance_withIamInstanceProfile (114.62s)
--- SKIP: TestAccAWSInstance_outpost (1.13s)

@YakDriver YakDriver merged commit cbbada6 into hashicorp:master Jan 13, 2021
@github-actions github-actions bot added this to the v3.24.0 milestone Jan 13, 2021
@klebediev
Copy link
Contributor Author

@YakDriver thank you very much for all the work you've done!

@YakDriver
Copy link
Member

@klebediev Thank you for your work on this!! 🎉 There were no real changes with the functionality of your fixes - some minor variable name tweaks and test tweaks. I did some gardening with all the attributes/arguments but that was really secondary. Also, I saw what you were discussing with EBS volumes since the instance really isn't handling those. At some point, I think we should either add support to manage EBS volumes properly from aws_instance or deprecate it and point people to aws_ebs_volume.

@ghost
Copy link

ghost commented Jan 15, 2021

This has been released in version 3.24.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!

@tdmalone
Copy link
Contributor

Causes: #17125

@yermulnik
Copy link

yermulnik commented Jan 15, 2021

Did this PR cause the removal of volume_tags block from aws_instance for me with the latest AWS provider version or did I hit something else?

  # module.mssql-2.aws_instance.mssql-ec2 will be updated in-place
  ~ resource "aws_instance" "mssql-ec2" {
[…]
      ~ volume_tags                  = {
          - "Application"          = "MSSQL" -> null
[…]
        }
        ebs_block_device {
            delete_on_termination = false
[…]
            tags                  = {}
[…]
        }
[…]
        root_block_device {
[…]
            tags                  = {}
[…]
        }
[…]
}

If it was indeed this PR what caused the change why wouldn't it worth to communicate this via CHANGELOG entry?

UPD: the aws_instance resource in my TF code has no volume_tags attribute set but only tags though this PR replaced "volume_tags": tagsSchemaComputed(), with "volume_tags": tagsSchema(), which means that previously the contents of this attribute might have been supplied by the provider (if by any case this can be a cause of the change I faced):

[…] If Optional is true and Computed is true, the user can specify a value for this field, but the provider may supply a value if the user does not. […]

dekimsey added a commit to dekimsey/terraform-aws-ec2-instance that referenced this pull request Jan 15, 2021
This effectively removes the churn-ing that is happening when an
ebs_volume is attached separately from the module

Takes advantage of the new feature in the aws provider available as of 3.24.0.
hashicorp/terraform-provider-aws#15474
@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.