Skip to content

feat: Add placement group_id support to EC2 launch templates#44097

Merged
ewbankkit merged 4 commits into
hashicorp:mainfrom
aljazmbts:f-ec2_launch_template-placement_group_id
Sep 2, 2025
Merged

feat: Add placement group_id support to EC2 launch templates#44097
ewbankkit merged 4 commits into
hashicorp:mainfrom
aljazmbts:f-ec2_launch_template-placement_group_id

Conversation

@aljazmbts
Copy link
Copy Markdown
Contributor

@aljazmbts aljazmbts commented Aug 30, 2025

Description

Add support for specifying placement groups by ID in EC2 launch templates, providing an alternative to the existing group_name parameter.

Changes:

  • Add group_id field to launch template placement configuration
  • Implement proper conflict validation between group_name and group_id
  • Include acceptance test coverage:
    • Test basic group_id functionality
    • Test migration from group_name to group_id
    • Test data source support for group_id
  • Add documentation for new group_id parameter with conflict notes
  • Update changelog with enhancement details

This enables users to reference placement groups by their unique ID rather than name, providing more robust infrastructure as code practices and supporting programmatic placement group management. This is required for placement groups that are shared through Resource Access Manager (RAM).

The implementation maintains full backward compatibility with existing group_name configurations while adding the new group_id option with proper validation to prevent conflicting specifications.

Rollback Plan

This change adds a new optional parameter (group_id) with proper conflict validation. If rollback is needed:

  1. No data loss risk: Existing configurations using group_name continue to work unchanged
  2. Safe removal: The group_id field can be removed in a future version without breaking existing infrastructure
  3. Migration path: Users can revert from group_id back to group_name by updating their configuration
  4. Version-specific rollback: Downgrade to the previous provider version if immediate rollback is required

No state migration or data conversion is needed for rollback as this is an additive change.

Changes to Security Controls

No changes to security controls. This change only adds a new optional parameter for specifying placement groups by ID rather than name.

Relations

Closes #38908.

Output from Acceptance Testing

% make testacc TESTS=TestAccEC2LaunchTemplate_placement_groupID PKG=ec2                    
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.24.6 test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2LaunchTemplate_placement_groupID'  -timeout 360m -vet=off
2025/08/30 12:13:05 Creating Terraform AWS Provider (SDKv2-style)...
2025/08/30 12:13:05 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccEC2LaunchTemplate_placement_groupID
=== PAUSE TestAccEC2LaunchTemplate_placement_groupID
=== CONT  TestAccEC2LaunchTemplate_placement_groupID
--- PASS: TestAccEC2LaunchTemplate_placement_groupID (39.28s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	45.907s

% make testacc TESTS=TestAccEC2LaunchTemplate_placement_groupNameToGroupID PKG=ec2
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.24.6 test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2LaunchTemplate_placement_groupNameToGroupID'  -timeout 360m -vet=off
2025/08/30 12:14:46 Creating Terraform AWS Provider (SDKv2-style)...
2025/08/30 12:14:46 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccEC2LaunchTemplate_placement_groupNameToGroupID
=== PAUSE TestAccEC2LaunchTemplate_placement_groupNameToGroupID
=== CONT  TestAccEC2LaunchTemplate_placement_groupNameToGroupID
--- PASS: TestAccEC2LaunchTemplate_placement_groupNameToGroupID (59.10s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	65.307s

% make testacc TESTS=TestAccEC2LaunchTemplateDataSource_placementGroupID PKG=ec2
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.24.6 test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2LaunchTemplateDataSource_placementGroupID'  -timeout 360m -vet=off
2025/08/30 12:17:32 Creating Terraform AWS Provider (SDKv2-style)...
2025/08/30 12:17:32 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccEC2LaunchTemplateDataSource_placementGroupID
=== PAUSE TestAccEC2LaunchTemplateDataSource_placementGroupID
=== CONT  TestAccEC2LaunchTemplateDataSource_placementGroupID
--- PASS: TestAccEC2LaunchTemplateDataSource_placementGroupID (34.81s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	41.780s

@aljazmbts aljazmbts requested a review from a team as a code owner August 30, 2025 10:36
@github-actions
Copy link
Copy Markdown
Contributor

Community Guidelines

This comment is added to every new Pull Request to provide quick reference to how the Terraform AWS Provider is maintained. Please review the information below, and thank you for contributing to the community that keeps the provider thriving! 🚀

Voting for Prioritization

  • Please vote on this Pull Request by adding a 👍 reaction to the original post to help the community and maintainers prioritize it.
  • Please see our prioritization guide for additional information on how the maintainers handle prioritization.
  • Please do not leave +1 or other comments that do not add relevant new information or questions; they generate extra noise for others following the Pull Request and do not help prioritize the request.

Pull Request Authors

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 30, 2025

✅ Thank you for correcting the previously detected issues! The maintainers appreciate your efforts to make the review process as smooth as possible.

@github-actions github-actions Bot added needs-triage Waiting for first response or review from a maintainer. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/ec2 Issues and PRs that pertain to the ec2 service. provider Pertains to the provider itself, rather than any interaction with AWS. size/L Managed by automation to categorize the size of a PR. labels Aug 30, 2025
@aljazmbts aljazmbts force-pushed the f-ec2_launch_template-placement_group_id branch from 4df85d5 to 1a462d4 Compare August 30, 2025 10:39
Add support for specifying placement groups by ID in EC2 launch templates,
providing an alternative to the existing group_name parameter.

Changes:
- Add group_id field to launch template placement configuration
- Implement proper conflict validation between group_name and group_id
- Add expand/flatten functions for group_id API mapping
- Include comprehensive acceptance test coverage:
  * Test basic group_id functionality
  * Test migration from group_name to group_id
  * Test data source support for group_id
- Add documentation for new group_id parameter with conflict notes
- Add proper changelog entry file (.changelog/38908.txt)

This enables users to reference placement groups by their unique ID
rather than name, providing more robust infrastructure as code practices
and supporting programmatic placement group management. This is particularly
useful for placement groups that are shared through Resource Access Manager
(RAM), where cross-account access may provide the group ID but not the name.

The implementation maintains full backward compatibility with existing
group_name configurations while adding the new group_id option with
proper validation to prevent conflicting specifications.
@aljazmbts aljazmbts force-pushed the f-ec2_launch_template-placement_group_id branch from 1a462d4 to 638f3a9 Compare August 30, 2025 10:41
@ewbankkit ewbankkit added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. provider Pertains to the provider itself, rather than any interaction with AWS. labels Sep 2, 2025
@ewbankkit ewbankkit self-assigned this Sep 2, 2025
@github-actions github-actions Bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Sep 2, 2025
Copy link
Copy Markdown
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=TestAccEC2LaunchTemplate_basic\|TestAccEC2LaunchTemplate_Placement_\|TestAccEC2LaunchTemplateDataSource_name' PKG=ec2 ACCTEST_PARALLELISM=3
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.24.6 test ./internal/service/ec2/... -v -count 1 -parallel 3  -run=TestAccEC2LaunchTemplate_basic\|TestAccEC2LaunchTemplate_Placement_\|TestAccEC2LaunchTemplateDataSource_name -timeout 360m -vet=off
2025/09/02 11:43:13 Creating Terraform AWS Provider (SDKv2-style)...
2025/09/02 11:43:13 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccEC2LaunchTemplateDataSource_name
=== PAUSE TestAccEC2LaunchTemplateDataSource_name
=== RUN   TestAccEC2LaunchTemplate_basic
=== PAUSE TestAccEC2LaunchTemplate_basic
=== RUN   TestAccEC2LaunchTemplate_Placement_groupID
=== PAUSE TestAccEC2LaunchTemplate_Placement_groupID
=== RUN   TestAccEC2LaunchTemplate_Placement_groupNameToGroupID
=== PAUSE TestAccEC2LaunchTemplate_Placement_groupNameToGroupID
=== RUN   TestAccEC2LaunchTemplate_Placement_hostResourceGroupARN
=== PAUSE TestAccEC2LaunchTemplate_Placement_hostResourceGroupARN
=== RUN   TestAccEC2LaunchTemplate_Placement_partitionNum
=== PAUSE TestAccEC2LaunchTemplate_Placement_partitionNum
=== CONT  TestAccEC2LaunchTemplateDataSource_name
=== CONT  TestAccEC2LaunchTemplate_Placement_partitionNum
=== CONT  TestAccEC2LaunchTemplate_Placement_groupNameToGroupID
--- PASS: TestAccEC2LaunchTemplate_Placement_partitionNum (35.57s)
=== CONT  TestAccEC2LaunchTemplate_Placement_hostResourceGroupARN
--- PASS: TestAccEC2LaunchTemplate_Placement_groupNameToGroupID (35.64s)
=== CONT  TestAccEC2LaunchTemplate_Placement_groupID
--- PASS: TestAccEC2LaunchTemplate_Placement_groupID (20.29s)
=== CONT  TestAccEC2LaunchTemplate_basic
--- PASS: TestAccEC2LaunchTemplate_Placement_hostResourceGroupARN (21.74s)
--- PASS: TestAccEC2LaunchTemplateDataSource_name (69.98s)
--- PASS: TestAccEC2LaunchTemplate_basic (19.65s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	81.488s

Copy link
Copy Markdown
Member

@jar-b jar-b left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@ewbankkit
Copy link
Copy Markdown
Contributor

@aljazmbts Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit ed7d892 into hashicorp:main Sep 2, 2025
44 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 2, 2025

Warning

This Issue has been closed, meaning that any additional comments are much easier for the maintainers to miss. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions Bot added this to the v6.12.0 milestone Sep 2, 2025
@github-actions github-actions Bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Sep 4, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 4, 2025

This functionality has been released in v6.12.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
Copy Markdown
Contributor

github-actions Bot commented Oct 5, 2025

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 5, 2025
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. enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service. size/L 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.

[Enhancement]: EC2 placement groups can now be shared across multiple AWS accounts

3 participants