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.73k stars 9.09k forks source link

[Bug]: Skip destroying AWS Cloud9 Environment Membership #29299

Open obouchta opened 1 year ago

obouchta commented 1 year ago

Terraform Core Version

1.3.7

AWS Provider Version

4.53.0

Affected Resource(s)

aws_cloud9_environment_membership

Expected Behavior

The resource "aws_cloud9_environment_membership" cannot be destroyed by an administrator. It has to be destroyed by an owner. It would be nice to have a skip_destroy parameter to skip destroying the resource.

Actual Behavior

Terraform try to remove the resource and AWS return an error "Forbidden Exception".

Relevant Error/Panic Output Snippet

│ Error: deleting Cloud9 EC2 Environment (xxxxxxxxxxxxxxxxxxxxxxxx#arn:aws:sts::yyyyyyyyyyyyy:assumed-role/role_name): ForbiddenException: arn:aws:sts::yyyyyyyyyyyyy:assumed-role/gitlab/cicd is not the environment owner so can't delete another member.

Terraform Configuration Files

resource "aws_cloud9_environment_ec2" "this" {
  for_each = var.users
  instance_type = var.instance_type
  name          = "${each.key}-${local.env}-env"
  automatic_stop_time_minutes = 240
  description = "cloud9 environment"
  owner_arn = "arn:aws:sts::${data.aws_caller_identity.current.account_id}:assumed-role/${each.value.role}/${each.key}"
  subnet_id = var.subnet_id
}

resource "aws_cloud9_environment_membership" "this" {
  for_each = var.users

  environment_id = aws_cloud9_environment_ec2.this[each.key].id
  permissions    = "read-write"
  user_arn       = "arn:aws:sts::${data.aws_caller_identity.current.account_id}:assumed-role/${each.value.new_role}/${each.key}"
}

Steps to Reproduce

Please, follow these steps to reproduce the issue:

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue