Skip to content

Commit a160d5f

Browse files
SudharsaneSivamanysudharsane sivamany
andauthored
feat: Added new feature for hierarchical compartments (#42)
* Added new feature for #41 issue Signed-off-by: sudharsane sivamany <[email protected]> * Updating the year for copyright Signed-off-by: sudharsane sivamany <[email protected]> * Updating the year for copyright Signed-off-by: sudharsane sivamany <[email protected]> * Updating the year for copyright Signed-off-by: sudharsane sivamany <[email protected]> * Updating the year for copyright Signed-off-by: sudharsane sivamany <[email protected]> --------- Signed-off-by: sudharsane sivamany <[email protected]> Co-authored-by: sudharsane sivamany <[email protected]>
1 parent 01978b7 commit a160d5f

28 files changed

+406
-19
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ Given a version number MAJOR.MINOR.PATCH:
1111
- MINOR version when adding functionality in a backwards compatible manner,
1212
- PATCH version when making backwards compatible bug fixes.
1313

14+
## [2.0.2] - 2025-05-27
15+
16+
### Added
17+
18+
#### New features
19+
20+
- iam-hierarchical-compartment
21+
1422
## [2.0.1] - 2021-02-09
1523

1624
### Fixed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
Copyright (c) 2018, 2025, Oracle and/or its affiliates.
22

33
This software is dual-licensed to you under the Universal Permissive License (UPL) or Apache License 2.0. See below for license terms. You may choose either license.
44
____________________________
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2018, 2025, Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
compartments:
5+
- compartment_name: compartment_level_1_a
6+
description: "level 1 a"
7+
freeform_tags:
8+
"Env": "Dev"
9+
"Billing": "Devbilling"
10+
enable_delete: true
11+
compartments:
12+
- compartment_name: compartment_level_2_a
13+
description: "level 2 a"
14+
enable_delete: true
15+
compartments:
16+
- compartment_name: compartment_level_3_1_a
17+
description: "level 3.1 a"
18+
enable_delete: true
19+
compartments: []
20+
- compartment_name: compartment_level_3_2_a
21+
description: "level 3.2 a"
22+
enable_delete: true
23+
compartments:
24+
- compartment_name: compartment_level_4_a
25+
description: "level 4 a"
26+
enable_delete: true
27+
compartments:
28+
- compartment_name: compartment_level_5_a
29+
description: "level 5 a"
30+
enable_delete: true
31+
compartments:
32+
- compartment_name: compartment_level_6_a
33+
description: "level 6 a"
34+
enable_delete: true
35+
- compartment_name: compartment_level_1_b
36+
description: "level 1 b"
37+
enable_delete: true
38+
compartments:
39+
- compartment_name: compartment_level_2_b
40+
compartments: []
41+
description: "level 2b"
42+
enable_delete: true
43+
freeform_tags:
44+
"Env": "Test"
45+
"Billing": "Testbilling"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2018, 2025, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
/*
5+
* This example shows how to create a hierarchical compartments.
6+
*
7+
* The hierarchical_compartment_config.yaml contains the detailed structure of
8+
* compartments that needs to be provisioned.
9+
*/
10+
11+
module "Hierarchical_compartment" {
12+
source = "oracle-terraform-modules/iam/oci//modules/iam-hierarchical-compartment"
13+
# version = "2.0.2"
14+
root_compartment_id = var.tenancy_ocid # define the parent compartment. Creation at tenancy root if omitted
15+
compartments = yamldecode(file("${path.module}/hierarchical_compartment_config.yaml"))["compartments"]
16+
}

examples/main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2025, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
23

34
variable "tenancy_ocid" {}
45
variable "compartment_ocid" {}
@@ -51,7 +52,7 @@ module "iam_compartment" {
5152
}
5253

5354
module "iam_subcompartment1" {
54-
source = "oracle-terraform-modules/iam/oci//modules/iam-compartment"
55+
source = "oracle-terraform-modules/iam/oci//modules/iam-compartment"
5556
# Pinning each module to a specific version is highly advisable. Please adjust and uncomment the line below
5657
# version = "x.x.x"
5758
tenancy_ocid = var.tenancy_ocid
@@ -63,7 +64,7 @@ module "iam_subcompartment1" {
6364
}
6465

6566
module "iam_subcompartment2" {
66-
source = "oracle-terraform-modules/iam/oci//modules/iam-compartment"
67+
source = "oracle-terraform-modules/iam/oci//modules/iam-compartment"
6768
# Pinning each module to a specific version is highly advisable. Please adjust and uncomment the line below
6869
# version = "x.x.x"
6970
tenancy_ocid = var.tenancy_ocid
@@ -75,7 +76,7 @@ module "iam_subcompartment2" {
7576
}
7677

7778
module "iam_users" {
78-
source = "oracle-terraform-modules/iam/oci//modules/iam-user"
79+
source = "oracle-terraform-modules/iam/oci//modules/iam-user"
7980
# Pinning each module to a specific version is highly advisable. Please adjust and uncomment the line below
8081
# version = "x.x.x"
8182
tenancy_ocid = var.tenancy_ocid
@@ -115,7 +116,7 @@ module "iam_group" {
115116
}
116117

117118
module "iam_dynamic_group" {
118-
source = "oracle-terraform-modules/iam/oci//modules/iam-dyanmic-group"
119+
source = "oracle-terraform-modules/iam/oci//modules/iam-dyanmic-group"
119120
# Pinning each module to a specific version is highly advisable. Please adjust and uncomment the line below
120121
# version = "x.x.x"
121122
tenancy_ocid = var.tenancy_ocid

examples/outputs.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2025, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
23

34
output "iam_compartment" {
45
description = "compartment name, description, ocid, and parent ocid"
@@ -43,3 +44,8 @@ output "iam_dynamic_group_name" {
4344
description = "dynamic group name and associated ocid"
4445
value = module.iam_dynamic_group.name_ocid
4546
}
47+
48+
output "compartment_ids_under_root" {
49+
description = "Compartment id list under root"
50+
value = module.Hierarchical_compartment.compartment_ids
51+
}

examples/terraform.tfvars.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) 2018, 2025, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
14
# OCI Authentication details
25
tenancy_ocid = "<tenancy OCID>"
36
compartment_ocid = "<compartment OCID>"

modules/iam-compartment/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Copyright (c) 2018, 2023 Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2025, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
24

35
########################
46
# Compartment

modules/iam-compartment/outputs.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2025, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
24

35
output "compartment_id" {
46
description = "Compartment ocid"

modules/iam-compartment/variables.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2025, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
24

35
variable "tenancy_ocid" {
46
type = string

0 commit comments

Comments
 (0)