Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #822

Open
wants to merge 15 commits into
base: prod
Choose a base branch
from
Open
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Configuring your **dev** environment
# Managing infrastructure as code with Terraform, Cloud Build, and GitOps

This is the repo for the [Managing infrastructure as code with Terraform, Cloud Build, and GitOps](https://cloud.google.com/solutions/managing-infrastructure-as-code) tutorial. This tutorial explains how to manage infrastructure as code with Terraform and Cloud Build using the popular GitOps methodology.

## Configuring your **dev** environment

Just for demostration, this step will:
1. Configure an apache2 http server on network '**dev**' and subnet '**dev**-subnet-01'
Expand All @@ -12,7 +16,7 @@ terraform apply
terraform destroy
```

# Promoting your environment to **production**
## Promoting your environment to **production**

Once you have tested your app (in this example an apache2 http server), you can promote your configuration to prodution. This step will:
1. Configure an apache2 http server on network '**prod**' and subnet '**prod**-subnet-01'
Expand Down
15 changes: 10 additions & 5 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ steps:
echo "***********************"

- id: 'tf init'
name: 'hashicorp/terraform:0.11.14'
name: 'hashicorp/terraform:1.0.0'
entrypoint: 'sh'
args:
- '-c'
Expand All @@ -50,7 +50,7 @@ steps:

# [START tf-plan]
- id: 'tf plan'
name: 'hashicorp/terraform:0.11.14'
name: 'hashicorp/terraform:1.0.0'
entrypoint: 'sh'
args:
- '-c'
Expand All @@ -65,7 +65,7 @@ steps:
env=${dir%*/}
env=${env#*/}
echo ""
echo "*************** TERRAFOM PLAN ******************"
echo "*************** TERRAFORM PLAN ******************"
echo "******* At environment: ${env} ********"
echo "*************************************************"
terraform plan || exit 1
Expand All @@ -76,7 +76,7 @@ steps:

# [START tf-apply]
- id: 'tf apply'
name: 'hashicorp/terraform:0.11.14'
name: 'hashicorp/terraform:1.0.0'
entrypoint: 'sh'
args:
- '-c'
Expand All @@ -86,7 +86,12 @@ steps:
terraform apply -auto-approve
else
echo "***************************** SKIPPING APPLYING *******************************"
echo "Branch '$BRANCH_NAME' does not represent an oficial environment."
echo "Branch '$BRANCH_NAME' does not represent an official environment."
echo "*******************************************************************************"
fi
# [END tf-apply]

- name: gcr.io/cloud-builders/gsutil
args: ["-m", "rsync", "-r", "-c", "-d", ".", "gs://terraform-test1-429512-tfstate"]
options:
logging: CLOUD_LOGGING_ONLY
2 changes: 1 addition & 1 deletion environments/dev/backend.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

terraform {
backend "gcs" {
bucket = "PROJECT_ID-tfstate"
bucket = "terraform-test1-429512-tfstate"
prefix = "env/dev"
}
}
2 changes: 1 addition & 1 deletion environments/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


locals {
"env" = "dev"
env = "dev"
}

provider "google" {
Expand Down
2 changes: 1 addition & 1 deletion environments/dev/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1 +1 @@
project="PROJECT_ID"
project="terraform-test1-429512"
2 changes: 1 addition & 1 deletion environments/dev/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@


terraform {
required_version = "~> 0.11.0"
required_version = "~> 1.0.0"
}
2 changes: 1 addition & 1 deletion environments/prod/backend.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

terraform {
backend "gcs" {
bucket = "PROJECT_ID-tfstate"
bucket = "terraform-test1-429512-tfstate"
prefix = "env/prod"
}
}
2 changes: 1 addition & 1 deletion environments/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


locals {
"env" = "prod"
env = "prod"
}

provider "google" {
Expand Down
2 changes: 1 addition & 1 deletion environments/prod/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1 +1 @@
project="PROJECT_ID"
project="terraform-test1-429512"
2 changes: 1 addition & 1 deletion environments/prod/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@


terraform {
required_version = "~> 0.11.0"
required_version = "~> 1.0.0"
}
2 changes: 1 addition & 1 deletion modules/firewall/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@


terraform {
required_version = "~> 0.11.0"
required_version = "~> 1.0.0"
}
2 changes: 1 addition & 1 deletion modules/http_server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resource "google_compute_instance" "http_server" {

boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
image = "debian-cloud/debian-11"
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/http_server/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@


terraform {
required_version = "~> 0.11.0"
required_version = "~> 1.0.0"
}
2 changes: 1 addition & 1 deletion modules/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

module "vpc" {
source = "terraform-google-modules/network/google"
version = "0.6.0"
version = "3.3.0"

project_id = "${var.project}"
network_name = "${var.env}"
Expand Down
2 changes: 1 addition & 1 deletion modules/vpc/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@


terraform {
required_version = "~> 0.11.0"
required_version = "~> 1.0.0"
}