Skip to content

Commit 06084be

Browse files
romanini-ciandtgtsorbodaniel-cit
authored
feat: create subfolders for business units in 4-projects step (#1039)
Co-authored-by: Grant Sorbo <[email protected]> Co-authored-by: Daniel Andrade <[email protected]>
1 parent 25c61c4 commit 06084be

File tree

11 files changed

+113
-71
lines changed

11 files changed

+113
-71
lines changed

0-bootstrap/sa.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ locals {
8484
"roles/dns.admin",
8585
],
8686
"proj" = [
87-
"roles/resourcemanager.folderViewer",
88-
"roles/resourcemanager.folderIamAdmin",
87+
"roles/resourcemanager.folderAdmin",
8988
"roles/artifactregistry.admin",
9089
"roles/compute.networkAdmin",
9190
"roles/compute.xpnAdmin",

4-projects/modules/base_env/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| business\_unit | The business (ex. business\_unit\_1). | `string` | n/a | yes |
88
| env | The environment to prepare (ex. development). | `string` | n/a | yes |
99
| firewall\_enable\_logging | Toggle firewall logging for VPC Firewalls. | `bool` | `true` | no |
10+
| folder\_prefix | Name prefix to use for folders created. Should be the same in all steps. | `string` | `"fldr"` | no |
1011
| gcs\_bucket\_prefix | Name prefix to be used for GCS Bucket | `string` | `"bkt"` | no |
1112
| key\_name | Name to be used for KMS Key | `string` | `"crypto-key-example"` | no |
1213
| key\_rotation\_period | Rotation period in seconds to be used for KMS Key | `string` | `"7776000s"` | no |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright 2023 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+
env_business_unit_folder_name = "${var.folder_prefix}-${var.env}-${var.business_code}"
19+
}
20+
21+
resource "google_folder" "env_business_unit" {
22+
display_name = local.env_business_unit_folder_name
23+
parent = local.env_folder_name
24+
}

4-projects/modules/base_env/example_base_shared_vpc_project.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module "base_shared_vpc_project" {
1919

2020
org_id = local.org_id
2121
billing_account = local.billing_account
22-
folder_id = local.env_folder_name
22+
folder_id = google_folder.env_business_unit.name
2323
environment = var.env
2424
vpc_type = "base"
2525
shared_vpc_host_project_id = local.base_host_project_id

4-projects/modules/base_env/example_floating_project.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module "floating_project" {
1919

2020
org_id = local.org_id
2121
billing_account = local.billing_account
22-
folder_id = local.env_folder_name
22+
folder_id = google_folder.env_business_unit.name
2323
environment = var.env
2424
project_budget = var.project_budget
2525
project_prefix = local.project_prefix

4-projects/modules/base_env/example_peering_project.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module "peering_project" {
3535

3636
org_id = local.org_id
3737
billing_account = local.billing_account
38-
folder_id = local.env_folder_name
38+
folder_id = google_folder.env_business_unit.name
3939
environment = var.env
4040
project_budget = var.project_budget
4141
project_prefix = local.project_prefix

4-projects/modules/base_env/example_restricted_shared_vpc_project.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module "restricted_shared_vpc_project" {
1919

2020
org_id = local.org_id
2121
billing_account = local.billing_account
22-
folder_id = local.env_folder_name
22+
folder_id = google_folder.env_business_unit.name
2323
environment = var.env
2424
vpc_type = "restricted"
2525
shared_vpc_host_project_id = local.restricted_host_project_id

4-projects/modules/base_env/example_storage_cmek.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module "env_secrets_project" {
1919

2020
org_id = local.org_id
2121
billing_account = local.billing_account
22-
folder_id = local.env_folder_name
22+
folder_id = google_folder.env_business_unit.name
2323
environment = var.env
2424
project_budget = var.project_budget
2525
project_suffix = var.secrets_prj_suffix

4-projects/modules/base_env/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,9 @@ variable "subnet_ip_range" {
152152
type = string
153153
default = null
154154
}
155+
156+
variable "folder_prefix" {
157+
description = "Name prefix to use for folders created. Should be the same in all steps."
158+
type = string
159+
default = "fldr"
160+
}

4-projects/modules/single_project/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module "project" {
5151
random_project_id = true
5252
random_project_id_length = 4
5353
activate_apis = distinct(concat(var.activate_apis, ["billingbudgets.googleapis.com"]))
54-
name = "${var.project_prefix}-${var.business_code}-${local.env_code}-${var.project_suffix}"
54+
name = "${var.project_prefix}-${local.env_code}-${var.business_code}${var.project_suffix}"
5555
org_id = var.org_id
5656
billing_account = var.billing_account
5757
folder_id = var.folder_id

0 commit comments

Comments
 (0)