Created
January 9, 2019 04:14
-
-
Save nhandler/97f55b13187d51968efa61de06f2b2f6 to your computer and use it in GitHub Desktop.
Terraform JSON Policy Templating Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "template_files" { | |
default = [ | |
"policy1.json", | |
"policy2.json", | |
] | |
} | |
data "template_file" "template" { | |
count = "${length(var.template_files)}" | |
template = "${file("${path.module}/templates/${element(var.template_files, count.index)}")}" | |
vars { | |
some_account_id = "12345678" | |
some_role_id = "${data.terraform_remote_state.other_state.fake_role_id}" | |
} | |
} | |
resource "aws_s3_bucket_policy" "some_bucket_policy" { | |
bucket = "some_bucket" | |
policy = "${element(data.template_file.template.*.rendered, index(var.template_files, "policy1.json"))}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment