-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Conversation
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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! |
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. |
Community Note
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 whetherplacement_group
was configured.ec2.RunInstanceInput.Placement.GroupName
cannot be set if launching in a (dedicated) host resource group. Even though thehost_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
andhost_resource_group_arn
cannot both be set andec2.RunInstanceInput.Placement.GroupName
is not defined ifplacement_group
is not configured.Output from acceptance testing: