The purpose of this step is to set up a folder structure, projects, and infrastructure and application pipelines, which are connected as service projects to deploy an example application called Bank of Anthos.
- 0-bootstrap executed successfully.
- 1-org executed successfully.
- 2-environments executed successfully.
- 3-networks executed successfully.
Update the terraform-validator policies repo to allow the new APIs used GKE and Anthos.
- Change directory to outside of
terraform-example-foundation-app
and go to the gcp-policies repo cloned in step 1-org.cd .. ls # should see terraform-example-foundation-app and gcp-policies cd gcp-policies
- Add the new allowed APIs to the end of the services list in the constraint
policies/constraints/serviceusage_allow_basic_apis.yaml
:- "anthos.googleapis.com" - "binaryauthorization.googleapis.com" - "containerscanning.googleapis.com" - "gkeconnect.googleapis.com" - "gkehub.googleapis.com" - "iap.googleapis.com" - "meshca.googleapis.com" - "meshconfig.googleapis.com" - "meshtelemetry.googleapis.com" - "multiclusteringress.googleapis.com" - "privateca.googleapis.com" - "sqladmin.googleapis.com" - "stackdriver.googleapis.com" - "storage.googleapis.com"
- Commit changes.
git add . git commit -m 'Add new APIS to allowed list'
- Push your changes.
git push origin master
- Change directory to outside
gcp-policies
usingcd ..
, to confirm you runls
and you should seeterraform-example-foundation-app
listed - Clone repo
gcloud source repos clone gcp-projects --project=YOUR_CLOUD_BUILD_PROJECT_ID
. - Change into freshly cloned repo
cd gcp-projects
and change to non master branchgit checkout -b plan
(the branchplan
is not a special one. Any branch which name is different fromdevelopment
,non-production
orproduction
will trigger a terraform plan). - Copy example foundation to new repo
cp -RT ../terraform-example-foundation-app/foundation-extension/4-projects/ .
(modify accordingly based on your current directory). - Copy cloud build configuration files for terraform
cp ../terraform-example-foundation-app/build/cloudbuild-tf-* .
(modify accordingly based on your current directory). - Copy terraform wrapper script
cp ../terraform-example-foundation-app/build/tf-wrapper.sh .
to the root of your new repository (modify accordingly based on your current directory). - Ensure wrapper script can be executed
chmod 755 ./tf-wrapper.sh
.
- You will need to only once manually plan + apply the
shared
pipeline environments sincedevelopment
,non-production
andproduction
will depend on it. - Change into
business_unit_1/shared
folder. - Run
cp ../../tf-wrapper.sh .
- Run
chmod 755 tf-wrapper.sh
. - Rename
shared.auto.example.tfvars
toshared.auto.tfvars
and update the file with values from your environment and bootstrap. - Update backend.tf with your bucket from example-foundation. You can run
cd .. && for i in `find -name 'backend.tf'`; do sed -i 's/UPDATE_ME/<YOUR-BUCKET-NAME>/' $i; done && cd shared
. - Run
terraform init
- Run
terraform plan
- Run
terraform apply
ensure you have the correct permissions before doing this.
- Go back to root folder
cd ../..
- Rename
mv business_unit_1/development/development.auto.example.tfvars business_unit_1/development/development.auto.tfvars
and update the file with values from your environment and outputs from 4-projects/shared. - Rename
mv business_unit_1/non-production/non-production.auto.example.tfvars business_unit_1/non-production/non-production.auto.tfvars
and update the file with values from your environment and outputs from 4-projects/shared. - Rename
mv business_unit_1/production/production.auto.example.tfvars business_unit_1/production/production.auto.tfvars
and update the file with values from your environment and outputs from 4-projects/shared. - Commit changes with
git add .
andgit commit -m 'Your message'
. - Push your plan branch to trigger a plan
git push --set-upstream origin plan
(the branchplan
is not a special one. Any branch which name is different fromdevelopment
,non-production
orproduction
will trigger a terraform plan).- Review the plan output in your cloud build project https://console.cloud.google.com/cloud-build/builds?project=prj-b-cicd-xxxx
- Merge changes to development with
git checkout -b development
andgit push origin development
.- Review the apply output in your cloud build project https://console.cloud.google.com/cloud-build/builds?project=prj-b-cicd-xxxx
- Merge changes to non-production with
git checkout -b non-production
andgit push origin non-production
.- Review the apply output in your cloud build project. https://console.cloud.google.com/cloud-build/builds?project=prj-b-cicd-xxxx
- Merge changes to production with
git checkout -b production
andgit push origin production
.- Review the apply output in your cloud build project. https://console.cloud.google.com/cloud-build/builds?project=prj-b-cicd-xxxx
Troubleshooting:
If your user does not have access to run the terraform modules locally and you are in the organization admins group, you can append --impersonate-service-account=org-terraform@prj-b-cicd-xxxx.iam.gserviceaccount.com
to run terraform modules as the service account.
To use the validate
option of the tf-wrapper.sh
script, please follow the instructions in the Install Terraform Validator section and install version 2021-03-22
in your system. You will also need to rename the binary from terraform-validator-<your-platform>
to terraform-validator
and the terraform-validator
binary must be in your PATH
.
- Run
./tf-wrapper.sh init production
. - Run
./tf-wrapper.sh plan production
and review output. - Run
./tf-wrapper.sh validate production $(pwd)/../policy-library <YOUR_INFRA_PIPELINE_PROJECT>
and check for violations. - Run
./tf-wrapper.sh apply production
. - Run
./tf-wrapper.sh init non-production
. - Run
./tf-wrapper.sh plan non-production
and review output. - Run
./tf-wrapper.sh plan non-production
and review output. - Run
./tf-wrapper.sh validate non-production $(pwd)/../policy-library <YOUR_INFRA_PIPELINE_PROJECT>
and check for violations. - Run
./tf-wrapper.sh apply non-production
. - Run
./tf-wrapper.sh init development
. - Run
./tf-wrapper.sh plan development
and review output. - Run
./tf-wrapper.sh validate development $(pwd)/../policy-library <YOUR_INFRA_PIPELINE_PROJECT>
and check for violations. - Run
./tf-wrapper.sh apply development
.
If you received any errors or made any changes to the Terraform config or terraform.tfvars
you must re-run ./tf-wrapper.sh plan <env>
before run ./tf-wrapper.sh apply <env>
.