Skip to content

Commit 0d4a01d

Browse files
authored
Merge pull request #2 from infraspecdev/refactor/organizational-unit
refactor: update variable names and parent org condition
2 parents 3cef917 + 0f2c908 commit 0d4a01d

File tree

6 files changed

+30
-17
lines changed

6 files changed

+30
-17
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ No modules.
2525
| Name | Type |
2626
|------|------|
2727
| [aws_organizations_organizational_unit.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_organizational_unit) | resource |
28+
| [aws_organizations_policy_attachment.policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_policy_attachment) | resource |
2829
| [aws_organizations_organization.org](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organization) | data source |
2930

3031
## Inputs
3132

3233
| Name | Description | Type | Default | Required |
3334
|------|-------------|------|---------|:--------:|
34-
| <a name="input_name"></a> [name](#input\_name) | The name of the organizational unit | `string` | n/a | yes |
35+
| <a name="input_attached_policies"></a> [attached\_policies](#input\_attached\_policies) | List of policy IDs to attach to the organizational unit. | `list(string)` | `[]` | no |
36+
| <a name="input_organizational_unit_name"></a> [organizational\_unit\_name](#input\_organizational\_unit\_name) | The name of the organizational unit | `string` | n/a | yes |
37+
| <a name="input_parent_org_id"></a> [parent\_org\_id](#input\_parent\_org\_id) | The ID of the parent organizational unit. | `string` | `""` | no |
3538

3639
## Outputs
3740

3841
| Name | Description |
3942
|------|-------------|
40-
| <a name="output_id"></a> [id](#output\_id) | The ID of the organizational unit |
43+
| <a name="output_organizational_unit_id"></a> [organizational\_unit\_id](#output\_organizational\_unit\_id) | The ID of the created organizational unit. |
4144
<!-- END_TF_DOCS -->

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)