Skip to content

Instantly share code, notes, and snippets.

@conzy
Created March 23, 2022 21:49
Show Gist options
  • Save conzy/e5eb0466171dd5209ffc202bce8e3b6b to your computer and use it in GitHub Desktop.
Save conzy/e5eb0466171dd5209ffc202bce8e3b6b to your computer and use it in GitHub Desktop.
Bucket policy that allows multiple accounts for AWS Config bucket
data "aws_iam_policy_document" "config_organization" {
statement {
principals {
identifiers = ["config.amazonaws.com"]
type = "Service"
}
actions = ["s3:GetBucketAcl"]
resources = [module.config_bucket.bucket_arn]
condition {
test = "StringEquals"
values = var.account_ids
variable = "AWS:SourceAccount"
}
}
statement {
principals {
identifiers = ["config.amazonaws.com"]
type = "Service"
}
actions = ["s3:ListBucket"]
resources = [
module.config_bucket.bucket_arn,
]
condition {
test = "StringEquals"
values = var.account_ids
variable = "AWS:SourceAccount"
}
}
statement {
principals {
identifiers = ["config.amazonaws.com"]
type = "Service"
}
actions = ["s3:PutObject"]
resources = [for account in var.account_ids : "${module.config_bucket.bucket_arn}/AWSLogs/${account}/*"]
condition {
test = "StringEquals"
values = ["bucket-owner-full-control"]
variable = "s3:x-amz-acl"
}
condition {
test = "StringEquals"
values = var.account_ids
variable = "AWS:SourceAccount"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment