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

Abhinav8109 patch 10 #825

Open
wants to merge 20 commits into
base: prod
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 14 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,16 @@ 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]
options:
machineType: 'E2_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
diskSizeGb: 100
substitutionOption: 'ALLOW_LOOSE'

substitutions:
_SERVICE_ACCOUNT: '[email protected]'
_LOG_BUCKET: 'gs://amplified-asset-426508-e7-tfstate'
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 = "amplified-asset-426508-e7-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="amplified-asset-426508-e7"
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 = "amplified-asset-426508-e7-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="amplified-asset-426508-e7"
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"
}
5 changes: 2 additions & 3 deletions modules/firewall/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Copyright 2019 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
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
Expand All @@ -27,6 +26,6 @@ resource "google_compute_firewall" "allow-http" {
ports = ["80"]
}

target_tags = ["http-server2"]
target_tags = ["http-server"]
source_ranges = ["0.0.0.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"
}
4 changes: 2 additions & 2 deletions modules/http_server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ resource "google_compute_instance" "http_server" {
name = "${local.network}-apache2-instance"
machine_type = "f1-micro"

metadata_startup_script = "sudo apt-get update && sudo apt-get install apache2 -y && echo '<html><body><h1>Environment: ${local.network}</h1></body></html>' | sudo tee /var/www/html/index.html"
metadata_startup_script = "sudo apt-get update && sudo apt-get install apache2 -y && echo '<html><body><h1>my Environment: ${local.network}</h1></body></html>' | sudo tee /var/www/html/index.html"

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"
}