Skip to content

Instantly share code, notes, and snippets.

@nhandler
Created January 9, 2019 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhandler/97f55b13187d51968efa61de06f2b2f6 to your computer and use it in GitHub Desktop.
Save nhandler/97f55b13187d51968efa61de06f2b2f6 to your computer and use it in GitHub Desktop.
Terraform JSON Policy Templating Example
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