Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bf83e89
Update README.md
fernandorubbo Sep 11, 2019
e6bcec8
Moving to terraform 1.0.0
fernandorubbo Jun 10, 2021
d8fc5e5
Update main.tf
nardo-google Sep 27, 2022
5ded46d
Merge pull request #554 from nardo-google/patch-1
fernandorubbo Sep 27, 2022
552f3b9
Update cloudbuild.yaml
nardo-google Sep 27, 2022
742eb87
Merge pull request #555 from nardo-google/patch-2
fernandorubbo Sep 27, 2022
31923ef
Fix typo in cloudbuild.yaml
mc-k1 Feb 2, 2024
dc4cbde
Merge pull request #780 from mc-k1/patch-1
iennae May 4, 2024
3d5eb8c
Update project IDs and buckets
Crow-0818 Jan 7, 2025
b3133b4
Update main.tf
Crow-0818 Jan 7, 2025
581fcc2
Merge pull request #8 from Crow-0818/Crow-0818-patch-8
Crow-0818 Jan 7, 2025
fec4633
Update cloudbuild.yaml
Crow-0818 Jan 7, 2025
5722f18
Update cloudbuild.yaml
Crow-0818 Jan 7, 2025
7a7cd3f
Update main.tf
Crow-0818 Jan 7, 2025
a5e74ec
Update main.tf
Crow-0818 Jan 7, 2025
06f8036
Merge pull request #12 from Crow-0818/Crow-0818-patch-12
Crow-0818 Jan 7, 2025
55241f6
Update main.tf
Crow-0818 Jan 8, 2025
5cb1fed
Merge pull request #13 from Crow-0818/Crow-0818-patch-13
Crow-0818 Jan 8, 2025
6c4fc10
Update main.tf
Crow-0818 Jan 8, 2025
1efa462
Merge pull request #14 from Crow-0818/Crow-0818-patch-14
Crow-0818 Jan 8, 2025
6bf5aa6
Update cloudbuild.yaml
Crow-0818 Jan 8, 2025
505b568
Merge pull request #15 from Crow-0818/Crow-0818-patch-15
Crow-0818 Jan 8, 2025
326ad1b
Update main.tf
Crow-0818 Jan 8, 2025
27468f2
Merge pull request #16 from Crow-0818/Crow-0818-patch-16
Crow-0818 Jan 8, 2025
5a25b58
Update main.tf
Crow-0818 Jan 8, 2025
67b9333
Merge pull request #18 from Crow-0818/Crow-0818-patch-18
Crow-0818 Jan 8, 2025
8a5ae0c
Update main.tf
Crow-0818 Jan 8, 2025
c9c32a1
Merge pull request #19 from Crow-0818/Crow-0818-patch-19
Crow-0818 Jan 8, 2025
2951926
Update main.tf
Crow-0818 Jan 8, 2025
a482202
Merge pull request #20 from Crow-0818/Crow-0818-patch-20
Crow-0818 Jan 8, 2025
d9812c4
Update main.tf
Crow-0818 Jan 8, 2025
e8cdb72
Merge pull request #22 from Crow-0818/Crow-0818-patch-21
Crow-0818 Jan 8, 2025
bbaea90
Update main.tf
Crow-0818 Jan 8, 2025
0f3665e
Merge pull request #23 from Crow-0818/Crow-0818-patch-22
Crow-0818 Jan 8, 2025
e8f8ad0
Update main.tf
Crow-0818 Jan 8, 2025
ae9f58e
Merge pull request #24 from Crow-0818/Crow-0818-patch-23
Crow-0818 Jan 8, 2025
3a51948
Update main.tf
Crow-0818 Jan 8, 2025
f89147f
Merge pull request #25 from Crow-0818/Crow-0818-patch-24
Crow-0818 Jan 8, 2025
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
21 changes: 21 additions & 0 deletions backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
# 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 = "ian-lab-tfstate"
prefix = "env/dev"
}
}
13 changes: 8 additions & 5 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# limitations under the License.


options:
logging: NONE

steps:
- id: 'branch name'
name: 'alpine'
Expand All @@ -25,7 +28,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 +53,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 +68,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 +79,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 +89,7 @@ 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]
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 = "ian-lab-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="ian-lab"
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 = "ian-lab-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="ian-lab"
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/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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"
}
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"
}