hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.87k stars 9.21k forks source link

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

Open gaplo917 opened 3 months ago

gaplo917 commented 3 months ago

Description

On Nov 8, 2022, You can now share Amazon EC2 placement groups across multiple AWS accounts using AWS Resource Access Manager (RAM). When a placement group is shared, instances launched by one AWS account can utilize a placement group created by another account.

The current terraform implementation of aws_instance.placement_group doesn't support this feature.

Affected Resource(s) and/or Data Source(s)

Potential Terraform Configuration

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

  tags = {
    Name = "HelloWorld"
  }
}

References

To launch EC2 instance with shared cluster placement group

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/share-placement-group.html

aws ec2 run-instances --placement "GroupId = pg-xxxxxxxxxxxx"

The existing terraform implementation assign placement_group to Placement.GroupName while a shared placement group has to assign to GroupId.

https://github.com/hashicorp/terraform-provider-aws/blob/a0609b9810341fe94a3dd0b5f14aed30973ba06c/internal/service/ec2/ec2_instance.go#L2988-L2989

Potential Fix

Introduce placement_group_id that support both non-shared or shared cases and make it conflict to placement_group

Errors Log

case 1: using placement_group="shared-placement-group-name"

An error occurred (InvalidPlacementGroup.Unknown) when calling the RunInstances operation: 

The placement group 'shared_cluster-placement-group' is unknown.

case 2: using placement_group="pg-xxxxxxxxxxxx"

Error: creating EC2 Instance: operation error EC2: RunInstances, https response error StatusCode: 400, RequestID: xxxxx-xxxx-xxxx-xxxx, api error InvalidPlacementGroup.Unknown: 

The placement group 'pg-xxxxxxxxxxxx' is unknown.

case 3. using placement_group="GroupId=pg-xxxxxxxxxxxx"

Error: creating EC2 Instance: operation error EC2: RunInstances, https response error StatusCode: 400, RequestID: xxxxx-xxxx-xxxx-xxxx, api error InvalidPlacementGroup.Unknown: 

The placement group 'GroupId=pg-xxxxxxxxxxx' is unknown

Relevant PR

38527

Would you like to implement a fix?

No

github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue