by chucky_z · 6y ago · 0 comments
data "aws_iam_policy_document" "s3_bucket" {
version = "2012-10-17"
statement {
sid = "PublicReadGetObject"
principals {
type = "*"
identifiers = ["*"]
}
actions = [
"s3:GetObject"
]
resources = [
"arn:aws:s3:::${var.bucket_name}/*"
]
}
}
resource "aws_s3_bucket" "s3_bucket" {
bucket = var.bucket_name
acl = "public-read"
policy = data.aws_iam_policy_document.s3_bucket.json
website {
index_document = "index.html"
error_document = "error.html"
}
tags = var.tags
}As much documentation as they have, Hashicorp products can be very confusing.
Also, like, most of their examples ignore this data resource. That specific data resource, with terraform 0.12 makes building IAMs so much nicer, because you can mash a bunch of common ones together with for_each and generate policies in a dynamic way without having to learn dynamic IAM stuff, which is it's own thing entirely.