|
| 1 | +# Service |
| 2 | + |
| 3 | +This root module provisions the resources required for the service. |
| 4 | + |
| 5 | +## Environments |
| 6 | + |
| 7 | +There are multiple environments that replicate the resources which are represented as Terraform workspaces: |
| 8 | + |
| 9 | +* `dev` |
| 10 | +* `test` |
| 11 | +* `prod` |
| 12 | + |
| 13 | +Set the target environment, for example: |
| 14 | + |
| 15 | +```bash |
| 16 | +export ENVIRONMENT=dev |
| 17 | +``` |
| 18 | + |
| 19 | +## Provisioning |
| 20 | + |
| 21 | +1. Change directory: |
| 22 | + |
| 23 | + ```bash |
| 24 | + cd cloud/plan/service |
| 25 | + ``` |
| 26 | + |
| 27 | +1. Authenticate with Google Cloud: |
| 28 | + |
| 29 | + ```bash |
| 30 | + gcloud auth application-default login |
| 31 | + ``` |
| 32 | + |
| 33 | +1. Initialise Terraform: |
| 34 | + |
| 35 | + ```bash |
| 36 | + terraform init |
| 37 | + ``` |
| 38 | + |
| 39 | +1. Create a Terraform workspace for the environment: |
| 40 | + |
| 41 | + ```bash |
| 42 | + terraform workspace new ${ENVIRONMENT} |
| 43 | + ``` |
| 44 | + |
| 45 | +1. Apply the changes: |
| 46 | + |
| 47 | + ```bash |
| 48 | + terraform apply |
| 49 | + ``` |
| 50 | +## Configuring GitHub Actions |
| 51 | + |
| 52 | +For the Dev environment only, configure the [CI workflow](../../.github/workflows/ci.yml) with credentials to deploy |
| 53 | +images to the service: |
| 54 | + |
| 55 | +1. Obtain the Cloud Run service account private key: |
| 56 | + |
| 57 | + ```bash |
| 58 | + terraform output -raw github_action_deploy_private_key |
| 59 | + ``` |
| 60 | + |
| 61 | +1. [Set the GitHub Actions environment secret](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-an-environment) `GCP_CREDENTIALS_DEPLOY` to the private key |
| 62 | + |
| 63 | + |
| 64 | +## Destroying |
| 65 | + |
| 66 | +1. Change directory: |
| 67 | + |
| 68 | + ```bash |
| 69 | + cd cloud/plan/service |
| 70 | + ``` |
| 71 | + |
| 72 | +1. Authenticate with Google Cloud: |
| 73 | + |
| 74 | + ```bash |
| 75 | + gcloud auth application-default login |
| 76 | + ``` |
| 77 | + |
| 78 | +1. Select the Terraform workspace for the environment: |
| 79 | + |
| 80 | + ```bash |
| 81 | + terraform workspace select ${ENVIRONMENT} |
| 82 | + ``` |
| 83 | +
|
| 84 | +1. Disable deletion protection for the service by modifying `cloud/plan/service/application/main.tf`: |
| 85 | +
|
| 86 | + ```diff |
| 87 | + resource "google_cloud_run_v2_service" "plan" { |
| 88 | + + deletion_protection = false |
| 89 | + ... |
| 90 | + } |
| 91 | + ``` |
| 92 | +
|
| 93 | +1. Apply the change: |
| 94 | +
|
| 95 | + ```bash |
| 96 | + terraform apply |
| 97 | + ``` |
| 98 | +
|
| 99 | +1. Revert the modification: |
| 100 | +
|
| 101 | + ```bash |
| 102 | + git checkout application/main.tf |
| 103 | + ``` |
| 104 | + |
| 105 | +1. Delete the resources: |
| 106 | +
|
| 107 | + ```bash |
| 108 | + terraform destroy |
| 109 | + ``` |
0 commit comments