Skip to content

Commit 69b0fd8

Browse files
committed
Add support for Terraform v0.12 #2
1 parent 29f01c7 commit 69b0fd8

File tree

18 files changed

+151
-66
lines changed

18 files changed

+151
-66
lines changed

CHANGELOG.md

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

1010
## [Unreleased]
1111

12+
### CHANGED
13+
14+
- Upgraded for usage with terraform-0.12.x [#3]
15+
1216
## [0.1.0] - 2019-05-28
1317

1418
### Added
@@ -17,3 +21,4 @@ and this project adheres to
1721

1822
[Unreleased]: https://github.com/terraform-google-modules/terraform-google-folders/compare/v0.1.0...HEAD
1923
[0.1.0]: https://github.com/terraform-google-modules/terraform-google-folders/releases/tag/v0.1.0
24+
[#3]: https://github.com/terraform-google-modules/terraform-google-folders/pull/3

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
ruby '2.5.3'
1616

1717
source 'https://rubygems.org/' do
18-
gem 'kitchen-terraform', '~> 4.8'
18+
gem 'kitchen-terraform', '~> 4.9'
1919
end

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SHELL := /usr/bin/env bash
2121
# Docker build config variables
2222
CREDENTIALS_PATH ?= /cft/workdir/credentials.json
2323
DOCKER_ORG := gcr.io/cloud-foundation-cicd
24-
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 1.0.1
24+
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 2.3.0
2525
DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCKER_TAG_BASE_KITCHEN_TERRAFORM}
2626

2727
# All is the first target in the file so it will get picked up when you just run 'make' on its own
@@ -30,7 +30,7 @@ all: check generate_docs
3030

3131
# Run all available linters
3232
.PHONY: check
33-
check: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace
33+
check: check_python check_golang check_terraform check_base_files test_check_headers check_headers check_trailing_whitespace
3434

3535
# The .PHONY directive tells make that this isn't a real target and so
3636
# the presence of a file named 'check_shell' won't cause this target to stop
@@ -95,7 +95,7 @@ docker_run:
9595
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
9696
-v $(CURDIR):/cft/workdir \
9797
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
98-
/bin/bash -c "source test/ci_integration.sh && setup_environment && exec /bin/bash"
98+
/bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && exec /bin/bash"
9999

100100
.PHONY: docker_create
101101
docker_create:
@@ -105,7 +105,7 @@ docker_create:
105105
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
106106
-v $(CURDIR):/cft/workdir \
107107
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
108-
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen create"
108+
/bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && kitchen create"
109109

110110
.PHONY: docker_converge
111111
docker_converge:
@@ -115,7 +115,7 @@ docker_converge:
115115
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
116116
-v $(CURDIR):/cft/workdir \
117117
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
118-
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen converge"
118+
/bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && kitchen converge"
119119

120120
.PHONY: docker_verify
121121
docker_verify:
@@ -125,7 +125,7 @@ docker_verify:
125125
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
126126
-v $(CURDIR):/cft/workdir \
127127
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
128-
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen verify"
128+
/bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && kitchen verify"
129129

130130
.PHONY: docker_destroy
131131
docker_destroy:
@@ -135,7 +135,7 @@ docker_destroy:
135135
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
136136
-v $(CURDIR):/cft/workdir \
137137
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
138-
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen destroy"
138+
/bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && kitchen destroy"
139139

140140
.PHONY: test_integration_docker
141141
test_integration_docker:
@@ -145,4 +145,4 @@ test_integration_docker:
145145
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
146146
-v $(CURDIR):/cft/workdir \
147147
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
148-
make test_integration
148+
/bin/bash -c "cd /cft/workdir && source test/ci_integration.sh && setup_environment && make test_integration"

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ The resources/services/activations/deletions that this module will create/trigge
77
- Create folders with the provided names
88
- Assign the defined permissions to the provided list of users or groups.
99

10+
## Compatibility
11+
12+
This module is meant for use with Terraform 0.12. If you haven't [upgraded](https://www.terraform.io/upgrade-guides/0-12.html)
13+
and need a Terraform 0.11.x-compatible version of this module, the last released version intended for
14+
Terraform 0.11.x is [0.1.0](https://registry.terraform.io/modules/terraform-google-modules/folders/google/0.1.0).
15+
16+
1017
## Usage
1118

1219
Basic usage of this module is as follows:
@@ -75,7 +82,7 @@ These sections describe requirements for using this module.
7582

7683
The following dependencies must be available:
7784

78-
- [Terraform][terraform] v0.11
85+
- [Terraform][terraform] v0.12
7986
- [Terraform Provider for GCP][terraform-provider-gcp] plugin v2.0
8087

8188
### Service Account

examples/simple_example/main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
*/
1616

1717
provider "google" {
18-
version = "~> 2.0"
18+
version = "~> 2.7"
1919
}
2020

2121
module "folders" {
2222
source = "../.."
2323

24-
parent_id = "${var.parent_id}"
25-
parent_type = "${var.parent_type}"
26-
names = "${var.names}"
27-
set_roles = true
28-
per_folder_admins = "${var.per_folder_admins}"
29-
all_folder_admins = "${var.all_folder_admins}"
30-
}
24+
parent_id = var.parent_id
25+
parent_type = var.parent_type
26+
names = var.names
27+
set_roles = true
28+
per_folder_admins = var.per_folder_admins
29+
all_folder_admins = var.all_folder_admins
30+
}
31+

examples/simple_example/outputs.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616

1717
output "names_and_ids" {
1818
description = "Map of name => folder resource id."
19-
value = "${module.folders.names_and_ids}"
20-
}
19+
value = module.folders.names_and_ids
20+
}
21+

examples/simple_example/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,31 @@
1515
*/
1616

1717
variable "parent_id" {
18+
type = string
1819
description = "Id of the resource under which the folder will be placed."
1920
}
2021

2122
variable "parent_type" {
23+
type = string
2224
description = "Type of the parent reosurce, defaults to organization."
2325
default = "folder"
2426
}
2527

2628
variable "names" {
29+
type = list(string)
2730
description = "Folder names."
2831
default = []
2932
}
3033

3134
variable "per_folder_admins" {
35+
type = list(string)
3236
description = "List of IAM-style members per folder who will get extended permissions."
3337
default = []
3438
}
3539

3640
variable "all_folder_admins" {
41+
type = list(string)
3742
description = "List of IAM-style members that will get the extended permissions across all the folders."
3843
default = []
39-
}
44+
}
45+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
terraform {
18+
required_version = ">= 0.12"
19+
}

main.tf

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
*/
1616

1717
terraform {
18-
required_version = "~> 0.11.0"
18+
required_version = ">= 0.12"
1919
}
2020

2121
locals {
22-
prefix = "${var.prefix == "" ? "" : "${var.prefix}-"}"
22+
prefix = var.prefix == "" ? "" : "${var.prefix}-"
2323
}
2424

2525
resource "google_folder" "folders" {
26-
count = "${length(var.names)}"
26+
count = length(var.names)
2727
display_name = "${local.prefix}${element(var.names, count.index)}"
2828
parent = "${var.parent_type}s/${var.parent_id}"
2929
}
@@ -32,14 +32,16 @@ resource "google_folder" "folders" {
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}"
36-
folder = "${element(google_folder.folders.*.name, count.index / length(var.folder_admin_roles))}"
37-
role = "${element(var.folder_admin_roles, count.index % length(var.folder_admin_roles))}"
35+
count = var.set_roles ? length(var.names) * length(var.folder_admin_roles) : 0
36+
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)]
38+
39+
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+
}
3847

39-
members = ["${
40-
compact(concat(
41-
split(",", element(concat(var.per_folder_admins, list("")), count.index / length(var.folder_admin_roles))),
42-
var.all_folder_admins
43-
))
44-
}"]
45-
}

outputs.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
output "names_and_display_names" {
1818
description = "Map of name => folder resource name."
19-
value = "${zipmap(var.names, google_folder.folders.*.display_name)}"
19+
value = zipmap(var.names, google_folder.folders.*.display_name)
2020
}
2121

2222
output "names_and_ids" {
2323
description = "Map of name => folder resource id."
24-
value = "${zipmap(var.names, google_folder.folders.*.name)}"
25-
}
24+
value = zipmap(var.names, google_folder.folders.*.name)
25+
}
26+

0 commit comments

Comments
 (0)