SlideShare a Scribd company logo
@magickatt
Andrew Kirkpatrick
DevOps Toronto, February 2021
Self-service PR-based
automated Terraform
Alexandre Dulaunoy
https://search.creativecommons.org
/photos/50a56587-4db5-4de7-a98e-06730497a283
@magickatt
@magickatt
@magickatt
Infrastructure-as-Code solves some problems, but not all problems...
@magickatt
There are many legitimate reasons why someone might need an
infrastructure change
● Need a VM for application
● Increase database capacity
● New build job
● Create user account
● Update DNS record
● … and so forth
@magickatt
Is it important that someone with infrastructure expertise carry out
the change? 🤷
What is important then? Surely that the change is
● Performed safely and securely
● Tracked against an individual/team/project/division
● Codified in a reproducible stream of changes
● Peer reviewed and approval by chain-of-command
@magickatt
● Infrastructure-as-Code codifies your infrastructure, using
Terraform (HCL) in many cases
● Modules abstract domain-specific* logic into re-usable building
blocks
● Using pre-built building blocks, could you let other people
create/update/delete those resources?
● If so, how would you validate and approve those resources?
* https://en.wikipedia.org/wiki/Domain_(software_engineering)
@magickatt
● View proposed resource
changes ahead of time
(terraform plan)
○ Creation
○ Modification
○ Deletion
● Automatically validate and
re-validate if requested changes
are modified (new commits in a
Pull Request)
@magickatt
● If not making changes
directly, who can and should
approve changes?
● Integrated into issue
tracking, auditable for
compliance
● How and when do proposed
changes occur?
@magickatt
1. Introduction
2. Terraform-at-a-glance
3. Self-service infrastructure
4. Atlantis versus alternatives
5. Pull Request workflows
6. Centralised execution
7. Examples
8. Advantages and Drawbacks
9. Summary
@magickatt
Terraform at-a-glance
@magickatt
● Resources (usually cloud
infrastructure) represented as code
(HCL*) that can be created,
modified or deleted
● Abstract the underlying APIs with a
common-ish syntax
● Different providers (AWS, GCP,
Azure, etc.) offer resources to use
* https://www.terraform.io/docs/configuration/syntax.html, https://github.com/hashicorp/hcl
@magickatt
● Code, what I want to be true
● State, what I last knew to be
true
● APIs, where I can ask for the
truth
Code State
API
Plan
A
p
p
l
y
A
p
p
l
y
@magickatt
Typical Terraform flow is as
follows...
● init
○ Links any Modules being used
○ Download Providers (API clients)
○ Configure Remote State*
● plan
● apply
* Unless using local state. Only use local state for testing purposes
@magickatt
● init
● plan
○ Refresh Remote State
○ Diff between code and state
○ Work out what to create that is present in code and not in state
○ Work out to modify that is different between code and state
○ Work out what to delete that is present in state and not in code
○ Figure out correct order to make changes in
● apply
* Unless using local state. Only use local state for testing purposes
@magickatt
● plan
● apply
○ plan
○ Attempt to create, update and/or
delete resources in order
○ Update state based on changes
* Unless using local state. Only use local state for testing purposes
@magickatt
● If multiple users are working with the same Terraform code, you will
need a way to “share” state
● Ensures changes made by different users and by automation are kept
in sync
@magickatt
@magickatt
@magickatt
@magickatt
@magickatt
Self-service infrastructure
@magickatt
● Infrastructure engineers usually
write infrastructure code
● Application engineers usually
write application code
● Often results in the Thrown
Over The Wall anti-pattern*
* https://wiki.c2.com/?ThrownOverTheWall
** https://www.commitstrip.com/en/2016/11/07/which-full-stack-developer-are-you/
@magickatt
This creates a couple problems…
● Infrastructure engineers want x change to
application(s) to prevent y problem with infrastructure
● Application engineers want x change to infrastructure
to allow y feature with application
@magickatt
Infrastructure engineers want x change to application(s) to prevent
y problem with infrastructure...
@magickatt
Application engineers want x change to infrastructure to allow y
feature with application
● JIRA ticket, Slack message, email, tap-on-the-shoulder…
● Could we make a safe self-service process for them to do
it themselves?
● How to validate and approve the changes?
@magickatt
● Writing Terraform from scratch is
daunting!
● How to encapsulate complexity?
● If Terraform Modules* are the
“classes” of HCL**, think about what
users should not be able to modify,
rather than what can they modify?
* https://www.terraform.io/docs/configuration/syntax.html, https://github.com/hashicorp/hcl
** https://www.terraform.io/docs/configuration/modules.html
@magickatt
Terraform Resources can be overly complex with too many arguments,
use Modules as guardrails to simplify
Configuration for Resources in Modules can be...
● Globally configured, for all usages of a Module (not configurable)
● Dynamically configured, based on an argument (indirectly
configurable)
● Individually configured per module usage (directly configurable)
@magickatt
Resource for VM
Module invocation for VM
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/droplet
@magickatt
Module invocation for VM
@magickatt
@magickatt
Atlantis versus alternatives
@magickatt
Atlantis is an application for automating Terraform via pull requests.
It is deployed as a standalone application into your infrastructure.
No third-party has access to your credentials.
Atlantis listens for GitHub, GitLab or Bitbucket webhooks about
Terraform pull requests. It then runs terraform plan and comments
with the output back on the pull request.
https://www.runatlantis.io/guide/#overview-–-what-is-atlantis
@magickatt
● First PR-based Terraform automation
● Runs in a container (Go application)
● Responds to webhooks (GitHub/GitLab/Bitbucket)
● Configurable
○ Multiple repositories
○ Multiple projects per repository
○ Custom workflows
@magickatt
“Terraform Cloud is a platform that performs Terraform runs to provision
infrastructure, either on demand or in response to various events.”
“It manages Terraform runs in a consistent and reliable environment, and
includes easy access to shared state and secret data, access controls for
approving changes to infrastructure, a private registry for sharing
Terraform modules, detailed policy controls for governing the contents of
Terraform configurations, and more.”
https://www.terraform.io/docs/cloud/overview.html
https://www.terraform.io/docs/cloud/index.html#about-terraform-cloud-and-terraform-enterprise
@magickatt
● Cloud-hosted which saves maintenance, can use in conjunction
with on-premise execution (Business plan)
● Can be fully self-hosted* (Enterprise plan)
● Private Terraform Module registry
● Terraform Cloud enhanced backend for Remote State
● Non-trivial to setup Workspaces (UI/API/CLI rather than
configuration)
https://www.hashicorp.com/products/terraform/pricing
@magickatt
Atlantis is only PR-based, whereas Terraform Cloud can be CLI and API driven
@magickatt
@magickatt
@magickatt
@magickatt
Project cannot contain symlinks
@magickatt
Only supports Enhanced Backends, will not read Remote State from anything else
@magickatt
“env0 presents Terraform plans on your SCM pull requests so
you can approve your infrastructure change requests with
maximum confidence, all from within your existing workflows.
Shorten the cycle of pull requests and enable your team to
create pull requests without the need to distribute Terraform
credentials to everyone.”
https://www.env0.com
@magickatt
● Create Organization Templates from VCS* (GitHub, etc.)
● Create a Project Environment from a Project Template (which is
a selection of the available Organization Templates)
● Project Environments use Terraform Workspaces to
differentiate
● Non-trivial to setup Workspaces (UI/API rather than
configuration)
● Relatively new (public beta April 2020) but looks promising!
** https://en.wikipedia.org/wiki/Version_control
@magickatt
Uses long-running or ad-hoc Terraform Workspaces to manage multiple
Environments from a single Project Template
@magickatt
@magickatt
@magickatt
● Does not support remote state (manages state within env0)
● Project Templates created from directory within a VCS
repository, exist persistently as Project Environments
● Uses Terraform Workspaces to manage env0 Environments
@magickatt
env0 and Terraform Cloud support
● Environment variables
● Terraform variables
Atlantis can support
● Environment variables
● Files (including tfvars)
● … anything really
@magickatt
Pull Request workflows
@magickatt
● Possible with CircleCI and GitHub Actions
● Have problems that Atlantis, Terraform Cloud and env0 have
since solved
a. Plan and apply synchronisation
b. Approval of plans
c. Which project to plan
“it can be difficult or impossible to ensure that the plan and apply
subcommands are run on the same machine, in the same directory, with all of
the same files present.”
https://learn.hashicorp.com/tutorials/terraform/automate-terraform#plan-and-apply-on-different-machines
@magickatt
“To implement this robustly, it is important to ensure that either only one plan can
be outstanding at a time or that the two steps are connected such that approving a
plan passes along enough information to the apply step to ensure that the correct
plan is applied, as opposed to some later plan that also exists.”
There are 2 problems here…
● terraform plan outfile from a specific commit is supplied to terraform
apply
● Plan is either blocked or overwrites older plan for newer commit
https://learn.hashicorp.com/tutorials/terraform/automate-terraform
@magickatt
“Another challenge with automating the Terraform workflow is the desire
for an interactive approval step between plan and apply.”
When running in CI, how would you implement an approval step?
● You could get it to plan on feature branches and apply on master…
● ...but what if the apply fails? Then you have broken code on master
○ Terraform Cloud applies after merge
○ env0 also applies after merge
● Could use a manual gate on CI pipeline
https://learn.hashicorp.com/tutorials/terraform/automate-terraform#auto-approval-of-plans
@magickatt
● Atlantis responds to 2 comments
○ atlantis plan
○ atlantis apply
● Atlantis will also show feedback via
comments and the PR status check
● Terraform Cloud only provides
feedback on the PR status check
● env0 comments feedback, but will not
respond to comments, has no PR
status check
@magickatt
https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/about-status-checks
@magickatt
● Atlantis will lock each Project* so only 1 PR will plan/apply at once
● Terraform Cloud will lock each Workspace (1-n with Projects)
● env0 creates more Workspaces as it uses Project Templates
* Atlantis makes you specify a Workspace per Project in atlantis.yaml configuration
@magickatt
● Atlantis will “lock” a Pull Request (PR) once it has been planned
● New PRs try to obtain locks, will be granted lock in the future
● Locked plan must either be applied (PR approved) or discarded (PR
closed) before lock is released
https://www.runatlantis.io/docs/locking.html
@magickatt
● Approved – requires pull requests to be approved by at least one user other
than the author
● Mergeable – requires pull requests to be able to be merged
Atlantis will only apply if approved/mergeable conditions are met. Terraform Cloud
and env0 will apply after PR is merged
@magickatt
Centralised execution
@magickatt
● Atlantis is deployed into your infrastructure
● Terraform Cloud can run
○ Entirely in the cloud (Free, Team & Governance plans)
○ Control plane in the cloud, Agent Pools deployed into your infrastructure
(Business plan)
○ Fully deployed into your infrastructure (Enterprise plan)
● Env0 runs in the cloud
https://www.runatlantis.io/docs/deployment.html
https://www.terraform.io/docs/cloud/agents/index.html
https://docs.env0.com/docs/about-env0
@magickatt
● Big workflow change is getting Terraform
to use credentials from a robot account
than a real user account (you on your
workstation)
● Most Terraform providers can be
configured purely via environment
variables
● Different env var combinations can
determine how
authentication/authorisation is handled
@magickatt
● Need to supply credentials for
every Terraform Provider you
wish to use
● What permissions should each
service account, access key or
API token have?
● What Projects/Workspaces
should have access to which
variables/credentials?
@magickatt
@magickatt
@magickatt
@magickatt
If your Terraform workflow is non-standard in any way, how would you
accommodate this?
● Atlantis supports Custom Workflows and a customised
installation/container image
● Terraform Cloud will allow standalone binary execution, and discourages
provisioner usage
● env0 supports Custom Flows including multiple language support
https://www.runatlantis.io/docs/custom-workflows.html
https://www.terraform.io/docs/cloud/run/install-software.html
https://docs.env0.com/docs/custom-flows
@magickatt
@magickatt
@magickatt
Examples
@magickatt
@magickatt
@magickatt
@magickatt
@magickatt
@magickatt
@magickatt
Advantages and Drawbacks
@magickatt
● Allows contributions without needing to run Terraform locally
● Peer review before execution
● Ties into other workflow automation (JIRA for example)
● Potentially decreases credential theft as an attack vector
● Can alleviate “DevOps” bottlenecks, but depends on...
○ Your peer review allocation process
○ Documentation for existing Terraform usage
○ Readability of existing Terraform code
@magickatt
● Slow feedback cycle
● Less ideal for module development/prototyping
● Moves security controls from Cloud IAM* to VCS IAM
● Could become a skeleton key for your infrastructure
● Maintenance of yet another tool
● Can be problematic if run on same infrastructure that it
controls
* https://en.wikipedia.org/wiki/Identity_management
@magickatt
● Open Source, free to use
● Frequent contributions,
well-maintained
● Simplicity/easier-to-use
● Can inject file-based
configuration (useful for multiple
k8s clusters)
● Custom workflows allow it to do
anything weird you do on your
workstation
@magickatt
Summary
@magickatt
● Open source, free-to-use
● Customisable workflow and execution
● On-premise*
● Post-approval pre-merge apply
● Cloud-hosted
● Temporary environments, per user
quotas
● Fairly new
● Cloud-hosted or on-premise
● Many more features and integrations
● Less feedback via on Pull Request
● Approvals can happen outside of Pull
Requests (via Terraform Cloud)
* I don’t mean that it’s not in a cloud somewhere, I just mean your cloud 😛
@magickatt
● Infrastructure Engineer at PartnerStack (https://jobs.lever.co/partnerstack)
● Any questions?

More Related Content

PDF
How to get started with Site Reliability Engineering
PDF
Hidden Dragons of CGO
PDF
Ratpack Web Framework
PDF
Full stack development
PDF
Future of Grails
PDF
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
PDF
Ratpack Web Framework
PDF
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
How to get started with Site Reliability Engineering
Hidden Dragons of CGO
Ratpack Web Framework
Full stack development
Future of Grails
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
Ratpack Web Framework
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native

What's hot (20)

PDF
Matteo Manchi - React Native for multi-platform mobile applications - Codemot...
PDF
Intro to Ratpack (CDJDN 2015-01-22)
PDF
Es fácil contribuir al open source - Bolivia JUG 2020
PDF
Creando microservicios con Java y Microprofile - Nicaragua JUG
PPTX
Building Web Apps in Ratpack
PDF
Foundations of Zend Framework
PPTX
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
PDF
Its easy! contributing to open source - Devnexus 2020
PPT
Ratpack - Classy and Compact Groovy Web Apps
PDF
Open-source RPA: Leveraging Python and Robot Framework ecosystems for busines...
PPTX
Steve Sfartz - How to embed Messaging and Video in your apps - Codemotion Mil...
PDF
javerosmx-2015-marzo-groovy-java8-comparison
PPTX
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
PDF
Bgoug 2019.11 building free, open-source, plsql products in cloud
PDF
Use groovy & grails in your spring boot projects
PDF
TDD for APIs @ Europython 2015, Bilbao by Michael Kuehne
PDF
Ratpack JVM_MX Meetup February 2016
PDF
Enterprise PHP
PDF
Go at Skroutz
PDF
Lua as a business logic language in high load application
Matteo Manchi - React Native for multi-platform mobile applications - Codemot...
Intro to Ratpack (CDJDN 2015-01-22)
Es fácil contribuir al open source - Bolivia JUG 2020
Creando microservicios con Java y Microprofile - Nicaragua JUG
Building Web Apps in Ratpack
Foundations of Zend Framework
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Its easy! contributing to open source - Devnexus 2020
Ratpack - Classy and Compact Groovy Web Apps
Open-source RPA: Leveraging Python and Robot Framework ecosystems for busines...
Steve Sfartz - How to embed Messaging and Video in your apps - Codemotion Mil...
javerosmx-2015-marzo-groovy-java8-comparison
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Bgoug 2019.11 building free, open-source, plsql products in cloud
Use groovy & grails in your spring boot projects
TDD for APIs @ Europython 2015, Bilbao by Michael Kuehne
Ratpack JVM_MX Meetup February 2016
Enterprise PHP
Go at Skroutz
Lua as a business logic language in high load application
Ad

Similar to Self-service PR-based Terraform (20)

PDF
GDG Cloud Southlake #8 Steve Cravens: Infrastructure as-Code (IaC) in 2022: ...
PDF
Collaborative Terraform with Atlantis
PDF
Managing GCP Projects with Terraform (devfest Pisa 2018)
PDF
Meetup 2020 - Back to the Basics part 101 : IaC
PDF
Introduction to IAC and Terraform
PDF
Introduction to Apache Airflow
PDF
Git ops & Continuous Infrastructure with terra*
PDF
A case study why Zoominfo uses Terraform Cloud in high-scale environment.
PDF
How to plan and define your CI-CD pipeline
PPTX
Kubernetes is hard! Lessons learned taking our apps to Kubernetes - Eldad Ass...
PDF
Gestión de infraestructura tomcat/Tom EE con tfactory
PPTX
Terraform Automation in Azure Cloud Online Training in Hyderabad.pptx
PDF
Enterprise Application Migration
PDF
Configuration management II - Terraform
PPTX
RIMA-Infrastructure as a code with Terraform.pptx
PPTX
Terraform day 1
PDF
Deploy 22 microservices from scratch in 30 mins with GitOps
PPTX
Terraform in production - experiences, best practices and deep dive- Piotr Ki...
PDF
GDG Cloud Southlake no. 22 Gutta and Nayer GCP Terraform Modules Scaling Your...
PPTX
Fluentd – Making Logging Easy & Effective in a Multi-cloud & Hybrid Environme...
GDG Cloud Southlake #8 Steve Cravens: Infrastructure as-Code (IaC) in 2022: ...
Collaborative Terraform with Atlantis
Managing GCP Projects with Terraform (devfest Pisa 2018)
Meetup 2020 - Back to the Basics part 101 : IaC
Introduction to IAC and Terraform
Introduction to Apache Airflow
Git ops & Continuous Infrastructure with terra*
A case study why Zoominfo uses Terraform Cloud in high-scale environment.
How to plan and define your CI-CD pipeline
Kubernetes is hard! Lessons learned taking our apps to Kubernetes - Eldad Ass...
Gestión de infraestructura tomcat/Tom EE con tfactory
Terraform Automation in Azure Cloud Online Training in Hyderabad.pptx
Enterprise Application Migration
Configuration management II - Terraform
RIMA-Infrastructure as a code with Terraform.pptx
Terraform day 1
Deploy 22 microservices from scratch in 30 mins with GitOps
Terraform in production - experiences, best practices and deep dive- Piotr Ki...
GDG Cloud Southlake no. 22 Gutta and Nayer GCP Terraform Modules Scaling Your...
Fluentd – Making Logging Easy & Effective in a Multi-cloud & Hybrid Environme...
Ad

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Cloud computing and distributed systems.
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Spectroscopy.pptx food analysis technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation theory and applications.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Chapter 3 Spatial Domain Image Processing.pdf
Electronic commerce courselecture one. Pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Review of recent advances in non-invasive hemoglobin estimation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Cloud computing and distributed systems.
Big Data Technologies - Introduction.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Spectral efficient network and resource selection model in 5G networks
Spectroscopy.pptx food analysis technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
sap open course for s4hana steps from ECC to s4
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf

Self-service PR-based Terraform

  • 1. @magickatt Andrew Kirkpatrick DevOps Toronto, February 2021 Self-service PR-based automated Terraform Alexandre Dulaunoy https://search.creativecommons.org /photos/50a56587-4db5-4de7-a98e-06730497a283
  • 4. @magickatt Infrastructure-as-Code solves some problems, but not all problems...
  • 5. @magickatt There are many legitimate reasons why someone might need an infrastructure change ● Need a VM for application ● Increase database capacity ● New build job ● Create user account ● Update DNS record ● … and so forth
  • 6. @magickatt Is it important that someone with infrastructure expertise carry out the change? 🤷 What is important then? Surely that the change is ● Performed safely and securely ● Tracked against an individual/team/project/division ● Codified in a reproducible stream of changes ● Peer reviewed and approval by chain-of-command
  • 7. @magickatt ● Infrastructure-as-Code codifies your infrastructure, using Terraform (HCL) in many cases ● Modules abstract domain-specific* logic into re-usable building blocks ● Using pre-built building blocks, could you let other people create/update/delete those resources? ● If so, how would you validate and approve those resources? * https://en.wikipedia.org/wiki/Domain_(software_engineering)
  • 8. @magickatt ● View proposed resource changes ahead of time (terraform plan) ○ Creation ○ Modification ○ Deletion ● Automatically validate and re-validate if requested changes are modified (new commits in a Pull Request)
  • 9. @magickatt ● If not making changes directly, who can and should approve changes? ● Integrated into issue tracking, auditable for compliance ● How and when do proposed changes occur?
  • 10. @magickatt 1. Introduction 2. Terraform-at-a-glance 3. Self-service infrastructure 4. Atlantis versus alternatives 5. Pull Request workflows 6. Centralised execution 7. Examples 8. Advantages and Drawbacks 9. Summary
  • 12. @magickatt ● Resources (usually cloud infrastructure) represented as code (HCL*) that can be created, modified or deleted ● Abstract the underlying APIs with a common-ish syntax ● Different providers (AWS, GCP, Azure, etc.) offer resources to use * https://www.terraform.io/docs/configuration/syntax.html, https://github.com/hashicorp/hcl
  • 13. @magickatt ● Code, what I want to be true ● State, what I last knew to be true ● APIs, where I can ask for the truth Code State API Plan A p p l y A p p l y
  • 14. @magickatt Typical Terraform flow is as follows... ● init ○ Links any Modules being used ○ Download Providers (API clients) ○ Configure Remote State* ● plan ● apply * Unless using local state. Only use local state for testing purposes
  • 15. @magickatt ● init ● plan ○ Refresh Remote State ○ Diff between code and state ○ Work out what to create that is present in code and not in state ○ Work out to modify that is different between code and state ○ Work out what to delete that is present in state and not in code ○ Figure out correct order to make changes in ● apply * Unless using local state. Only use local state for testing purposes
  • 16. @magickatt ● plan ● apply ○ plan ○ Attempt to create, update and/or delete resources in order ○ Update state based on changes * Unless using local state. Only use local state for testing purposes
  • 17. @magickatt ● If multiple users are working with the same Terraform code, you will need a way to “share” state ● Ensures changes made by different users and by automation are kept in sync
  • 23. @magickatt ● Infrastructure engineers usually write infrastructure code ● Application engineers usually write application code ● Often results in the Thrown Over The Wall anti-pattern* * https://wiki.c2.com/?ThrownOverTheWall ** https://www.commitstrip.com/en/2016/11/07/which-full-stack-developer-are-you/
  • 24. @magickatt This creates a couple problems… ● Infrastructure engineers want x change to application(s) to prevent y problem with infrastructure ● Application engineers want x change to infrastructure to allow y feature with application
  • 25. @magickatt Infrastructure engineers want x change to application(s) to prevent y problem with infrastructure...
  • 26. @magickatt Application engineers want x change to infrastructure to allow y feature with application ● JIRA ticket, Slack message, email, tap-on-the-shoulder… ● Could we make a safe self-service process for them to do it themselves? ● How to validate and approve the changes?
  • 27. @magickatt ● Writing Terraform from scratch is daunting! ● How to encapsulate complexity? ● If Terraform Modules* are the “classes” of HCL**, think about what users should not be able to modify, rather than what can they modify? * https://www.terraform.io/docs/configuration/syntax.html, https://github.com/hashicorp/hcl ** https://www.terraform.io/docs/configuration/modules.html
  • 28. @magickatt Terraform Resources can be overly complex with too many arguments, use Modules as guardrails to simplify Configuration for Resources in Modules can be... ● Globally configured, for all usages of a Module (not configurable) ● Dynamically configured, based on an argument (indirectly configurable) ● Individually configured per module usage (directly configurable)
  • 29. @magickatt Resource for VM Module invocation for VM https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/droplet
  • 33. @magickatt Atlantis is an application for automating Terraform via pull requests. It is deployed as a standalone application into your infrastructure. No third-party has access to your credentials. Atlantis listens for GitHub, GitLab or Bitbucket webhooks about Terraform pull requests. It then runs terraform plan and comments with the output back on the pull request. https://www.runatlantis.io/guide/#overview-–-what-is-atlantis
  • 34. @magickatt ● First PR-based Terraform automation ● Runs in a container (Go application) ● Responds to webhooks (GitHub/GitLab/Bitbucket) ● Configurable ○ Multiple repositories ○ Multiple projects per repository ○ Custom workflows
  • 35. @magickatt “Terraform Cloud is a platform that performs Terraform runs to provision infrastructure, either on demand or in response to various events.” “It manages Terraform runs in a consistent and reliable environment, and includes easy access to shared state and secret data, access controls for approving changes to infrastructure, a private registry for sharing Terraform modules, detailed policy controls for governing the contents of Terraform configurations, and more.” https://www.terraform.io/docs/cloud/overview.html https://www.terraform.io/docs/cloud/index.html#about-terraform-cloud-and-terraform-enterprise
  • 36. @magickatt ● Cloud-hosted which saves maintenance, can use in conjunction with on-premise execution (Business plan) ● Can be fully self-hosted* (Enterprise plan) ● Private Terraform Module registry ● Terraform Cloud enhanced backend for Remote State ● Non-trivial to setup Workspaces (UI/API/CLI rather than configuration) https://www.hashicorp.com/products/terraform/pricing
  • 37. @magickatt Atlantis is only PR-based, whereas Terraform Cloud can be CLI and API driven
  • 42. @magickatt Only supports Enhanced Backends, will not read Remote State from anything else
  • 43. @magickatt “env0 presents Terraform plans on your SCM pull requests so you can approve your infrastructure change requests with maximum confidence, all from within your existing workflows. Shorten the cycle of pull requests and enable your team to create pull requests without the need to distribute Terraform credentials to everyone.” https://www.env0.com
  • 44. @magickatt ● Create Organization Templates from VCS* (GitHub, etc.) ● Create a Project Environment from a Project Template (which is a selection of the available Organization Templates) ● Project Environments use Terraform Workspaces to differentiate ● Non-trivial to setup Workspaces (UI/API rather than configuration) ● Relatively new (public beta April 2020) but looks promising! ** https://en.wikipedia.org/wiki/Version_control
  • 45. @magickatt Uses long-running or ad-hoc Terraform Workspaces to manage multiple Environments from a single Project Template
  • 48. @magickatt ● Does not support remote state (manages state within env0) ● Project Templates created from directory within a VCS repository, exist persistently as Project Environments ● Uses Terraform Workspaces to manage env0 Environments
  • 49. @magickatt env0 and Terraform Cloud support ● Environment variables ● Terraform variables Atlantis can support ● Environment variables ● Files (including tfvars) ● … anything really
  • 51. @magickatt ● Possible with CircleCI and GitHub Actions ● Have problems that Atlantis, Terraform Cloud and env0 have since solved a. Plan and apply synchronisation b. Approval of plans c. Which project to plan “it can be difficult or impossible to ensure that the plan and apply subcommands are run on the same machine, in the same directory, with all of the same files present.” https://learn.hashicorp.com/tutorials/terraform/automate-terraform#plan-and-apply-on-different-machines
  • 52. @magickatt “To implement this robustly, it is important to ensure that either only one plan can be outstanding at a time or that the two steps are connected such that approving a plan passes along enough information to the apply step to ensure that the correct plan is applied, as opposed to some later plan that also exists.” There are 2 problems here… ● terraform plan outfile from a specific commit is supplied to terraform apply ● Plan is either blocked or overwrites older plan for newer commit https://learn.hashicorp.com/tutorials/terraform/automate-terraform
  • 53. @magickatt “Another challenge with automating the Terraform workflow is the desire for an interactive approval step between plan and apply.” When running in CI, how would you implement an approval step? ● You could get it to plan on feature branches and apply on master… ● ...but what if the apply fails? Then you have broken code on master ○ Terraform Cloud applies after merge ○ env0 also applies after merge ● Could use a manual gate on CI pipeline https://learn.hashicorp.com/tutorials/terraform/automate-terraform#auto-approval-of-plans
  • 54. @magickatt ● Atlantis responds to 2 comments ○ atlantis plan ○ atlantis apply ● Atlantis will also show feedback via comments and the PR status check ● Terraform Cloud only provides feedback on the PR status check ● env0 comments feedback, but will not respond to comments, has no PR status check
  • 56. @magickatt ● Atlantis will lock each Project* so only 1 PR will plan/apply at once ● Terraform Cloud will lock each Workspace (1-n with Projects) ● env0 creates more Workspaces as it uses Project Templates * Atlantis makes you specify a Workspace per Project in atlantis.yaml configuration
  • 57. @magickatt ● Atlantis will “lock” a Pull Request (PR) once it has been planned ● New PRs try to obtain locks, will be granted lock in the future ● Locked plan must either be applied (PR approved) or discarded (PR closed) before lock is released https://www.runatlantis.io/docs/locking.html
  • 58. @magickatt ● Approved – requires pull requests to be approved by at least one user other than the author ● Mergeable – requires pull requests to be able to be merged Atlantis will only apply if approved/mergeable conditions are met. Terraform Cloud and env0 will apply after PR is merged
  • 60. @magickatt ● Atlantis is deployed into your infrastructure ● Terraform Cloud can run ○ Entirely in the cloud (Free, Team & Governance plans) ○ Control plane in the cloud, Agent Pools deployed into your infrastructure (Business plan) ○ Fully deployed into your infrastructure (Enterprise plan) ● Env0 runs in the cloud https://www.runatlantis.io/docs/deployment.html https://www.terraform.io/docs/cloud/agents/index.html https://docs.env0.com/docs/about-env0
  • 61. @magickatt ● Big workflow change is getting Terraform to use credentials from a robot account than a real user account (you on your workstation) ● Most Terraform providers can be configured purely via environment variables ● Different env var combinations can determine how authentication/authorisation is handled
  • 62. @magickatt ● Need to supply credentials for every Terraform Provider you wish to use ● What permissions should each service account, access key or API token have? ● What Projects/Workspaces should have access to which variables/credentials?
  • 66. @magickatt If your Terraform workflow is non-standard in any way, how would you accommodate this? ● Atlantis supports Custom Workflows and a customised installation/container image ● Terraform Cloud will allow standalone binary execution, and discourages provisioner usage ● env0 supports Custom Flows including multiple language support https://www.runatlantis.io/docs/custom-workflows.html https://www.terraform.io/docs/cloud/run/install-software.html https://docs.env0.com/docs/custom-flows
  • 77. @magickatt ● Allows contributions without needing to run Terraform locally ● Peer review before execution ● Ties into other workflow automation (JIRA for example) ● Potentially decreases credential theft as an attack vector ● Can alleviate “DevOps” bottlenecks, but depends on... ○ Your peer review allocation process ○ Documentation for existing Terraform usage ○ Readability of existing Terraform code
  • 78. @magickatt ● Slow feedback cycle ● Less ideal for module development/prototyping ● Moves security controls from Cloud IAM* to VCS IAM ● Could become a skeleton key for your infrastructure ● Maintenance of yet another tool ● Can be problematic if run on same infrastructure that it controls * https://en.wikipedia.org/wiki/Identity_management
  • 79. @magickatt ● Open Source, free to use ● Frequent contributions, well-maintained ● Simplicity/easier-to-use ● Can inject file-based configuration (useful for multiple k8s clusters) ● Custom workflows allow it to do anything weird you do on your workstation
  • 81. @magickatt ● Open source, free-to-use ● Customisable workflow and execution ● On-premise* ● Post-approval pre-merge apply ● Cloud-hosted ● Temporary environments, per user quotas ● Fairly new ● Cloud-hosted or on-premise ● Many more features and integrations ● Less feedback via on Pull Request ● Approvals can happen outside of Pull Requests (via Terraform Cloud) * I don’t mean that it’s not in a cloud somewhere, I just mean your cloud 😛
  • 82. @magickatt ● Infrastructure Engineer at PartnerStack (https://jobs.lever.co/partnerstack) ● Any questions?