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

ec2/instance: Dedicated host resource group compatibility #26532

Merged
merged 9 commits into from
Aug 30, 2022

Conversation

YakDriver
Copy link
Member

@YakDriver YakDriver commented Aug 29, 2022

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 #16995.
Closes #17282.
Supersedes #17282.

NOTE: We cannot easily test this solution. We have determined that it does not seem to cause any regressions and should work. However, this is best-effort functionality. We would love to hear from you if you use this functionality and it does or doesn't work.

The crux of the problem noted by op in #16995 resulted from ec2.RunInstanceInput.Placement.GroupName always being set in API calls, even if to an empty string, if instance interruption behavior was not set or set to terminate, regardless whether placement_group was configured. ec2.RunInstanceInput.Placement.GroupName cannot be set if launching in a (dedicated) host resource group. Even though the host_resource_group_arn argument is added in this PR, the association could previously be done implicitly based on the AMI ID and the host resource group being set to "Allocate hosts automatically."

Now, placement_group and host_resource_group_arn cannot both be set and ec2.RunInstanceInput.Placement.GroupName is not defined if placement_group is not configured.

Output from acceptance testing:

% make testacc TESTS=TestAccEC2Instance_ PKG=ec2       
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2Instance_'  -timeout 180m
--- PASS: TestAccEC2Instance_CreditSpecificationEmpty_nonBurstable (139.08s)
--- PASS: TestAccEC2Instance_LaunchTemplate_overrideTemplate (142.13s)
--- PASS: TestAccEC2Instance_LaunchTemplate_spotAndStop (145.67s)
--- PASS: TestAccEC2Instance_basic (159.10s)
--- PASS: TestAccEC2Instance_CreditSpecification_unspecifiedDefaultsToStandard (185.58s)
--- PASS: TestAccEC2Instance_IPv6_supportAddressCountWithIPv4 (187.68s)
--- PASS: TestAccEC2Instance_LaunchTemplate_setSpecificVersion (204.65s)
--- PASS: TestAccEC2Instance_LaunchTemplateModifyTemplate_defaultVersion (207.14s)
--- PASS: TestAccEC2Instance_CreditSpecificationUnspecifiedToEmpty_nonBurstable (208.01s)
--- PASS: TestAccEC2Instance_LaunchTemplate_swapIDAndName (208.39s)
--- PASS: TestAccEC2Instance_CreditSpecification_standardCPUCredits (208.55s)
--- PASS: TestAccEC2Instance_EBSRootDeviceMultipleBlockDevices_modifyDeleteOnTermination (211.56s)
--- PASS: TestAccEC2Instance_CreditSpecification_unlimitedCPUCredits (215.94s)
--- PASS: TestAccEC2Instance_GetPasswordData_falseToTrue (220.58s)
--- PASS: TestAccEC2Instance_LaunchTemplate_updateTemplateVersion (232.31s)
--- PASS: TestAccEC2Instance_CapacityReservation_modifyTarget (243.06s)
--- PASS: TestAccEC2Instance_GetPasswordData_trueToFalse (245.37s)
--- PASS: TestAccEC2Instance_CapacityReservation_modifyPreference (261.30s)
--- PASS: TestAccEC2Instance_LaunchTemplate_basic (119.98s)
--- PASS: TestAccEC2Instance_EBSRootDevice_multipleDynamicEBSBlockDevices (262.24s)
--- PASS: TestAccEC2Instance_CapacityReservation_targetID (130.49s)
--- PASS: TestAccEC2Instance_AssociatePublic_overridePrivate (152.86s)
--- PASS: TestAccEC2Instance_AssociatePublic_overridePublic (140.12s)
--- PASS: TestAccEC2Instance_rootBlockDeviceMismatch (300.90s)
--- PASS: TestAccEC2Instance_CapacityReservationPreference_open (117.93s)
--- PASS: TestAccEC2Instance_CapacityReservationPreference_none (129.95s)
--- PASS: TestAccEC2Instance_AssociatePublic_explicitPrivate (152.35s)
--- PASS: TestAccEC2Instance_AssociatePublic_explicitPublic (154.13s)
--- PASS: TestAccEC2Instance_AssociatePublic_defaultPublic (152.96s)
--- PASS: TestAccEC2Instance_metadataOptions (158.64s)
--- PASS: TestAccEC2Instance_CapacityReservation_unspecifiedDefaultsToOpen (171.00s)
--- PASS: TestAccEC2Instance_UserData_emptyStringToUnspecified (174.76s)
--- PASS: TestAccEC2Instance_UserData_unspecifiedToEmptyString (184.94s)
--- PASS: TestAccEC2Instance_AssociatePublic_defaultPrivate (147.55s)
--- PASS: TestAccEC2Instance_UserDataReplaceOnChange_Off_Base64 (229.64s)
--- PASS: TestAccEC2Instance_hibernation (243.53s)
--- PASS: TestAccEC2Instance_enclaveOptions (263.34s)
--- PASS: TestAccEC2Instance_UserDataReplaceOnChange_Off (248.29s)
--- PASS: TestAccEC2Instance_UserData (144.27s)
--- PASS: TestAccEC2Instance_EBSRootDeviceMultipleBlockDevices_modifySize (186.45s)
--- PASS: TestAccEC2Instance_NewNetworkInterface_privateIPAndSecondaryPrivateIPs (164.06s)
--- PASS: TestAccEC2Instance_UserDataReplaceOnChange_On (255.71s)
--- PASS: TestAccEC2Instance_EBSRootDevice_modifyDeleteOnTermination (151.18s)
--- PASS: TestAccEC2Instance_NewNetworkInterface_privateIPAndSecondaryPrivateIPsUpdate (208.73s)
--- PASS: TestAccEC2Instance_UserDataReplaceOnChange_On_Base64 (281.33s)
--- PASS: TestAccEC2Instance_UserData_stringToEncodedString (263.27s)
--- PASS: TestAccEC2Instance_EBSRootDevice_modifyAll (192.82s)
--- PASS: TestAccEC2Instance_UserData_update (266.26s)
--- PASS: TestAccEC2Instance_NewNetworkInterface_emptyPrivateIPAndSecondaryPrivateIPs (117.67s)
--- PASS: TestAccEC2Instance_EBSRootDeviceModifyThroughput_gp3 (199.86s)
--- PASS: TestAccEC2Instance_NewNetworkInterface_emptyPrivateIPAndSecondaryPrivateIPsUpdate (247.79s)
--- PASS: TestAccEC2Instance_EBSRootDeviceModifyIOPS_io2 (211.15s)
--- PASS: TestAccEC2Instance_CreditSpecificationT3_unlimitedCPUCredits (143.32s)
--- PASS: TestAccEC2Instance_EBSRootDeviceModifyIOPS_io1 (179.42s)
--- PASS: TestAccEC2Instance_EBSRootDevice_basic (135.81s)
--- PASS: TestAccEC2Instance_EBSRootDevice_modifyType (185.69s)
--- PASS: TestAccEC2Instance_CreditSpecificationT3_standardCPUCredits (162.42s)
--- PASS: TestAccEC2Instance_EBSRootDevice_modifySize (179.11s)
--- PASS: TestAccEC2Instance_CreditSpecification_isNotAppliedToNonBurstable (131.22s)
--- PASS: TestAccEC2Instance_CreditSpecificationUnknownCPUCredits_t4g (114.56s)
--- PASS: TestAccEC2Instance_CreditSpecificationT3_unspecifiedDefaultsToUnlimited (143.96s)
--- PASS: TestAccEC2Instance_CreditSpecificationUnknownCPUCredits_t3a (109.24s)
--- PASS: TestAccEC2Instance_CreditSpecificationT3_updateCPUCredits (237.73s)
--- PASS: TestAccEC2Instance_CreditSpecificationStandardCPUCredits_t2Tot3Taint (274.19s)
--- PASS: TestAccEC2Instance_primaryNetworkInterfaceSourceDestCheck (152.39s)
--- PASS: TestAccEC2Instance_CreditSpecificationUnlimitedCPUCredits_t2Tot3Taint (280.01s)
--- PASS: TestAccEC2Instance_networkCardIndex (139.69s)
--- PASS: TestAccEC2Instance_NewNetworkInterface_publicIPAndSecondaryPrivateIPs (245.41s)
--- PASS: TestAccEC2Instance_gp3RootBlockDevice (99.12s)
--- PASS: TestAccEC2Instance_primaryNetworkInterface (120.64s)
--- PASS: TestAccEC2Instance_CreditSpecificationUnknownCPUCredits_t3 (135.79s)
--- PASS: TestAccEC2Instance_CreditSpecification_updateCPUCredits (236.15s)
--- PASS: TestAccEC2Instance_keyPairCheck (119.31s)
--- PASS: TestAccEC2Instance_CreditSpecificationUnknownCPUCredits_t2 (146.83s)
--- PASS: TestAccEC2Instance_gp2WithIopsValue (16.46s)
--- PASS: TestAccEC2Instance_withIAMInstanceProfile (158.74s)
--- PASS: TestAccEC2Instance_Empty_privateIP (140.00s)
--- PASS: TestAccEC2Instance_changeInstanceTypeAndUserDataBase64 (337.74s)
--- PASS: TestAccEC2Instance_associatePublicIPAndPrivateIP (142.79s)
--- PASS: TestAccEC2Instance_ipv6AddressCountAndSingleAddressCausesError (2.02s)
--- PASS: TestAccEC2Instance_PrivateDNSNameOptions_configured (179.74s)
    acctest.go:1346: skipping since no Outposts found
--- SKIP: TestAccEC2Instance_outpost (0.61s)
--- PASS: TestAccEC2Instance_changeInstanceType (225.93s)
--- PASS: TestAccEC2Instance_withIAMInstanceProfilePath (141.13s)
--- PASS: TestAccEC2Instance_privateIP (154.13s)
--- PASS: TestAccEC2Instance_forceNewAndTagsDrift (239.09s)
--- PASS: TestAccEC2Instance_networkInstanceVPCSecurityGroupIDs (142.62s)
--- PASS: TestAccEC2Instance_disableAPITerminationFinalTrue (129.54s)
--- PASS: TestAccEC2Instance_PrivateDNSNameOptions_computed (203.84s)
--- PASS: TestAccEC2Instance_EBSBlockDevice_invalidThroughputForVolumeType (19.20s)
--- PASS: TestAccEC2Instance_BlockDeviceTags_ebsAndRoot (194.12s)
--- PASS: TestAccEC2Instance_changeInstanceTypeAndUserData (280.37s)
--- PASS: TestAccEC2Instance_EBSBlockDevice_invalidIopsForVolumeType (20.51s)
--- PASS: TestAccEC2Instance_addSecurityGroupNetworkInterface (453.36s)
--- PASS: TestAccEC2Instance_networkInstanceSecurityGroups (152.43s)
--- PASS: TestAccEC2Instance_addSecondaryInterface (451.97s)
--- PASS: TestAccEC2Instance_placementGroup (100.75s)
--- PASS: TestAccEC2Instance_BlockDeviceTags_volumeTags (237.89s)
--- PASS: TestAccEC2Instance_disableAPITerminationFinalFalse (186.81s)
--- PASS: TestAccEC2Instance_BlockDeviceTags_withAttachedVolume (263.99s)
--- PASS: TestAccEC2Instance_dedicatedInstance (122.64s)
--- PASS: TestAccEC2Instance_placementPartitionNumber (119.30s)
--- PASS: TestAccEC2Instance_blockDevices (109.04s)
--- PASS: TestAccEC2Instance_rootInstanceStore (120.09s)
--- PASS: TestAccEC2Instance_autoRecovery (177.58s)
--- PASS: TestAccEC2Instance_noAMIEphemeralDevices (133.10s)
--- PASS: TestAccEC2Instance_instanceProfileChange (318.10s)
--- PASS: TestAccEC2Instance_EBSBlockDevice_kmsKeyARN (118.28s)
--- PASS: TestAccEC2Instance_IPv6_supportAddressCount (156.39s)
--- PASS: TestAccEC2Instance_disableAPIStop (197.36s)
--- PASS: TestAccEC2Instance_gp2IopsDevice (103.28s)
--- PASS: TestAccEC2Instance_inDefaultVPCBySgID (144.32s)
--- PASS: TestAccEC2Instance_userDataBase64 (132.47s)
--- PASS: TestAccEC2Instance_sourceDestCheck (225.37s)
--- PASS: TestAccEC2Instance_RootBlockDevice_kmsKeyARN (128.45s)
--- PASS: TestAccEC2Instance_inDefaultVPCBySgName (135.37s)
--- PASS: TestAccEC2Instance_tags (197.66s)
--- PASS: TestAccEC2Instance_atLeastOneOtherEBSVolume (229.72s)
--- PASS: TestAccEC2Instance_networkInstanceRemovingAllSecurityGroups (155.67s)
--- PASS: TestAccEC2Instance_userDataBase64_updateWithBashFile (239.47s)
--- PASS: TestAccEC2Instance_userDataBase64_updateWithZipFile (221.96s)
--- PASS: TestAccEC2Instance_userDataBase64_update (261.46s)
--- PASS: TestAccEC2Instance_EBSBlockDevice_RootBlockDevice_removed (263.74s)
--- PASS: TestAccEC2Instance_disappears (330.55s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	1372.987s
% make testacc TESTS=TestAccEC2InstanceDataSource_ PKG=ec2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2InstanceDataSource_'  -timeout 180m
--- PASS: TestAccEC2InstanceDataSource_enclaveOptions (106.93s)
--- PASS: TestAccEC2InstanceDataSource_placementGroup (108.88s)
--- PASS: TestAccEC2InstanceDataSource_RootBlockDevice_kmsKeyID (112.87s)
--- PASS: TestAccEC2InstanceDataSource_gp3ThroughputDevice (130.04s)
--- PASS: TestAccEC2InstanceDataSource_blockDevices (132.61s)
--- PASS: TestAccEC2InstanceDataSource_blockDeviceTags (134.91s)
--- PASS: TestAccEC2InstanceDataSource_timeout (138.63s)
--- PASS: TestAccEC2InstanceDataSource_basic (145.44s)
--- PASS: TestAccEC2InstanceDataSource_keyPair (148.82s)
--- PASS: TestAccEC2InstanceDataSource_rootInstanceStore (150.13s)
--- PASS: TestAccEC2InstanceDataSource_vpc (155.16s)
--- PASS: TestAccEC2InstanceDataSource_creditSpecification (155.91s)
--- PASS: TestAccEC2InstanceDataSource_secondaryPrivateIPs (156.60s)
--- PASS: TestAccEC2InstanceDataSource_metadataOptions (160.41s)
--- PASS: TestAccEC2InstanceDataSource_EBSBlockDevice_kmsKeyID (161.87s)
--- PASS: TestAccEC2InstanceDataSource_privateIP (165.21s)
--- PASS: TestAccEC2InstanceDataSource_ipv6Addresses (176.36s)
--- PASS: TestAccEC2InstanceDataSource_disableAPIStopTermination (191.34s)
--- PASS: TestAccEC2InstanceDataSource_autoRecovery (205.62s)
--- PASS: TestAccEC2InstanceDataSource_GetPasswordData_falseToTrue (212.72s)
--- PASS: TestAccEC2InstanceDataSource_securityGroups (112.23s)
--- PASS: TestAccEC2InstanceDataSource_gp2IopsDevice (86.87s)
--- PASS: TestAccEC2InstanceDataSource_vpcSecurityGroups (149.33s)
--- PASS: TestAccEC2InstanceDataSource_tags (125.85s)
--- PASS: TestAccEC2InstanceDataSource_azUserData (146.76s)
--- PASS: TestAccEC2InstanceDataSource_GetPasswordData_trueToFalse (199.72s)
--- PASS: TestAccEC2InstanceDataSource_GetUserData_noUserData (194.06s)
--- PASS: TestAccEC2InstanceDataSource_getUserData (204.92s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	338.961s
% make testacc TESTS=TestAccEC2InstancesDataSource_ PKG=ec2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2InstancesDataSource_'  -timeout 180m
--- PASS: TestAccEC2InstancesDataSource_empty (30.27s)
--- PASS: TestAccEC2InstancesDataSource_instanceStateNames (107.62s)
--- PASS: TestAccEC2InstancesDataSource_timeout (118.17s)
--- PASS: TestAccEC2InstancesDataSource_tags (158.67s)
--- PASS: TestAccEC2InstancesDataSource_basic (129.21s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	709.139s

@github-actions github-actions bot added documentation Introduces or discusses updates to documentation. service/ec2 Issues and PRs that pertain to the ec2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/XL Managed by automation to categorize the size of a PR. labels Aug 29, 2022
if v := d.Get("placement_group").(string); instanceInterruptionBehavior == "" || instanceInterruptionBehavior == ec2.InstanceInterruptionBehaviorTerminate {
opts.Placement.GroupName = aws.String(v)
opts.SpotPlacement.GroupName = aws.String(v)
if v, ok := d.GetOk("placement_group"); ok && (instanceInterruptionBehavior == "" || instanceInterruptionBehavior == ec2.InstanceInterruptionBehaviorTerminate) {
Copy link
Member Author

@YakDriver YakDriver Aug 29, 2022

Choose a reason for hiding this comment

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

This logic problem is the crux of the problem noted by op. ec2.RunInstanceInput.Placement.GroupName was being set regardless whether placement_group was configured if instance interruption behavior was not set or set to terminate.

Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

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

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccEC2Instance_basic\|TestAccEC2Instance_dedicatedInstance\|TestAccEC2InstanceDataSource_basic' PKG=ec2 ACCTEST_PARALLELISM=3
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 3  -run=TestAccEC2Instance_basic\|TestAccEC2Instance_dedicatedInstance\|TestAccEC2InstanceDataSource_basic -timeout 180m
=== RUN   TestAccEC2InstanceDataSource_basic
=== PAUSE TestAccEC2InstanceDataSource_basic
=== RUN   TestAccEC2Instance_basic
=== PAUSE TestAccEC2Instance_basic
=== RUN   TestAccEC2Instance_dedicatedInstance
=== PAUSE TestAccEC2Instance_dedicatedInstance
=== CONT  TestAccEC2InstanceDataSource_basic
=== CONT  TestAccEC2Instance_dedicatedInstance
=== CONT  TestAccEC2Instance_basic
--- PASS: TestAccEC2Instance_dedicatedInstance (102.71s)
--- PASS: TestAccEC2InstanceDataSource_basic (105.80s)
--- PASS: TestAccEC2Instance_basic (115.77s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	119.631s

@YakDriver YakDriver merged commit 8cbba50 into main Aug 30, 2022
@YakDriver YakDriver deleted the b-ec2-instance-hostresourcegrouparn branch August 30, 2022 14:50
@github-actions github-actions bot added this to the v4.29.0 milestone Aug 30, 2022
github-actions bot pushed a commit that referenced this pull request Aug 30, 2022
@github-actions
Copy link

github-actions bot commented Sep 2, 2022

This functionality has been released in v4.29.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. Thank you!

@github-actions
Copy link

github-actions bot commented Oct 4, 2022

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. service/ec2 Issues and PRs that pertain to the ec2 service. size/XL 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.

Placement GroupName being specified causing conflict with HostResourceGroupArn
2 participants