Skip to content
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

[Docs]: Race Condition in Example Cloudtrail Creation #27945

Closed
groja opened this issue Nov 22, 2022 · 3 comments · Fixed by #30758
Closed

[Docs]: Race Condition in Example Cloudtrail Creation #27945

groja opened this issue Nov 22, 2022 · 3 comments · Fixed by #30758
Labels
documentation Introduces or discusses updates to documentation. eventual-consistency Pertains to eventual consistency issues. service/cloudtrail Issues and PRs that pertain to the cloudtrail service.
Milestone

Comments

@groja
Copy link

groja commented Nov 22, 2022

Documentation Link

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudtrail

Description

When following the example you can hit a race condition - if terraform tries to create the Cloudtrail resource before the aws_s3_bucket_policy has finished creating, the creation of the cloudtrail resource fails with an "InsufficientS3BucketPolicyException".

In my own use of this, I have added the following to the cloudtrail resource:

depends_on = [
aws_s3_bucket_policy.foo
]

That ensures that it waits till the policy is in place before trying to create it.

That would mean the fix here would be changing the Basic example to the following:


resource "aws_cloudtrail" "foobar" {
  name                          = "tf-trail-foobar"
  s3_bucket_name                = aws_s3_bucket.foo.id
  s3_key_prefix                 = "prefix"
  include_global_service_events = false
  depends_on = [
    aws_s3_bucket_policy.foo
  ]
}

resource "aws_s3_bucket" "foo" {
  bucket        = "tf-test-trail"
  force_destroy = true
}

resource "aws_s3_bucket_policy" "foo" {
  bucket = aws_s3_bucket.foo.id
  policy = <<POLICY
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AWSCloudTrailAclCheck",
            "Effect": "Allow",
            "Principal": {
              "Service": "cloudtrail.amazonaws.com"
            },
            "Action": "s3:GetBucketAcl",
            "Resource": "${aws_s3_bucket.foo.arn}"
        },
        {
            "Sid": "AWSCloudTrailWrite",
            "Effect": "Allow",
            "Principal": {
              "Service": "cloudtrail.amazonaws.com"
            },
            "Action": "s3:PutObject",
            "Resource": "${aws_s3_bucket.foo.arn}/prefix/AWSLogs/${data.aws_caller_identity.current.account_id}/*",
            "Condition": {
                "StringEquals": {
                    "s3:x-amz-acl": "bucket-owner-full-control"
                }
            }
        }
    ]
}
POLICY
}```

### References

_No response_

### Would you like to implement a fix?

_No response_
@groja groja added documentation Introduces or discusses updates to documentation. needs-triage Waiting for first response or review from a maintainer. labels Nov 22, 2022
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/cloudtrail Issues and PRs that pertain to the cloudtrail service. service/s3 Issues and PRs that pertain to the s3 service. service/sts Issues and PRs that pertain to the sts service. labels Nov 22, 2022
@ewbankkit ewbankkit added eventual-consistency Pertains to eventual consistency issues. and removed service/s3 Issues and PRs that pertain to the s3 service. service/sts Issues and PRs that pertain to the sts service. needs-triage Waiting for first response or review from a maintainer. labels Nov 22, 2022
@github-actions github-actions bot added this to the v5.25.0 milestone Nov 6, 2023
Copy link

This functionality has been released in v5.25.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!

Copy link

I'm going to lock this issue 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 similar to this, 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 Dec 11, 2023
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. eventual-consistency Pertains to eventual consistency issues. service/cloudtrail Issues and PRs that pertain to the cloudtrail service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants