CloudFormation CloudTrail S3 Policy Error - Incorrect S3 bucket policy is detected for bucket
Date : March 29 2020, 07:55 AM
may help you . To fix this the resource needed to be joined up to the bucket using a reference "Resource": [{
"Fn::Join": [ "", [
"arn:aws:s3:::", {
"Ref": "s3traillogs"
}, "/AWSLogs/XXXXXXXXXXX/*"
]
]
}],
|
Terraform use existing policy for s3 bucket
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You have multiple ways to achieve that. You can have a policy JSON and reference it in every bucket: resource "aws_s3_bucket" "b" {
bucket = "s3-website-test.hashicorp.com"
acl = "public-read"
policy = "${file("policy.json")}"
}
data "aws_iam_policy_document" "your_super_amazing_policy" {
count = "${length(keys(var.statement))}"
statement {
sid = "CloudfrontBucketActions"
actions = ["s3:GetObject"]
resources = ["*"]
}
resource "aws_s3_bucket" "private_bucket" {
bucket = "acme-private-bucket"
acl = "private"
policy = "${data.aws_iam_policy_document.your_super_amazing_policy.json}"
tags {
Name = "private-bucket"
terraform = "true"
}
}
|
Attach a single IAM policy to two separate roles in two different regions (same account) using terraform and apex
Date : March 29 2020, 07:55 AM
With these it helps aws_iam_policy_attachment creates exclusive attachment of IAM Policies and override any existing policy attached to the IAM Role. If you are looking to attach multiple policies to a Single IAM Role, then try using aws_iam_role_policy_attachment ( https://www.terraform.io/docs/providers/aws/r/iam_role_policy_attachment.html). This resource should help you to achieve your goal.
|
How do I create an S3 bucket policy from a template in Terraform 0.12?
Date : March 29 2020, 07:55 AM
like below fixes the issue You can use data resource to create a JSON template for policy by passing the variables based on your environment and use that template_file as policy in aws_s3_bucket resource. variable "env-bucket" {
default = "sample"
}
variable "env-vpce" {
default = "sample-vpc"
}
data "template_file" "policy" {
template = "${file("policy.json")}"
vars = {
env-bucket = "${var.env-bucket}"
env-vpce = "${var.env-vpce}"
}
}
resource "aws_s3_bucket" "b" {
bucket = "my-tf-test-bucket"
policy = "${data.template_file.policy.rendered}"
}
|
Terraform tries to create s3 bucket policy although it exists
Date : September 24 2020, 05:00 PM
This might help you Your terraform state doesn't know that the policy already exists. You need to import it first with something like this: terraform import aws_s3_bucket_policy.example my-bucket-name
|