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.83k stars 9.17k forks source link

resource/aws_batch_compute_environment: IAM propagation error when waiting for deployment #37945

Open gdavison opened 4 months ago

gdavison commented 4 months ago

Terraform Core Version

N/A

AWS Provider Version

5.53.0

Affected Resource(s)

aws_batch_compute_environment

Expected Behavior

When a new IAM role is used with a new Batch Compute Environment, it should succeed

Actual Behavior

When a new IAM role is used with a new Batch Compute Environment, there is sometimes a race condition with IAM propagation, which returns the error

Error: waiting for Batch Compute Environment (tf-acc-test-3086423369041877539) create: unexpected state 'INVALID', wanted target 'VALID'. last error: CLIENT_ERROR - User: arn:aws:sts::123456789012:assumed-role/tf-acc-test-3086423369041877539-batch-service/aws-batch is not authorized to perform: ecs:DescribeClusters on resource: arn:aws:ecs:us-west-2: 123456789012:cluster/tf-acc-test-3086423369041877539_Batch_85c0db2f-9cd0-3d7b-805d-ec3a8681fd19 because no identity-based policy allows the ecs:DescribeClusters action

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

Any Compute Environment acceptance test

Steps to Reproduce

Run any Compute Environment acceptance test

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 4 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

fwereade commented 3 months ago

In the past I've addressed this by adding explicit dependencies to the aws_batch_compute_environment, e.g.

  depends_on = [
    aws_iam_role_policy_attachment.batch_service_role,
    aws_iam_role_policy_attachment.batch_service_ecs_policy,
  ]

…but recently I've been seeing this same failure intermittently even with those in place.