1 of 43

Get Started with GitOps

Operations by Pull Request enable Terraform for Teams

<hello@cloudposse.com>�https://cloudposse.com/

@cloudposse

2 of 43

What to Expect

Feelings of Euphoria

Aha! Moments

Reduced Anxiety

What is GitOps? (not rocket science)

Why it’s awesome (and you’ll agree)

How to get started… (our way)

Live demo. . . Q&A . . .

And...

  • HashiConf News!

3 of 43

Who is this dude?

Founder of a DevOps Professional Services Company��We’ve pioneered ��� Collaborative DevOps for Companies

(cloudposse.com)

SweetOps

Me

(Erik Osterman)

( 100% Open Source )

4 of 43

We got problems.

We Maintain 100+ Terraform Modules (the largest!)

Dozens of Helm Charts

Pain in the *ss to test everything

Multi-stage rollouts get complicated

Lots of tools like Helm, Kops, Terraform and Cloud Formation

Thousands of users (hey, some problems are good to have!)

5 of 43

Goal: Effortlessly Deploy Infrastructure.(e.g. spin up RDS Database with Terraform, or deploy Helm Chart)

6 of 43

One Approach...

Make changes in the �privacy of your personal laptop. �(sometimes after a few beers)

7 of 43

“I ^ it worked on my� machine.”

SWEAR .

8 of 43

Then comes… Launch Day

Production

9 of 43

Other Problems...

No Audit Trails (huge risk)

Complicated Manual Rollouts

Not clear what’s been deployed (configuration drift)

Failed Deployments on Merge (now what?!)

Insufficient Code Reviews

No one knows how to make changes

10 of 43

So….�Let’s fix this.

11 of 43

Let’s Practice GitOps.

Use Git as a System of Record for the desired state of configuration

Do Operations by Pull Request for Infrastructure as Code

Then use Continuous Delivery to apply changes to infrastructure(basically it’s a CI/CD for DevOps)Issue commands using comments to trigger actions (a.k.a “ChatOps”) � (E.g. “@bot give me a plan”, “@bot deploy these changes”)�� Run PLAN Run APPLY � See what should change See what actually happened

12 of 43

The “Git Workflow”

13 of 43

Why do you care?

Teamwork.

14 of 43

GitOps Objectives

Repeatable - Apply changes the same way every time� (even your entire stack all at once!)

Predictable - Know what’s going to happen� (e.g. before you merge)

Auditable - See what was done� (e.g. when things were applied. see if there were errors)

Accessible - Anyone who can open a PR can contribute

15 of 43

The Solution

https://runatlantis.io

Tool of...

Now an official HashiCorp sponsored project

16 of 43

Built for

(but will run anything)

17 of 43

About Atlantis

Purpose-built for Terraform (understands init, plan, apply)

Project started at

�Officially forked into

https://github.com/runatlantis/atlantis

Open Source APACHE2

100% Golang with good test coverage

Current Maintainer is �Luke Kysow

18 of 43

Basic Flow Diagram

19 of 43

How We Use Atlantis

Terraform� Cloud Formation� Helm� Helmfile

Because we can � run any command

20 of 43

But will it work with...

Terragrunt? YES� GITLAB? YES� BITBUCKET? YES� Docker? YES

21 of 43

“Interactive” � Pull Requests

22 of 43

Step One: Open Pull Request

23 of 43

Step Two: Review “Auto Plan”

24 of 43

Step Three: Seek Approval

Code Review

25 of 43

Step Four: Deploy Changes

26 of 43

Step Five: Merge Pull Request

27 of 43

That was easy.

28 of 43

Atlantis Users?

(...and soon most of our customers)

29 of 43

What others are saying...

30 of 43

Kelsey Hightower says...

https://runatlantis.io

Extra Dope

31 of 43

How to get started

  1. Deploy Atlantis (e.g. ECS, Kubernetes+Helm)
  2. Add atlantis.yaml to each repo
  3. Get back to work (sorry).

Or just ask us for help =)

32 of 43

Deploy Atlantis on ECS Fargate

fargate certificate create�fargate certificate validate�fargate lb create�fargate lb alias�fargate service create

  1. Create TLS Certificate

2. Activate it�� 3. Create Load Balancer�� 4. Assign DNS�� 5. Deploy Container

https://github.com/cloudposse/geodesic-aws-atlantis

33 of 43

Example atlantis.yaml.

version: 2�projects:�- name: "alpinist"� dir: "terraform"� workspace: "default"� terraform_version: "v0.11.7"� autoplan:� when_modified:� - "*.tf"� enabled: true� apply_requirements:� - "approved"� workflow: "default"�

# define list of chart repositories�# list of projects in this repo�# friendly name for this project�# directory with the tf code�# workspace to use with this project�# terraform version to use�# automatically run terraform plan�# when…�# any .tf file changes�# and enabled�# then run terraform apply �# only when approved�# run this workflow

Steps can be Entirely Customized.

34 of 43

Example atlantis.yaml. (Continued)

workflows:� default:� plan:� steps:� - run: "init-terraform"� - run: |-� terraform plan -no-color \� -var-file atlantis.tfvars -out $PLANFILE� apply:� steps:� - run: |-� terraform apply -no-color \� -var-file atlantis.tfvars $PLANFILE

# define list of workflows�# friendly name for this workflow�# to do a plan�# perform some steps�# run a command to initialize tf state�# use fancy YAML conventions�# run a terraform plan use with -var-file�# save the plan to a file for later�# to do a plan...�# run these steps..�# with some fancy YAML�# run apply using previous plan�# $PLANFILE ensures WYSIWYG

Steps can be Entirely Customized.

35 of 43

Live Demo

  1. Add User
  2. Open PR
  3. Run Plan
  4. Seek Approval (or not)
  5. Apply
  6. Merge

36 of 43

Demo Time!

37 of 43

Our Best Practices

Use one Atlantis Server per account (prod, dev, staging, identity, security, etc)

Use IAM Service Account for credentials (not hardcoded credentials)

Use GitHub CODEOWNERS

Use -var-files for non-secrets

Use chamber by segmentio for secrets (SSM+KMS)

Disable for forks

Atlantis�“Best Practices”

38 of 43

Gotchas

Atlantis is under active development

We’ve forked it to support what we needed

  1. Restricted Users
  2. Git Submodules
  3. Multiple Pipelines (e.g. atlantis/prod.yaml, atlantis/staging.yaml)
  4. Destroy action
  5. Custom wake words (e.g. “echo, shut up”)

https://github.com/cloudposse/atlantis

39 of 43

GitOps

Stop living dangerously. � Start using GitOps.

  • Practice total transparency in operations
  • Increase Productivity, Simplify Maintenance, Ensure Repeatability
  • Reduce the barrier to entry
  • Scalable strategy to manage lots of infrastructure

https://github.com/runatlantis/atlantis

40 of 43

HashiConf 2018 Announcements

0.12 (alpha 1) released�+ “Terraform State as a Service”

Automatic Unsealing -> Open Source

New provider! Manage charts with terraform

41 of 43

Links

Join our community!

42 of 43

Totally Bodacious

Geodesic (container+env pattern for Infrastructure as Code)� github.com/cloudposse/geodesicPackages (our complete toolchain + alpine packages) � github.com/cloudposse/packagesBuild Harness (Makefiles on Steroids; build anything)� github.com/cloudposse/build-harnessReference Architectures� github.com/cloudposse?q=cloudposse.co�Documentation� docs.cloudposse.com

43 of 43

Hire us. =)

A Totally Sweet DevOps Professional Services Company

100+ Free Terraform Modules github.com/cloudposse/�

Active Community slack.cloudposse.com

�Awesome Documentation docs.cloudposse.com

415 535 8615��hello@cloudposse.com

(free consultation)