Skip to content

Commit

Permalink
Switch SCPs to using OU Names
Browse files Browse the repository at this point in the history
  • Loading branch information
jchrisfarris committed Nov 7, 2023
1 parent 3e5440b commit d13c841
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion modules/scp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ variable "policy_json" {
type = string
}

variable "ou_name_to_id" {}
variable "root_ou" {}

resource "aws_organizations_policy" "scp" {
name = var.policy_name
type = "SERVICE_CONTROL_POLICY"
Expand All @@ -44,5 +47,6 @@ resource "aws_organizations_policy" "scp" {
resource "aws_organizations_policy_attachment" "scp_attachment" {
count = length(var.policy_targets)
policy_id = aws_organizations_policy.scp.id
target_id = var.policy_targets[count.index]
target_id = var.policy_targets[count.index] == "Root" ? var.root_ou : var.ou_name_to_id[var.policy_targets[count.index]]
}

4 changes: 3 additions & 1 deletion scps.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ module "scp" {
policy_name = each.value["policy_name"]
policy_description = each.value["policy_description"]
policy_json = templatefile(fileexists(each.value["policy_json_file"]) ? each.value["policy_json_file"] : "${path.module}/${each.value["policy_json_file"]}", lookup(each.value, "policy_vars", {}))
policy_targets = lookup(each.value, "policy_targets", [aws_organizations_organization.org.roots[0].id])
policy_targets = lookup(each.value, "policy_targets", ["Root"])
ou_name_to_id = local.ou_name_to_id # Pass the map to avoid regenerating it
root_ou = aws_organizations_organization.org.roots[0].id
}


0 comments on commit d13c841

Please sign in to comment.