CloudFoundation - Terraform and CICD
CloudFoundation - Terraform and CICD
Topics
1 IaC
2 Terraform Basics
3 CI/CD
4 Hands-on demo
Proprietary + Confidential
Infrastructure
as Code
Proprietary + Confidential
Benefits of IaC
Roll back Roll out and roll back changes just like a regular application
No reinventing the
wheel, use software
Validate Assess desired state vs. current state infrastructure engineering practices
for infrastructure.
Terraform
Terraform is an infrastructure as code tool developed by HashiCorp that automates the building
and management of infrastructure using a declarative language
Support for all major Cloud Three different editions Thousands of third-party
providers as well as many ranging from self-hosted to providers and modules
other services exposed fully managed with available from the Terraform
through an API (like GitHub, enterprise-level support Registry
Kubernetes)
Proprietary + Confidential
Controlled Distribution
A product that surfaces curated, verified, Cloud admins manage visibility and deployment
access to curated templates and solutions at the
and approved deployment templates and organization, folder, and project levels.
cloud solutions defined by cloud
administrators to enable developers & Increased Discoverability
One-stop shop (catalog) for all pre-approved
operators to quickly and consistently product configs, templates, and solutions.
consume organization compliant and secured
solutions.
Ensured Compliance and
Governance
Cloud admins have full control over curated
templates and solutions ensuring that
deployments adhere to the organization policies.
Proprietary + Confidential
Terraform
basics
Proprietary + Confidential
Declarative Infrastructure
VS.
“I should have 5 servers” “Give me 5 servers”
Proprietary + Confidential
Key Concepts
01 02 03
Resource Configuration State Provider
Providers
State
Code layout
● plan - computes and shows execution ● fmt - formats your .tf files
plan to converge existing to described
● destroy - destroys all resources managed by
● apply - applies the computed plan to current state
converge infrastructure
● state - examines and manipulates state (list, show,
mv, rm, push, pull)
CI/CD: Terraform
Automation
Proprietary + Confidential
Evolve
CI/CD Pipeline
Git Repositories Google Cloud
When running Terraform in automation, the basic path is broadly the same as the familiar Terraform CLI
commands, with some additional options:
The -input=false option indicates that Terraform should not attempt to prompt for input, and instead
expect all necessary values to be provided by either configuration files or the command line.
image: hashicorp/terraform:full
pipelines:
default:
- step:
script:
- terraform init
- terraform plan -out=tfplan -input=false
- if [ $BITBUCKET_BRANCH == main ];
then terraform apply -input=false tfplan; fi
Proprietary + Confidential
Demo