Skip to content

Commit 1430f13

Browse files
authored
Merge pull request #9 from terraform-google-modules/ludo-fabric-outputs
Adopt the same output strategy as for the GCS and SA modules
2 parents e1c3829 + 2cd6a08 commit 1430f13

File tree

9 files changed

+145
-50
lines changed

9 files changed

+145
-50
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ and this project adheres to
99

1010
## [Unreleased]
1111

12+
## [2.0.0] - 2019-08-16
13+
14+
### Changed
15+
- Deprecate the `parent_id` and `parent_type` variables in favor of a single `parent` variable [#8]
16+
- Change outputs to follow the same conventions used in the `cloud-storage` and `service-accounts` modules ([migration instructions](docs/upgrading_to_folders_v2.0.md)) [#9]
17+
- Rename map outputs dropping the `names_and_` prefix
18+
- Add resource outputs
19+
- Add single use outputs
20+
- Add list-style outputs
21+
1222
## [1.0.0] - 2019-07-26
1323

1424
### Changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ Functional examples are included in the
6666

6767
| Name | Description |
6868
|------|-------------|
69-
| names\_and\_display\_names | Map of name => folder resource name. |
70-
| names\_and\_ids | Map of name => folder resource id. |
69+
| folder | Folder resource (for single use). |
70+
| folders | Folder resources. |
71+
| id | Folder id (for single use). |
72+
| ids | Folder ids. |
73+
| ids\_list | List of folder ids. |
74+
| name | Folder name (for single use). |
75+
| names | Folder names. |
76+
| names\_list | List of folder names. |
7177

7278
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
7379

docs/upgrading_to_folders_v2.0.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Upgrading to Folders v2.0 (from v1.X)
2+
3+
The v2.0 release of the Folders module is a backwards incompatible release, with two important sets of changes:
4+
5+
- the `parent_id` and `parent_type` variables have now been combined into a single `parent` variable
6+
- module outputs have changed to bring them in line with other modules
7+
8+
## Migration Instructions
9+
10+
### Single parent variable
11+
12+
The folder parent is now specificied using a single `parent` variable, that uses the full resource id path.
13+
14+
To create folders at the organization level, prefix the organization id with `organizations/`:
15+
16+
`parent = "organizations/0123456789"`
17+
18+
To create folders under an existing folder, prefix the existing folder id with `folders/`:
19+
20+
`parent = "folders/0123456789"`
21+
22+
### Rename map-style outputs
23+
24+
The `names_and_display_names` and `names_and_ids` outputs have been deprecated, and new ones are available in their place that expose the same data:
25+
26+
- `names_and_display_names` is now `names`
27+
- `names_and_ids` is now `ids`
28+
29+
### Leverage new output types
30+
31+
New output types have also been added that leverage new Terraform 0.12 features or facilitate specific use cases. They are describe below.
32+
33+
#### Folder resources
34+
35+
Terraform 0.12 makes it possible to expose complete resources alongside their attributes, so two new outputs have been added:
36+
37+
- `folder` is the first folder resource for single folder creation use cases
38+
- `folders` are all the folder resources as a list
39+
40+
#### Single folder use
41+
42+
When managing a single folder per module invocation, new outputs are available that directly expose its attributes:
43+
44+
- `folder` is the complete folder resource described above
45+
- `name` is a string output containing the display name of the folder, eg `"Test"`
46+
- `id` is a string output containing the numeric id of the folder, eg `"folders/12345"`
47+
48+
#### Lists
49+
50+
New list outputs have been added to expose folder attributes and preserve the ordering of the `names` variable, as maps reorder keys lexically and might introduce subtle bugs when used as lists through `values`:
51+
52+
- `names_list` is the list of folder display names as strings
53+
- `ids_list` is the list of folder ids as strings

examples/simple_example/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ This example illustrates how to use the `folders` module.
1717

1818
| Name | Description |
1919
|------|-------------|
20-
| names\_and\_ids | Map of name => folder resource id. |
20+
| ids | Folder ids. |
21+
| ids\_list | List of folder ids. |
22+
| names | Folder names. |
2123

2224
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2325

examples/simple_example/outputs.tf

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

17-
output "names_and_ids" {
18-
description = "Map of name => folder resource id."
19-
value = module.folders.names_and_ids
17+
output "ids" {
18+
description = "Folder ids."
19+
value = module.folders.ids
2020
}
2121

22+
output "names" {
23+
description = "Folder names."
24+
value = module.folders.names
25+
}
26+
27+
output "ids_list" {
28+
description = "List of folder ids."
29+
value = module.folders.ids_list
30+
}

outputs.tf

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,42 @@
1414
* limitations under the License.
1515
*/
1616

17-
output "names_and_display_names" {
18-
description = "Map of name => folder resource name."
19-
value = zipmap(var.names, google_folder.folders.*.display_name)
17+
output "folder" {
18+
description = "Folder resource (for single use)."
19+
value = google_folder.folders[0]
2020
}
2121

22-
output "names_and_ids" {
23-
description = "Map of name => folder resource id."
24-
value = zipmap(var.names, google_folder.folders.*.name)
22+
output "id" {
23+
description = "Folder id (for single use)."
24+
value = google_folder.folders[0].name
2525
}
2626

27+
output "name" {
28+
description = "Folder name (for single use)."
29+
value = google_folder.folders[0].display_name
30+
}
31+
32+
output "folders" {
33+
description = "Folder resources."
34+
value = google_folder.folders
35+
}
36+
37+
output "ids" {
38+
description = "Folder ids."
39+
value = zipmap(var.names, google_folder.folders[*].name)
40+
}
41+
42+
output "names" {
43+
description = "Folder names."
44+
value = zipmap(var.names, google_folder.folders[*].display_name)
45+
}
46+
47+
output "ids_list" {
48+
description = "List of folder ids."
49+
value = google_folder.folders[*].name
50+
}
51+
52+
output "names_list" {
53+
description = "List of folder names."
54+
value = google_folder.folders[*].display_name
55+
}

test/fixtures/simple_example/outputs.tf

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

17-
output "names_and_ids" {
18-
description = "Map of name => folder resource id."
19-
value = module.example.names_and_ids
17+
output "names" {
18+
description = "Folder names."
19+
value = module.example.names
20+
}
21+
22+
output "ids_list" {
23+
description = "List of folder ids."
24+
value = module.example.ids_list
2025
}
2126

2227
output "parent_id" {
@@ -29,11 +34,6 @@ output "parent_type" {
2934
value = var.parent_type
3035
}
3136

32-
output "names" {
33-
description = "Folder names."
34-
value = var.names
35-
}
36-
3737
output "per_folder_admins" {
3838
description = "List of IAM-style members per folder who will get extended permissions."
3939
value = var.per_folder_admins

test/integration/simple_example/controls/gcloud.rb

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,21 @@
1818
describe command("gcloud resource-manager folders list --folder=#{attribute("parent_id")}") do
1919
its(:exit_status) { should eq 0 }
2020
its(:stderr) { should eq "" }
21-
its(:stdout) { should include "#{attribute("names")[0]}" }
22-
its(:stdout) { should include "#{attribute("names")[1]}" }
23-
its(:stdout) { should include "#{attribute("names")[2]}" }
21+
its(:stdout) { should include "#{attribute("names").values[0]}" }
22+
its(:stdout) { should include "#{attribute("names").values[1]}" }
23+
its(:stdout) { should include "#{attribute("names").values[2]}" }
2424
end
2525

2626
folder_names = attribute("names")
27-
folder_names_and_ids = attribute("names_and_ids")
27+
folder_ids = attribute("ids_list")
2828
per_folder_admins = attribute("per_folder_admins")
2929

30-
folder_id = folder_names_and_ids[folder_names[0]]
31-
folder_admin = per_folder_admins[0]
32-
describe command("gcloud alpha resource-manager folders get-iam-policy #{folder_id}") do
33-
its(:exit_status) { should eq 0 }
34-
its(:stderr) { should eq "" }
35-
its(:stdout) { should include "#{attribute("per_folder_admins")[0]}" }
36-
end
37-
38-
39-
folder_id = folder_names_and_ids[folder_names[1]]
40-
folder_admin = per_folder_admins[1]
41-
describe command("gcloud alpha resource-manager folders get-iam-policy #{folder_id}") do
42-
its(:exit_status) { should eq 0 }
43-
its(:stderr) { should eq "" }
44-
its(:stdout) { should include "#{attribute("per_folder_admins")[1]}" }
45-
end
46-
47-
folder_id = folder_names_and_ids[folder_names[2]]
48-
folder_admin = per_folder_admins[2]
49-
describe command("gcloud alpha resource-manager folders get-iam-policy #{folder_id}") do
50-
its(:exit_status) { should eq 0 }
51-
its(:stderr) { should eq "" }
52-
its(:stdout) { should include "#{attribute("per_folder_admins")[2]}" }
30+
(0..2).each do |i|
31+
describe command("gcloud alpha resource-manager folders get-iam-policy #{folder_ids[i]}") do
32+
its(:exit_status) { should eq 0 }
33+
its(:stderr) { should eq "" }
34+
its(:stdout) { should include per_folder_admins[i] }
35+
end
5336
end
5437

5538
end

test/integration/simple_example/inspec.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ attributes:
88
required: true
99
type: string
1010
- name: names
11+
required: true
12+
type: hash
13+
- name: ids_list
1114
required: true
1215
type: array
13-
- name: names_and_ids
16+
- name: per_folder_admins
1417
required: true
15-
type: hash
18+
type: array
1619
- name: per_folder_admins
1720
required: true
18-
type: array
21+
type: array

0 commit comments

Comments
 (0)