Skip to content

Commit d84cf07

Browse files
authored
Merge pull request #8 from averbuks/master
Deprecate 'parent_type' and 'parent_id' input variables
2 parents 0c75f1c + b286c5d commit d84cf07

File tree

9 files changed

+37
-48
lines changed

9 files changed

+37
-48
lines changed

README.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ Basic usage of this module is as follows:
2121
```hcl
2222
module "folders" {
2323
source = "terraform-google-modules/folders/google"
24-
version = "~> 0.1"
24+
version = "~> 2.0"
2525
26-
parent_id = "65552901371"
27-
parent_type = "folder"
26+
parent = "folders/65552901371"
2827
2928
names = [
3029
"dev",
@@ -50,29 +49,27 @@ module "folders" {
5049
Functional examples are included in the
5150
[examples](./examples/) directory.
5251

53-
[^]: (autogen_docs_start)
54-
52+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
5553
## Inputs
5654

5755
| Name | Description | Type | Default | Required |
5856
|------|-------------|:----:|:-----:|:-----:|
59-
| all\_folder\_admins | List of IAM-style members that will get the extended permissions across all the folders. | list | `<list>` | no |
60-
| folder\_admin\_roles | List of roles that will be applied to per folder owners on their respective folder. | list | `<list>` | no |
61-
| names | Folder names. | list | `<list>` | no |
62-
| parent\_id | Id of the resource under which the folder will be placed. | string | n/a | yes |
63-
| parent\_type | Type of the parent reosurce, defaults to organization. | string | `"organization"` | no |
64-
| per\_folder\_admins | List of IAM-style members per folder who will get extended permissions. | list | `<list>` | no |
57+
| all\_folder\_admins | List of IAM-style members that will get the extended permissions across all the folders. | list(string) | `<list>` | no |
58+
| folder\_admin\_roles | List of roles that will be applied to per folder owners on their respective folder. | list(string) | `<list>` | no |
59+
| names | Folder names. | list(string) | `<list>` | no |
60+
| parent | The resource name of the parent Folder or Organization. Must be of the form folders/folder_id or organizations/org_id | string | n/a | yes |
61+
| per\_folder\_admins | List of IAM-style members per folder who will get extended permissions. | list(string) | `<list>` | no |
6562
| prefix | Optional prefix to enforce uniqueness of folder names. | string | `""` | no |
66-
| set\_roles | Set roles to actors passed in role_members variable. | string | `"false"` | no |
63+
| set\_roles | Set roles to actors passed in role_members variable. | bool | `"false"` | no |
6764

6865
## Outputs
6966

7067
| Name | Description |
7168
|------|-------------|
72-
| ids | Map of name => folder resource id. |
73-
| names | Map of name => folder resource name. |
69+
| names\_and\_display\_names | Map of name => folder resource name. |
70+
| names\_and\_ids | Map of name => folder resource id. |
7471

75-
[^]: (autogen_docs_end)
72+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
7673

7774
## Requirements
7875

examples/simple_example/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22

33
This example illustrates how to use the `folders` module.
44

5-
[^]: (autogen_docs_start)
6-
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
76
## Inputs
87

98
| Name | Description | Type | Default | Required |
109
|------|-------------|:----:|:-----:|:-----:|
11-
| all\_folder\_admins | List of IAM-style members that will get the extended permissions across all the folders. | list | `<list>` | no |
12-
| names | Folder names. | list | `<list>` | no |
10+
| all\_folder\_admins | List of IAM-style members that will get the extended permissions across all the folders. | list(string) | `<list>` | no |
11+
| names | Folder names. | list(string) | `<list>` | no |
1312
| parent\_id | Id of the resource under which the folder will be placed. | string | n/a | yes |
14-
| parent\_type | Type of the parent reosurce, defaults to organization. | string | `"organization"` | no |
15-
| per\_folder\_admins | List of IAM-style members per folder who will get extended permissions. | list | `<list>` | no |
13+
| parent\_type | Type of the parent reosurce, defaults to organization. | string | `"folders"` | no |
14+
| per\_folder\_admins | List of IAM-style members per folder who will get extended permissions. | list(string) | `<list>` | no |
1615

1716
## Outputs
1817

1918
| Name | Description |
2019
|------|-------------|
21-
| ids | Map of name => folder resource id. |
20+
| names\_and\_ids | Map of name => folder resource id. |
2221

23-
[^]: (autogen_docs_end)
22+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2423

2524
To provision this example, run the following from within this directory:
2625
- `terraform init` to get the plugins

examples/simple_example/main.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ provider "google" {
2121
module "folders" {
2222
source = "../.."
2323

24-
parent_id = var.parent_id
25-
parent_type = var.parent_type
24+
parent = "${var.parent_type}/${var.parent_id}"
2625
names = var.names
2726
set_roles = true
2827
per_folder_admins = var.per_folder_admins

examples/simple_example/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ variable "parent_id" {
2222
variable "parent_type" {
2323
type = string
2424
description = "Type of the parent reosurce, defaults to organization."
25-
default = "folder"
25+
default = "folders"
2626
}
2727

2828
variable "names" {

main.tf

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,22 @@ locals {
2525
resource "google_folder" "folders" {
2626
count = length(var.names)
2727
display_name = "${local.prefix}${element(var.names, count.index)}"
28-
parent = "${var.parent_type}s/${var.parent_id}"
28+
parent = "${var.parent}"
2929
}
3030

3131
# give project creation access to service accounts
3232
# https://cloud.google.com/resource-manager/docs/access-control-folders#granting_folder-specific_roles_to_enable_project_creation
3333

3434
resource "google_folder_iam_binding" "owners" {
35-
count = var.set_roles ? length(var.names) * length(var.folder_admin_roles) : 0
35+
count = var.set_roles ? length(var.names) * length(var.folder_admin_roles) : 0
3636
folder = google_folder.folders[floor(count.index / length(var.folder_admin_roles))].name
37-
role = var.folder_admin_roles[count.index % length(var.folder_admin_roles)]
37+
role = var.folder_admin_roles[count.index % length(var.folder_admin_roles)]
3838

3939
members = compact(
40-
concat(
41-
split(",",
42-
concat(var.per_folder_admins, [""])[floor(count.index / length(var.folder_admin_roles))],
43-
), var.all_folder_admins,
44-
),
45-
)
46-
}
47-
40+
concat(
41+
split(",",
42+
concat(var.per_folder_admins, [""])[floor(count.index / length(var.folder_admin_roles))],
43+
), var.all_folder_admins,
44+
),
45+
)
46+
}

test/fixtures/simple_example/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module "example" {
2222
source = "../../../examples/simple_example"
2323

2424
parent_id = var.parent_id
25+
parent_type = var.parent_type
2526
names = var.names
2627
per_folder_admins = var.per_folder_admins
2728
all_folder_admins = var.all_folder_admins

test/fixtures/simple_example/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ variable "parent_id" {
2222
variable "parent_type" {
2323
type = string
2424
description = "Type of the parent reosurce, defaults to organization."
25-
default = "folder"
25+
default = "folders"
2626
}
2727

2828
variable "names" {

test/integration/simple_example/inspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ attributes:
1515
type: hash
1616
- name: per_folder_admins
1717
required: true
18-
type: array
18+
type: array

variables.tf

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
variable "parent_id" {
17+
variable "parent" {
1818
type = string
19-
description = "Id of the resource under which the folder will be placed."
20-
}
21-
22-
variable "parent_type" {
23-
type = string
24-
description = "Type of the parent reosurce, defaults to organization."
25-
default = "organization"
19+
description = "The resource name of the parent Folder or Organization. Must be of the form folders/folder_id or organizations/org_id"
2620
}
2721

2822
variable "names" {
@@ -50,7 +44,7 @@ variable "all_folder_admins" {
5044
}
5145

5246
variable "prefix" {
53-
type = string
47+
type = string
5448
description = "Optional prefix to enforce uniqueness of folder names."
5549
default = ""
5650
}

0 commit comments

Comments
 (0)