Skip to content

Commit e66fcab

Browse files
committed
refactor: update variable names and parent org condition
1 parent 3cef917 commit e66fcab

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

data.tf

Lines changed: 0 additions & 1 deletion
This file was deleted.

main.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
data "aws_organizations_organization" "org" {}
2+
13
resource "aws_organizations_organizational_unit" "this" {
2-
name = var.name
3-
parent_id = data.aws_organizations_organization.org.roots[0].id
4+
name = var.organizational_unit_name
5+
parent_id = var.parent_org_id != "" ? var.parent_org_id : data.aws_organizations_organization.org.roots[0].id
6+
}
7+
8+
resource "aws_organizations_policy_attachment" "policy_attachment" {
9+
count = length(var.attached_policies)
10+
policy_id = var.attached_policies[count.index]
11+
target_id = aws_organizations_organizational_unit.this.id
412
}

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
output "id" {
2-
description = "The ID of the organizational unit"
1+
output "organizational_unit_id" {
2+
description = "The ID of the created organizational unit."
33
value = aws_organizations_organizational_unit.this.id
44
}

provider.tf

Lines changed: 0 additions & 9 deletions
This file was deleted.

variables.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
variable "name" {
1+
variable "organizational_unit_name" {
22
description = "The name of the organizational unit"
33
type = string
44
}
5+
6+
variable "parent_org_id" {
7+
description = "The ID of the parent organizational unit."
8+
type = string
9+
default = ""
10+
}
11+
12+
variable "attached_policies" {
13+
description = "List of policy IDs to attach to the organizational unit."
14+
type = list(string)
15+
default = []
16+
}

0 commit comments

Comments
 (0)