Skip to content

Commit f5f5224

Browse files
renato-rudnickibharathkkb
authored andcommitted
fix: Bugfix/fix 4-projects issues (terraform-google-modules#374)
* Fix issue 350 - common.auto.tfvars link pointing to an example file * Fix issue 351 - Missing backend.tf file and provider.tf from shared folder * Adding versions.tf * Adding versions.tf for BU 1 and 2 * Fixing access_context * Adding extra steps for Business Unit 1 and 2 * Updating Readme.md and adding business_unit example files * Adding simbolic links for business_unit 1 and 2 * Increasing providers.tf from 900s to 1200s * Updating lifetime to 1200ms in shared/providers.tf
1 parent 1fda12b commit f5f5224

31 files changed

+279
-10
lines changed

4-projects/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ If your user does not have access to run the commands above and you are in the o
2626
1. Rename `development.auto.example.tfvars` to `development.auto.tfvars` and update the file with the `perimeter_name` that starts with `sp_d_shared_restricted`.
2727
1. Rename `non-production.auto.example.tfvars` to `non-production.auto.tfvars` and update the file with the `perimeter_name` that starts with `sp_n_shared_restricted`.
2828
1. Rename `production.auto.example.tfvars` to `production.auto.tfvars` and update the file with the `perimeter_name` that starts with `sp_p_shared_restricted`.
29+
1. Rename `access_context.auto.example.tfvars` to `access_context.auto.tfvars` and update the file with the `access_context_manager_policy_id`.
30+
1. You will need only once to manually plan + apply the `business_unit_1/shared` environment since `development`, `non-production` and `production` depend on it.
31+
1. Run `cd ./business_unit_1/shared/`.
32+
1. Update `backend.tf` with your bucket name from the bootstrap step.
33+
1. Run `terraform init`.
34+
1. Run `terraform plan` and review output.
35+
1. Run `terraform apply`.
36+
1. Run `terraform output cloudbuild_sa` to get the cloudbuild service account from the apply step.
37+
1. If you would like the bucket to be replaced by cloud build at run time, change the bucket name back to `UPDATE_ME`
38+
1. Once you have done the instructions for the `business_unit_1`, you need to repeat same steps for `business_unit_2` folder.
39+
1. Rename `business_unit_1.auto.example.tfvars` to `business_unit_1.auto.tfvars` and update the file with the `app_infra_pipeline_cloudbuild_sa` wich is the output of `cloudbuild_sa` from `business_unit_1` shared steps.
40+
1. Rename `business_unit_2.auto.example.tfvars` to `business_unit_2.auto.tfvars` and update the file with the `app_infra_pipeline_cloudbuild_sa` wich is the output of `cloudbuild_sa` from `business_unit_2` shared steps.
2941
1. Commit changes with `git add .` and `git commit -m 'Your message'`.
3042
1. Push your plan branch to trigger a plan `git push --set-upstream origin plan` (the branch `plan` is not a special one. Any branch which name is different from `development`, `non-production` or `production` will trigger a terraform plan).
3143
1. Review the plan output in your cloud build project https://console.cloud.google.com/cloud-build/builds?project=YOUR_CLOUD_BUILD_PROJECT_ID
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2021 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+
access_context_manager_policy_id = 000000000000
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2021 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+
app_infra_pipeline_cloudbuild_sa = "project-service-account@prj-bu1-s-sample-infra-<random>.iam.gserviceaccount.com"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../access_context.auto.tfvars
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../business_unit_1.auto.tfvars

4-projects/business_unit_1/development/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data "google_service_account_access_token" "default" {
3131
provider = google.impersonate
3232
target_service_account = local.tf_sa
3333
scopes = ["userinfo-email", "cloud-platform"]
34-
lifetime = "900s"
34+
lifetime = "1200s"
3535
}
3636

3737
/******************************************
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../access_context.auto.tfvars
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../business_unit_1.auto.tfvars

4-projects/business_unit_1/non-production/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data "google_service_account_access_token" "default" {
3131
provider = google.impersonate
3232
target_service_account = local.tf_sa
3333
scopes = ["userinfo-email", "cloud-platform"]
34-
lifetime = "900s"
34+
lifetime = "1200s"
3535
}
3636

3737
/******************************************
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../access_context.auto.tfvars
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../business_unit_1.auto.tfvars

4-projects/business_unit_1/production/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data "google_service_account_access_token" "default" {
3131
provider = google.impersonate
3232
target_service_account = local.tf_sa
3333
scopes = ["userinfo-email", "cloud-platform"]
34-
lifetime = "900s"
34+
lifetime = "1200s"
3535
}
3636

3737
/******************************************
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2021 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+
backend "gcs" {
19+
bucket = "UPDATE_ME"
20+
prefix = "terraform/projects/business_unit_1/shared"
21+
}
22+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../common.auto.example.tfvars
1+
../../common.auto.tfvars
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright 2021 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+
tf_sa = var.terraform_service_account
19+
}
20+
21+
provider "google" {
22+
alias = "impersonate"
23+
24+
scopes = [
25+
"https://www.googleapis.com/auth/cloud-platform",
26+
"https://www.googleapis.com/auth/userinfo.email",
27+
]
28+
}
29+
30+
data "google_service_account_access_token" "default" {
31+
provider = google.impersonate
32+
target_service_account = local.tf_sa
33+
scopes = ["userinfo-email", "cloud-platform"]
34+
lifetime = "1200s"
35+
}
36+
37+
/******************************************
38+
Provider credential configuration
39+
*****************************************/
40+
provider "google" {
41+
access_token = data.google_service_account_access_token.default.access_token
42+
}
43+
44+
provider "google-beta" {
45+
access_token = data.google_service_account_access_token.default.access_token
46+
}
47+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright 2021 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.13"
19+
required_providers {
20+
google = {
21+
source = "hashicorp/google"
22+
version = ">= 3.50"
23+
}
24+
google-beta = {
25+
source = "hashicorp/google-beta"
26+
version = ">= 3.50"
27+
}
28+
}
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2021 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+
app_infra_pipeline_cloudbuild_sa = "project-service-account@prj-bu2-s-sample-infra-<random>.iam.gserviceaccount.com"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../access_context.auto.tfvars
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../business_unit_2.auto.tfvars

4-projects/business_unit_2/development/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data "google_service_account_access_token" "default" {
3131
provider = google.impersonate
3232
target_service_account = local.tf_sa
3333
scopes = ["userinfo-email", "cloud-platform"]
34-
lifetime = "900s"
34+
lifetime = "1200s"
3535
}
3636

3737
/******************************************
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../access_context.auto.tfvars
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../business_unit_2.auto.tfvars

4-projects/business_unit_2/non-production/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data "google_service_account_access_token" "default" {
3131
provider = google.impersonate
3232
target_service_account = local.tf_sa
3333
scopes = ["userinfo-email", "cloud-platform"]
34-
lifetime = "900s"
34+
lifetime = "1200s"
3535
}
3636

3737
/******************************************
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../access_context.auto.tfvars
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../business_unit_2.auto.tfvars

4-projects/business_unit_2/production/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data "google_service_account_access_token" "default" {
3131
provider = google.impersonate
3232
target_service_account = local.tf_sa
3333
scopes = ["userinfo-email", "cloud-platform"]
34-
lifetime = "900s"
34+
lifetime = "1200s"
3535
}
3636

3737
/******************************************
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2021 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+
backend "gcs" {
19+
bucket = "UPDATE_ME"
20+
prefix = "terraform/projects/business_unit_2/shared"
21+
}
22+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../common.auto.example.tfvars
1+
../../common.auto.tfvars
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright 2021 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+
tf_sa = var.terraform_service_account
19+
}
20+
21+
provider "google" {
22+
alias = "impersonate"
23+
24+
scopes = [
25+
"https://www.googleapis.com/auth/cloud-platform",
26+
"https://www.googleapis.com/auth/userinfo.email",
27+
]
28+
}
29+
30+
data "google_service_account_access_token" "default" {
31+
provider = google.impersonate
32+
target_service_account = local.tf_sa
33+
scopes = ["userinfo-email", "cloud-platform"]
34+
lifetime = "1200s"
35+
}
36+
37+
/******************************************
38+
Provider credential configuration
39+
*****************************************/
40+
provider "google" {
41+
access_token = data.google_service_account_access_token.default.access_token
42+
}
43+
44+
provider "google-beta" {
45+
access_token = data.google_service_account_access_token.default.access_token
46+
}
47+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright 2021 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.13"
19+
required_providers {
20+
google = {
21+
source = "hashicorp/google"
22+
version = ">= 3.50"
23+
}
24+
google-beta = {
25+
source = "hashicorp/google-beta"
26+
version = ">= 3.50"
27+
}
28+
}
29+
}

4-projects/common.auto.example.tfvars

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,5 @@ org_id = "000000000000"
2020

2121
terraform_service_account = "[email protected]"
2222

23-
access_context_manager_policy_id = "000000000000"
24-
2523
//Optional - for development. Will place all resources under a specific folder instead of org root
2624
//parent_folder = "01234567890"

0 commit comments

Comments
 (0)