Skip to content

Commit 02af7d7

Browse files
authored
template files (#6)
support for template files (`.json.tpl`)
1 parent 6150105 commit 02af7d7

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

locals.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,16 @@
33

44
locals {
55
policies_directory = var.policies_directory == null ? lower(var.policy_type) : var.policies_directory
6+
7+
policy_content = merge(
8+
{
9+
for file_path in fileset(path.root, "${local.policies_directory}/*.json") :
10+
file_path => file(file_path)
11+
},
12+
{
13+
for file_path in fileset(path.root, "${local.policies_directory}/*.json.tpl") :
14+
replace(file_path, ".json.tpl", ".json") => templatefile(file_path, var.template_variables)
15+
}
16+
)
617
}
18+

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// SPDX-License-Identifier: MIT-0
33

44
resource "aws_organizations_policy" "this" {
5-
for_each = fileset(path.root, "${local.policies_directory}/*.json")
6-
name = trimprefix(trimsuffix(each.value, ".json"), "${local.policies_directory}/")
7-
content = file(each.value)
5+
for_each = local.policy_content
6+
name = trimprefix(trimsuffix(each.key, ".json"), "${local.policies_directory}/")
7+
content = each.value
88
type = var.policy_type
99
}
1010

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ variable "policies_directory" {
1212
variable "policy_type" {
1313
type = string
1414
}
15+
16+
variable "template_variables" {
17+
description = "Variables to substitute in policy templates (.json.tpl files)"
18+
type = map(string)
19+
default = {}
20+
}

0 commit comments

Comments
 (0)