Skip to content

Commit

Permalink
refactor: use long name for environments (terraform-google-modules#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjerrems authored Aug 5, 2020
1 parent 8902b07 commit 28de531
Show file tree
Hide file tree
Showing 154 changed files with 465 additions and 463 deletions.
6 changes: 3 additions & 3 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ suites:
- name: inspec-gcp
backend: gcp
controls:
- dev
- nonprod
- prod
- development
- non-production
- production
- name: dns_hub
driver:
root_module_directory: test/fixtures/dns_hub/
Expand Down
6 changes: 3 additions & 3 deletions 0-bootstrap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ module "cloudbuild_bootstrap" {
]

terraform_apply_branches = [
"dev",
"nonprod",
"prod"
"development",
"non-production",
"production"
]
}

Expand Down
22 changes: 11 additions & 11 deletions 1-org/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ You can choose not to enable the Data Access logs by setting variable `data_acce

### Setup to run via Cloud Build
1. Clone repo `gcloud source repos clone gcp-org --project=YOUR_CLOUD_BUILD_PROJECT_ID` (this is from terraform output from the previous section, 0-bootstrap).
1. Navigate into the repo `cd gcp-org` and change to a non prod branch `git checkout -b plan`
1. Navigate into the repo `cd gcp-org` and change to a non production branch `git checkout -b plan`
1. Copy contents of foundation to new repo `cp -RT ../terraform-example-foundation/1-org/ .` (modify accordingly based on your current directory).
1. Copy cloud build configuration files for terraform `cp ../terraform-example-foundation/build/cloudbuild-tf-* . ` (modify accordingly based on your current directory).
1. Copy terraform wrapper script `cp ../terraform-example-foundation/build/tf-wrapper.sh . `1. 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). to the root of your new repository (modify accordingly based on your current directory).
1. Ensure wrapper script can be executed `chmod 755 ./tf-wrapper.sh`.
1. Rename `terraform.example.tfvars` to `terraform.tfvars` and update the file with values from your environment and bootstrap (you can re-run `terraform output` in the 0-bootstrap directory to find these values). Make sure that `default_region` is set to a valid [BigQuery dataset region](https://cloud.google.com/bigquery/docs/locations).
1. Commit changes with `git add .` and `git commit -m 'Your message'`
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 `dev`, `nonprod` or `prod` will trigger a terraform plan).
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).
1. Review the plan output in your cloud build project https://console.cloud.google.com/cloud-build/builds?project=YOUR_CLOUD_BUILD_PROJECT_ID
1. Merge changes to prod branch with `git checkout -b prod` and `git push origin prod`
1. Merge changes to production branch 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

### Setup to run via Jenkins
1. Clone the repo you created manually in bootstrap: `git clone <YOUR_NEW_REPO-1-org>`
1. Navigate into the repo `cd YOUR_NEW_REPO_CLONE-1-org` and change to a non prod branch `git checkout -b plan`
1. Navigate into the repo `cd YOUR_NEW_REPO_CLONE-1-org` and change to a non production branch `git checkout -b plan`
1. Copy contents of foundation to new repo `cp -RT ../terraform-example-foundation/1-org/ .` (modify accordingly based on your current directory).
1. Copy the Jenkinsfile script `cp ../terraform-example-foundation/build/Jenkinsfile .` to the root of your new repository (modify accordingly based on your current directory).
1. Update the variables located in the `environment {}` section of the `Jenkinsfile` with values from your environment:
Expand All @@ -44,10 +44,10 @@ You can choose not to enable the Data Access logs by setting variable `data_acce
1. Ensure wrapper script can be executed `chmod 755 ./tf-wrapper.sh`.
1. Rename `terraform.example.tfvars` to `terraform.tfvars` and update the file with values from your environment and bootstrap (you can re-run `terraform output` in the 0-bootstrap directory to find these values). Make sure that `default_region` is set to a valid [BigQuery dataset region](https://cloud.google.com/bigquery/docs/locations).
1. Commit changes with `git add .` and `git commit -m 'Your message'`
1. Push your plan branch `git push --set-upstream origin plan`. The branch `plan` is not a special one. Any branch which name is different from `dev`, `nonprod` or `prod` will trigger a terraform plan.
1. Push your plan branch `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.
- Assuming you configured an automatic trigger in your Jenkins Master (see [Jenkins sub-module README](../0-bootstrap/modules/jenkins-agent)), this will trigger a plan. You can also trigger a Jenkins job manually. Given the many options to do this in Jenkins, it is out of the scope of this document see [Jenkins website](http://www.jenkins.io) for more details.
1. Review the plan output in your Master's web UI.
1. Merge changes to prod branch with `git checkout -b prod` and `git push origin prod`
1. Merge changes to production branch with `git checkout -b production` and `git push origin production`
1. Review the apply output in your Master's web UI (You might want to use the option to "Scan Multibranch Pipeline Now" in your Jenkins Master UI).
1. You can now move to the instructions in the step [2-environments](../2-environments/README.md).
Expand All @@ -62,11 +62,11 @@ You can choose not to enable the Data Access logs by setting variable `data_acce
```for i in `find -name 'backend.tf'`; do sed -i 's/UPDATE_ME/<YOUR-BUCKET-NAME>/' $i; done```.
You can run `terraform output gcs_bucket_tfstate` in the 0-bootstap folder to obtain the bucket name.
We will now deploy our environment (prod) using this script.
We will now deploy our environment (production) using this script.
When using Cloud Build or Jenkins as your CI/CD tool each environment corresponds to a branch is the repository for 1-org step and only the corresponding environment is applied.
1. Run `./tf-wrapper.sh init prod`
1. Run `./tf-wrapper.sh plan prod` and review output.
1. Run `./tf-wrapper.sh apply prod`
1. Run `./tf-wrapper.sh init production`
1. Run `./tf-wrapper.sh plan production` and review output.
1. Run `./tf-wrapper.sh apply production`
If you received any errors or made any changes to the Terraform config or `terraform.tfvars` you must re-run `./tf-wrapper.sh plan prod` before run `./tf-wrapper.sh apply prod`
If you received any errors or made any changes to the Terraform config or `terraform.tfvars` you must re-run `./tf-wrapper.sh plan production` before run `./tf-wrapper.sh apply production`
2 changes: 1 addition & 1 deletion 1-org/envs/shared/folders.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ locals {
*****************************************/

resource "google_folder" "common" {
display_name = "common"
display_name = "fldr-common"
parent = local.parent
}
12 changes: 6 additions & 6 deletions 1-org/envs/shared/projects.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module "org_audit_logs" {
activate_apis = ["logging.googleapis.com", "bigquery.googleapis.com", "billingbudgets.googleapis.com"]

labels = {
environment = "prod"
environment = "production"
application_name = "org-logging"
billing_code = "1234"
primary_contact = "example1"
Expand All @@ -59,7 +59,7 @@ module "org_billing_logs" {
activate_apis = ["logging.googleapis.com", "bigquery.googleapis.com", "billingbudgets.googleapis.com"]

labels = {
environment = "prod"
environment = "production"
application_name = "org-billing-logs"
billing_code = "1234"
primary_contact = "example1"
Expand Down Expand Up @@ -90,7 +90,7 @@ module "org_secrets" {
activate_apis = ["logging.googleapis.com", "secretmanager.googleapis.com", "billingbudgets.googleapis.com"]

labels = {
environment = "prod"
environment = "production"
application_name = "org-secrets"
billing_code = "1234"
primary_contact = "example1"
Expand Down Expand Up @@ -121,7 +121,7 @@ module "interconnect" {
activate_apis = ["billingbudgets.googleapis.com", "compute.googleapis.com"]

labels = {
environment = "prod"
environment = "production"
application_name = "org-interconnect"
billing_code = "1234"
primary_contact = "example1"
Expand Down Expand Up @@ -152,7 +152,7 @@ module "scc_notifications" {
skip_gcloud_download = var.skip_gcloud_download

labels = {
environment = "prod"
environment = "production"
application_name = "org-scc"
billing_code = "1234"
primary_contact = "example1"
Expand Down Expand Up @@ -191,7 +191,7 @@ module "dns_hub" {
]

labels = {
environment = "prod"
environment = "production"
application_name = "org-dns-hub"
billing_code = "1234"
primary_contact = "example1"
Expand Down
42 changes: 22 additions & 20 deletions 2-environments/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 2-environments

The purpose of this step is to set up dev, nonprod, and prod environments within the GCP organization.
The purpose of this step is to set updevelopment,non-production, and production environments within the GCP organization.

## Prerequisites

Expand All @@ -20,18 +20,20 @@ The purpose of this step is to set up dev, nonprod, and prod environments within
1. Ensure wrapper script can be executed `chmod 755 ./tf-wrapper.sh`.
1. Rename `terraform.example.tfvars` to `terraform.tfvars` and update the file with values from your environment and bootstrap (you can re-run `terraform output` in the 0-bootstrap directory to find these values).
1. Commit changes with `git add .` and `git commit -m 'Your message'`
1. Push your plan branch to trigger a plan for all environments `git push --set-upstream origin plan` (the branch `plan` is not a special one. Any branch which name is different from `dev`, `nonprod` or `prod` will trigger a terraform plan).

#### If using Cloud Build
1. Push your plan branch to trigger a plan for all environments `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
1. Merge changes to dev with `git checkout -b dev` and `git push origin dev`
1. 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
1. Merge changes to nonprod with `git checkout -b nonprod` and `git push origin nonprod`
1. 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
1. Merge changes to prod branch with `git checkout -b prod` and `git push origin prod`
1. Merge changes to production branch 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

### Setup to run via Jenkins
1. Clone the repo you created manually in bootstrap: `git clone <YOUR_NEW_REPO-2-environments>`
1. Navigate into the repo `cd YOUR_NEW_REPO_CLONE-2-environments` and change to a non prod branch `git checkout -b plan` (the branch `plan` is not a special one. Any branch which name is different from `dev`, `nonprod` or `prod` will trigger a terraform plan).
1. Navigate into the repo `cd YOUR_NEW_REPO_CLONE-2-environments` and change to a non production 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).
1. Copy contents of foundation to new repo `cp -RT ../terraform-example-foundation/2-environments/ .` (modify accordingly based on your current directory).
1. Copy the Jenkinsfile script `cp ../terraform-example-foundation/build/Jenkinsfile .` to the root of your new repository (modify accordingly based on your current directory).
1. Update the variables located in the `environment {}` section of the `Jenkinsfile` with values from your environment:
Expand All @@ -44,14 +46,14 @@ The purpose of this step is to set up dev, nonprod, and prod environments within
1. Ensure wrapper script can be executed `chmod 755 ./tf-wrapper.sh`.
1. Rename `terraform.example.tfvars` to `terraform.tfvars` and update the file with values from your environment and bootstrap (you can re-run `terraform output` in the 0-bootstrap directory to find these values).
1. Commit changes with `git add .` and `git commit -m 'Your message'`
1. Push your plan branch `git push --set-upstream origin plan`. The branch `plan` is not a special one. Any branch which name is different from `dev`, `nonprod` or `prod` will trigger a terraform plan.
1. Push your plan branch `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.
- Assuming you configured an automatic trigger in your Jenkins Master (see [Jenkins sub-module README](../0-bootstrap/modules/jenkins-agent)), this will trigger a plan. You can also trigger a Jenkins job manually. Given the many options to do this in Jenkins, it is out of the scope of this document see [Jenkins website](http://www.jenkins.io) for more details.
1. Review the plan output in your Master's web UI.
1. Merge changes to dev with `git checkout -b dev` and `git push origin dev`
1. Merge changes to development with `git checkout -b development` and `git push origin development`
1. Review the apply output in your Master's web UI (You might want to use the option to "Scan Multibranch Pipeline Now" in your Jenkins Master UI).
1. Merge changes to nonprod with `git checkout -b nonprod` and `git push origin nonprod`
1. Merge changes to non-production with `git checkout -b non-production` and `git push origin non-production`
1. Review the apply output in your Master's web UI (You might want to use the option to "Scan Multibranch Pipeline Now" in your Jenkins Master UI).
1. Merge changes to prod branch with `git checkout -b prod` and `git push origin prod`
1. Merge changes to production branch with `git checkout -b production` and `git push origin production`
1. Review the apply output in your Master's web UI (You might want to use the option to "Scan Multibranch Pipeline Now" in your Jenkins Master UI).
1. You can now move to the instructions in the step [3-networks](../3-networks/README.md).
Expand All @@ -65,17 +67,17 @@ The purpose of this step is to set up dev, nonprod, and prod environments within
```for i in `find -name 'backend.tf'`; do sed -i 's/UPDATE_ME/<YOUR-BUCKET-NAME>/' $i; done```.
You can run `terraform output gcs_bucket_tfstate` in the 0-bootstap folder to obtain the bucket name.
We will now deploy each of our environments(dev/prod/nonprod) using this script.
We will now deploy each of our environments(development/production/non-production) using this script.
When using Cloud Build or Jenkins as your CI/CD tool each environment corresponds to a branch is the repository for 2-environments step and only the corresponding environment is applied.
1. Run `./tf-wrapper.sh init dev`
1. Run `./tf-wrapper.sh plan dev` and review output.
1. Run `./tf-wrapper.sh apply dev`
1. Run `./tf-wrapper.sh init nonprod`
1. Run `./tf-wrapper.sh plan nonprod` and review output.
1. Run `./tf-wrapper.sh apply nonprod`
1. Run `./tf-wrapper.sh init prod`
1. Run `./tf-wrapper.sh plan prod` and review output.
1. Run `./tf-wrapper.sh apply prod`
1. Run `./tf-wrapper.sh init development`
1. Run `./tf-wrapper.sh plan development` and review output.
1. Run `./tf-wrapper.sh apply development`
1. Run `./tf-wrapper.sh init non-production`
1. Run `./tf-wrapper.sh plan non-production` and review output.
1. Run `./tf-wrapper.sh apply non-production`
1. Run `./tf-wrapper.sh init production`
1. Run `./tf-wrapper.sh plan production` and review output.
1. Run `./tf-wrapper.sh apply production`
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>`
File renamed without changes.
22 changes: 22 additions & 0 deletions 2-environments/envs/development/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

terraform {
backend "gcs" {
bucket = "UPDATE_ME"
prefix = "terraform/environments/development"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module "env" {
source = "../../modules/env_baseline"

env = "dev"
env = "development"
environment_code = "d"

parent_id = var.parent_folder != "" ? "folders/${var.parent_folder}" : "organizations/${var.org_id}"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions 2-environments/envs/non-production/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

terraform {
backend "gcs" {
bucket = "UPDATE_ME"
prefix = "terraform/environments/non-production"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module "env" {
source = "../../modules/env_baseline"

env = "nonprod"
env = "non-production"
environment_code = "n"

parent_id = var.parent_folder != "" ? "folders/${var.parent_folder}" : "organizations/${var.org_id}"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
terraform {
backend "gcs" {
bucket = "UPDATE_ME"
prefix = "terraform/environments/nonprod"
prefix = "terraform/environments/production"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module "env" {
source = "../../modules/env_baseline"

env = "prod"
env = "production"
environment_code = "p"

parent_id = var.parent_folder != "" ? "folders/${var.parent_folder}" : "organizations/${var.org_id}"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 28de531

Please sign in to comment.