Building a Continuous Delivery flow for your Infrastructure as Code.

version: v1.0
name: Terraform IaC
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
global_job_config:
env_vars:
— name: BUILD_TOOLS_VERSION
value: v0.1.2
— name: TF_IN_AUTOMATION
value: ‘yes’
— name: TERRAFORM_PLANFILE
value: out.tfplan
— name: TERRAFORM_DIR
value: gce_vm_cloudinit
secrets:
— name: secrets
prologue:
commands:
— checkout — use-cache
blocks:
— name: Lint and Plan
task:
prologue:
commands:
— cache clear
jobs:
— name: Pre Commit Hooks
commands:
— make pre-commit-hooks
— name: Terraform Plan
commands:
— cp ~/.secrets/gcp_sa.json $TERRAFORM_DIR/sa.json
— touch $TERRAFORM_PLANFILE
— make terraform-init
— make terraform-plan
— cache store terraform-wd-$TERRAFORM_DIR .terraform
— cache store terraform-planfile-$TERRAFORM_DIR $TERRAFORM_PLANFILE

promotions:
— name: IaC-Github Deploy to GitHub
pipeline_file: deploy.yml
auto_promote:
when: branch = ‘master’
version: v1.0
name: Apply Terraform Changes
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
global_job_config:
env_vars:
— name: BUILD_TOOLS_VERSION
value: v0.1.2
— name: TF_IN_AUTOMATION
value: ‘yes’
— name: TERRAFORM_PLANFILE
value: out.tfplan
— name: TERRAFORM_DIR
value: gce_vm_cloudinit
secrets:
— name: secrets
prologue:
commands:
— checkout — use-cache
blocks:
— name: Deploy Master
task:
prologue:
commands:
— cp ~/.secrets/gcp_sa.json $TERRAFORM_DIR/sa.json
— touch $TERRAFORM_PLANFILE
— cache restore terraform-wd-$TERRAFORM_DIR
— cache restore terraform-planfile-$TERRAFORM_DIR
jobs:
— name: Terraform Apply
commands:
— make terraform-apply
— cache clear
# Clone repo
$ git clone https://github.com/Timtech4u/iac-cd-sample.git

# Change directory
$ cd iac-cd-sample/gce_vm_cloudinit

# Initialize Terraform
$ terraform init

Initializing provider plugins…
# …
Terraform has been successfully initialized!

# Review plan
$ terraform plan

# Apply
$ terraform apply

An execution plan has been generated and is shown below.

Do you want to perform these actions?

Terraform will perform the actions described above.
Only ‘yes’ will be accepted to approve.
Enter a value: yes

# …

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

--

--

--

Software / DevOps Engineer | Google Developer Expert for Cloud | https://www.codementor.io/@timtech4u

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What will be the Trending Languages in 2020

Experimental study of the state of a gas

Tricks for keeping a tidy Git commit history

Using ModelBuilder in ArcGIS to deal with repeatedly analyse

How to create Galera claster using MariaDB 10.6.5 on Centos 7

Understanding List comprehensions in Python Programming

Programming with Weave, Part I

AZURE KUBERNETES SERVICE

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Timothy

Timothy

Software / DevOps Engineer | Google Developer Expert for Cloud | https://www.codementor.io/@timtech4u

More from Medium

Automated user migration and management of AWS Identity and Access Management (IAM) resources

DevOps: How we ended like this?

Hybrid Cloud Is Here to Stay

The Power of Terraform