Skip to content

Commit 9d07ccd

Browse files
authored
Merge pull request #309 from terraform-google-modules/fabric-issue-308
Fix issue #308 in fabric submodule, add submodule tests, general cleanup
2 parents fe91d4b + 06caa93 commit 9d07ccd

File tree

17 files changed

+355
-29
lines changed

17 files changed

+355
-29
lines changed

.kitchen.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ suites:
3232
name: terraform
3333
command_timeout: 1800
3434
root_module_directory: test/fixtures/minimal
35+
- name: fabric_project
36+
driver:
37+
name: terraform
38+
command_timeout: 1800
39+
root_module_directory: test/fixtures/fabric_project
3540
# Disabled due to issue #275
3641
# (https://github.com/terraform-google-modules/terraform-google-project-factory/issues/275)
3742
# - name: full

CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
* @morgante @aaron-lane @adrienthebo
2+
3+
# CFT Fabric
4+
/modules/fabric-project/ @terraform-google-modules/cft-fabric

examples/fabric_project/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Simple Project
2+
3+
This example illustrates how to create a simple project using the `fabric-project` submodule.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|:----:|:-----:|:-----:|
10+
| activate\_apis | Service APIs to enable. | list(string) | `<list>` | no |
11+
| billing\_account | Billing account id. | string | n/a | yes |
12+
| name | Project name, joined with prefix. | string | `"fabric-project"` | no |
13+
| owners | Optional list of IAM-format members to set as project owners. | list(string) | `<list>` | no |
14+
| parent | Organization or folder id, in the `organizations/nnn` or `folders/nnn` format. | string | n/a | yes |
15+
| prefix | Prefix prepended to project name, uses random id by default. | string | `""` | no |
16+
17+
## Outputs
18+
19+
| Name | Description |
20+
|------|-------------|
21+
| name | The name of the created project. |
22+
| project\_id | The project id of the created project. |
23+
| project\_number | The project number of the created project. |
24+
25+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/fabric_project/main.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
locals {
18+
prefix = var.prefix == "" ? random_string.prefix.result : var.prefix
19+
}
20+
21+
resource "random_string" "prefix" {
22+
length = 30 - length(var.name) - 1
23+
upper = false
24+
number = false
25+
special = false
26+
}
27+
module "fabric-project" {
28+
source = "../../modules/fabric-project"
29+
activate_apis = var.activate_apis
30+
billing_account = var.billing_account
31+
name = var.name
32+
owners = var.owners
33+
parent = var.parent
34+
prefix = local.prefix
35+
}

examples/fabric_project/outputs.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
output "project_id" {
18+
description = "The project id of the created project."
19+
value = module.fabric-project.project_id
20+
}
21+
22+
output "name" {
23+
description = "The name of the created project."
24+
value = module.fabric-project.name
25+
}
26+
27+
output "project_number" {
28+
description = "The project number of the created project."
29+
value = module.fabric-project.number
30+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
variable "activate_apis" {
18+
description = "Service APIs to enable."
19+
type = list(string)
20+
default = ["compute.googleapis.com"]
21+
}
22+
23+
variable "billing_account" {
24+
description = "Billing account id."
25+
type = string
26+
}
27+
28+
variable "name" {
29+
description = "Project name, joined with prefix."
30+
type = string
31+
default = "fabric-project"
32+
}
33+
34+
variable "owners" {
35+
description = "Optional list of IAM-format members to set as project owners."
36+
type = list(string)
37+
default = []
38+
}
39+
40+
variable "parent" {
41+
description = "Organization or folder id, in the `organizations/nnn` or `folders/nnn` format."
42+
type = string
43+
}
44+
45+
variable "prefix" {
46+
description = "Prefix prepended to project name, uses random id by default."
47+
type = string
48+
default = ""
49+
}

modules/fabric-project/README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ module "project_myproject" {
3434

3535
| Name | Description | Type | Default | Required |
3636
|------|-------------|:----:|:-----:|:-----:|
37-
| activate\_apis | Service APIs to enable. | list | `<list>` | no |
38-
| auto\_create\_network | Whether to create the default network for the project | string | `"false"` | no |
37+
| activate\_apis | Service APIs to enable. | list(string) | `<list>` | no |
38+
| auto\_create\_network | Whether to create the default network for the project | bool | `"false"` | no |
3939
| billing\_account | Billing account id. | string | `""` | no |
40-
| custom\_roles | Map of role name => comma-delimited list of permissions to create in this project. | map | `<map>` | no |
41-
| editors | Optional list of IAM-format members to set as project editor. | list | `<list>` | no |
42-
| extra\_bindings\_members | List of comma-delimited IAM-format members for additional IAM bindings, one item per role. | list | `<list>` | no |
43-
| extra\_bindings\_roles | List of roles for additional IAM bindings, pair with members list below. | list | `<list>` | no |
44-
| gce\_service\_account\_roles | List of project id=>role to assign to the default GCE service account. | list | `<list>` | no |
45-
| labels | Resource labels. | map | `<map>` | no |
40+
| custom\_roles | Map of role name => comma-delimited list of permissions to create in this project. | map(string) | `<map>` | no |
41+
| editors | Optional list of IAM-format members to set as project editor. | list(string) | `<list>` | no |
42+
| extra\_bindings\_members | List of comma-delimited IAM-format members for additional IAM bindings, one item per role. | list(string) | `<list>` | no |
43+
| extra\_bindings\_roles | List of roles for additional IAM bindings, pair with members list below. | list(string) | `<list>` | no |
44+
| gce\_service\_account\_roles | List of project id=>role to assign to the default GCE service account. | list(string) | `<list>` | no |
45+
| labels | Resource labels. | map(string) | `<map>` | no |
4646
| lien\_reason | If non-empty, creates a project lien with this description. | string | `""` | no |
4747
| name | Project name and id suffix. | string | n/a | yes |
48-
| oslogin | Enable oslogin. | string | `"false"` | no |
49-
| oslogin\_admins | List of IAM-format members that will get OS Login admin role. | list | `<list>` | no |
50-
| oslogin\_users | List of IAM-format members that will get OS Login user role. | list | `<list>` | no |
51-
| owners | Optional list of IAM-format members to set as project owners. | list | `<list>` | no |
52-
| 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 |
53-
| prefix | Prefix used to generate project id and name | string | n/a | yes |
54-
| viewers | Optional list of IAM-format members to set as project viewers. | list | `<list>` | no |
48+
| oslogin | Enable oslogin. | bool | `"false"` | no |
49+
| oslogin\_admins | List of IAM-format members that will get OS Login admin role. | list(string) | `<list>` | no |
50+
| oslogin\_users | List of IAM-format members that will get OS Login user role. | list(string) | `<list>` | no |
51+
| owners | Optional list of IAM-format members to set as project owners. | list(string) | `<list>` | no |
52+
| 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 |
53+
| prefix | Prefix used to generate project id and name. | string | n/a | yes |
54+
| viewers | Optional list of IAM-format members to set as project viewers. | list(string) | `<list>` | no |
5555

5656
## Outputs
5757

@@ -61,6 +61,7 @@ module "project_myproject" {
6161
| custom\_roles | Ids of the created custom roles. |
6262
| gce\_service\_account | Default GCE service account (depends on services). |
6363
| gke\_service\_account | Default GKE service account (depends on services). |
64+
| name | Name (depends on services). |
6465
| number | Project number (depends on services). |
6566
| project\_id | Project id (depends on services). |
6667

modules/fabric-project/main.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ resource "google_project" "project" {
3737
labels = var.labels
3838
}
3939

40-
module "project_services" {
41-
source = "../project_services"
42-
43-
project_id = google_project.project.project_id
44-
activate_apis = var.activate_apis
40+
resource "google_project_service" "project_services" {
41+
for_each = toset(var.activate_apis)
42+
project = google_project.project.project_id
43+
service = each.value
44+
disable_on_destroy = true
45+
disable_dependent_services = true
4546
}
4647

4748
# this will fail for external users, who need to be manually added so they
@@ -74,7 +75,7 @@ resource "google_compute_project_metadata_item" "oslogin_meta" {
7475
value = "TRUE"
7576

7677
# depend on services or it will fail on destroy
77-
depends_on = [module.project_services]
78+
depends_on = [google_project_service.project_services]
7879
}
7980

8081
resource "google_project_iam_member" "oslogin_admins" {

modules/fabric-project/outputs.tf

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,37 @@
1717
output "project_id" {
1818
description = "Project id (depends on services)."
1919
value = google_project.project.project_id
20-
depends_on = [google_project_services.services]
20+
depends_on = [google_project_service.project_services]
21+
}
22+
23+
output "name" {
24+
description = "Name (depends on services)."
25+
value = google_project.project.name
26+
depends_on = [google_project_service.project_services]
2127
}
2228

2329
output "number" {
2430
description = "Project number (depends on services)."
2531
value = google_project.project.number
26-
depends_on = [google_project_services.services]
32+
depends_on = [google_project_service.project_services]
2733
}
2834

2935
output "cloudsvc_service_account" {
3036
description = "Cloud services service account (depends on services)."
3137
value = "${local.cloudsvc_service_account}"
32-
depends_on = ["google_project_services.services"]
38+
depends_on = [google_project_service.project_services]
3339
}
3440

3541
output "gce_service_account" {
3642
description = "Default GCE service account (depends on services)."
3743
value = local.gce_service_account
38-
depends_on = [google_project_services.services]
44+
depends_on = [google_project_service.project_services]
3945
}
4046

4147
output "gke_service_account" {
4248
description = "Default GKE service account (depends on services)."
4349
value = local.gke_service_account
44-
depends_on = [google_project_services.services]
50+
depends_on = [google_project_service.project_services]
4551
}
4652

4753
output "custom_roles" {

modules/fabric-project/variables.tf

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

1717
variable "parent" {
18-
description = "The resource name of the parent Folder or Organization. Must be of the form folders/folder_id or organizations/org_id"
18+
description = "The resource name of the parent Folder or Organization. Must be of the form folders/folder_id or organizations/org_id."
19+
type = string
1920
}
2021

2122
variable "prefix" {
22-
description = "Prefix used to generate project id and name"
23+
description = "Prefix used to generate project id and name."
24+
type = string
2325
}
2426

2527
variable "name" {
2628
description = "Project name and id suffix."
29+
type = string
2730
}
2831

2932
variable "billing_account" {
3033
description = "Billing account id."
34+
type = string
3135
default = ""
3236
}
3337

3438
variable "activate_apis" {
3539
description = "Service APIs to enable."
40+
type = list(string)
3641
default = []
3742
}
3843

3944
variable "owners" {
4045
description = "Optional list of IAM-format members to set as project owners."
46+
type = list(string)
4147
default = []
4248
}
4349

4450
variable "editors" {
4551
description = "Optional list of IAM-format members to set as project editor."
52+
type = list(string)
4653
default = []
4754
}
4855

4956
variable "viewers" {
5057
description = "Optional list of IAM-format members to set as project viewers."
58+
type = list(string)
5159
default = []
5260
}
5361

5462
variable "lien_reason" {
5563
description = "If non-empty, creates a project lien with this description."
64+
type = string
5665
default = ""
5766
}
5867

5968
variable "oslogin" {
6069
description = "Enable oslogin."
70+
type = bool
6171
default = false
6272
}
6373

6474
variable "oslogin_admins" {
6575
description = "List of IAM-format members that will get OS Login admin role."
76+
type = list(string)
6677
default = []
6778
}
6879

6980
variable "oslogin_users" {
7081
description = "List of IAM-format members that will get OS Login user role."
82+
type = list(string)
7183
default = []
7284
}
7385

@@ -76,31 +88,37 @@ variable "oslogin_users" {
7688

7789
variable "extra_bindings_roles" {
7890
description = "List of roles for additional IAM bindings, pair with members list below."
91+
type = list(string)
7992
default = []
8093
}
8194

8295
variable "extra_bindings_members" {
8396
description = "List of comma-delimited IAM-format members for additional IAM bindings, one item per role."
97+
type = list(string)
8498
default = []
8599
}
86100

87101
variable "auto_create_network" {
88102
description = "Whether to create the default network for the project"
103+
type = bool
89104
default = false
90105
}
91106

92107
variable "custom_roles" {
93108
description = "Map of role name => comma-delimited list of permissions to create in this project."
109+
type = map(string)
94110
default = {}
95111
}
96112

97113
variable "gce_service_account_roles" {
98114
description = "List of project id=>role to assign to the default GCE service account."
115+
type = list(string)
99116
default = []
100117
}
101118

102119
variable "labels" {
103120
description = "Resource labels."
121+
type = map(string)
104122
default = {}
105123
}
106124

0 commit comments

Comments
 (0)