Skip to content

Latest commit

 

History

History
44 lines (39 loc) · 4.64 KB

File metadata and controls

44 lines (39 loc) · 4.64 KB

4-projects

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.

Prerequisites

  1. 0-bootstrap executed successfully.
  2. 1-org executed successfully.
  3. 2-environments executed successfully.
  4. 3-networks executed successfully.

Troubleshooting: If your user does not have access to run the commands above and you are in the organization admins group, you can append --impersonate-service-account=org-terraform@<SEED_PROJECT_ID>.iam.gserviceaccount.com to run the command as the terraform service account.

Usage

Setup to run via Cloud Build

  1. Clone repo gcloud source repos clone gcp-projects --project=YOUR_CLOUD_BUILD_PROJECT_ID.
  2. Change freshly cloned repo and change to non master branch git checkout -b 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).
  3. Copy example foundation to new repo cp -R ../terraform-example-foundation/4-projects/ . (modify accordingly based on your current directory).
  4. Find and remove the example projects find ../terraform-example-foundation/4-projects/ -type f -name example_*project.tf -exec ls {} \; and change the ls to rm to remove the example project files.
  5. Copy Bank of Anthos and pipeline projects to new repo cp -R ../terraform-example-foundation-app/4-projects/ . (modify accordingly based on your current directory).
  6. Copy cloud build configuration files for terraform cp ../terraform-example-foundation/build/cloudbuild-tf-* . (modify accordingly based on your current directory).
  7. Copy terraform wrapper script cp ../terraform-example-foundation/build/tf-wrapper.sh . to the root of your new repository (modify accordingly based on your current directory).
  8. Ensure wrapper script can be executed chmod 755 ./tf-wrapper.sh.
  9. Rename common.auto.example.tfvars to common.auto.tfvars and update the file with values from your environment and bootstrap.
  10. Rename development.auto.example.tfvars to development.auto.tfvars and update the file with the perimeter_name that starts with sp_d_shared_restricted.
  11. 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.
  12. Rename production.auto.example.tfvars to production.auto.tfvars and update the file with the perimeter_name that starts with sp_p_shared_restricted.
  13. Commit changes with git add . and git commit -m 'Your message'.
  14. You will need only once to manually plan + apply the shared pipeline environments since development, non-production and production will depend on it.
    1. cd to ./shared
    2. Update backend.tf with your bucket name from the bootstrap step.
    3. Run terraform init
    4. Run terraform plan and review output
    5. Run terraform apply
    6. If you would like the bucket to be replaced by cloud build at run time, change the bucket name back to UPDATE_ME
  15. 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).
    1. Review the plan output in your cloud build project https://console.cloud.google.com/cloud-build/builds?project=YOUR_CLOUD_BUILD_PROJECT_ID
  16. Merge changes to production with git checkout -b production and git push origin production.
    1. Review the apply output in your cloud build project. https://console.cloud.google.com/cloud-build/builds?project=YOUR_CLOUD_BUILD_PROJECT_ID
  17. Merge changes to development with git checkout -b development and git push origin development.
    1. Review the apply output in your cloud build project https://console.cloud.google.com/cloud-build/builds?project=YOUR_CLOUD_BUILD_PROJECT_ID
  18. Merge changes to non-production with git checkout -b non-production and git push origin non-production.
    1. Review the apply output in your cloud build project. https://console.cloud.google.com/cloud-build/builds?project=YOUR_CLOUD_BUILD_PROJECT_ID