Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rnrbarbosa/d6347b7cded67501869d1ca6ebe4903a to your computer and use it in GitHub Desktop.
Save rnrbarbosa/d6347b7cded67501869d1ca6ebe4903a to your computer and use it in GitHub Desktop.
provider "aws" {
region = "eu-central-1"
}
variable "input-buckets" {
default = [
"bucket1",
"bucket2"
]
}
variable "input-read" { default = false }
resource "aws_iam_policy" "read-only" {
count = "${var.input-read? length(var.input-buckets) : 0}"
name = "read-only-policy"
path = "/"
description = "My test policy"
policy = <<EOF
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal": "*",
"Action":[
"s3:GetObject",
"s3:List*"
],
"Resource":["arn:aws:s3:::${element(var.input-buckets, count.index)}/*"]
}
]
}
EOF
}
variable "output-write" { default = true }
variable "output-buckets" {
default = [
"bucket1",
"bucket2"
]
}
resource "aws_iam_policy" "write-list" {
count = "${var.output-write? length(var.output-buckets) : 0}"
name = "write-policy"
path = "/"
description = "My test policy"
policy = <<EOF
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal": "*",
"Action":[
"s3:List*",
"s3:PutObject"
],
"Resource":["arn:aws:s3:::${element(var.output-buckets, count.index)}/*"]
}
]
}
EOF
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment