AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi...

63
1 Scaling Terraform From Startup to Enterprise Paolo Tonin @ Flowing AWS Cloud Solution Architect

Transcript of AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi...

Page 1: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

1

Scaling TerraformFrom Startup to Enterprise

Paolo Tonin @ FlowingAWS Cloud Solution Architect

Page 2: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

#DOH19 2

Organizer & sponsors

GetLatestVersion.it

Page 3: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Paolo ToninCloud & DevOps

AWS Solution Architect

[email protected]

Page 4: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform

● Intro

● What is Terraform

● 4 Stages of Adoption

● Stage Next

Page 5: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform

● Intro

● What is Terraform

● 4 Stages of Adoption

● Stage Next

Page 6: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks
Page 7: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

From Infrastructure Services to multiple Cloud

Not IaaS services Cloud providerVirtualization and IaaS

Cloudflare

UltraDNS

Fastly

BitBucket

Datadog

(and more…)

Amazon

Google Cloud

Microsoft Azure

DigitalOcean

Alibaba Cloud

(and more…)

OpenStack

OpenNebula

VMware vCloud

Softlayer

Cloudstack

(and more…)

Page 8: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Pro Cons

● Multiple Provider

● Low learning curve

● Declarative HCL language, not

procedural code

● Dry runs

● Infrastructure versioning

● Terraform Registry

● No rolling upgrades*

● HCL Limitations (logic, loops)*

● Not “Drift detection”*

Page 9: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform

● Intro

● What is Terraform

● 4 Stages of Adoption

○ Stage 1 Manual

○ Stage 2 Semi Automated

○ Stage 3

○ Stage 4

● Stage Next

Page 10: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

4 Stage of Adoption

Page 11: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Stage 1

Page 12: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 1 Manual

● Web Consoles / Manual CLI

● Single environment(s)

● Mutable Infrastructure (Pets server)

Page 13: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 1 Manual

● Web Consoles / Manual CLI

● Single environment(s)

● Mutable Infrastructure (Pets server)

● “Infrastructure as Code”

Page 14: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 1 Manual

● Web Consoles / Manual CLI

● Single environment(s)

● Mutable Infrastructure (Pets server)

● “Infrastructure as Code” ops.txt

Page 15: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

● ….

Page 16: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

● Not using any

Terraform is the

first step to using a

lot of Terraform

Page 17: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 1 Manual

Technical Operational

Reproducibility Auditing

Change Management Consistency

Architecture Knowledge Sharing

Page 18: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 1 Manual

Technical Operational

Reproducibility Auditing

Change Management Consistency

Architecture Knowledge Sharing

Page 19: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 1 Manual

● Intro

● What is Terraform

● 4 Stages of Adoption

○ Stage 1 Manual

○ Stage 2 Semi automated

○ Stage 3

○ Stage 4

● Stage Next

Page 20: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Stage 2 - Semi automated

Page 21: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 2 Semi automated

● Adopting Infrastructure As Code (also Dockerfiles)

● Machine images (also playbooks and others / Packer)

● Web Consoles

● Introduce Terraform!

○ Configuration!

○ Automation!

○ Iteration!

Page 22: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Modeling Infrastructure with Configuration

Page 23: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

● Plan, Apply, Iterate

Page 24: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks
Page 25: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 2 Semi automated

Technical Operational

Reproducibility Auditing

Change Management Consistency

Architecture Knowledge Sharing

Page 26: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 2 Semi automated

Technical Operational

Reproducibility Auditing

Change Management Consistency

Architecture Knowledge Sharing

State management Operations

Page 27: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Let’s “import” our infrastructure

Page 28: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 2 Semi automated

Page 29: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 2 Semi automated

$ cat ec2_instance.tf

resource "aws_instance" "prod_ec2" {

# ...instance configuration...

}

$ terraform import aws_instance.prod_ec2 i-abcd1234

Page 30: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 2 Semi automated

Page 31: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform

● Intro

● What is Terraform

● 4 Stages of Adoption

○ Stage 1 Manual

○ Stage 2 Semi automated

○ Stage 3

○ Stage 4

● Stage Next

Page 32: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Stage 3

Page 33: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

● Workspaces

● Packaged Components

● Modules

● Inputs and Outputs

● Config Mgmt Hooks

Page 34: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

● Organizational adoption

● Multiple Environments

● Collaboration

● Version Control

Page 35: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

● Organizational adoption

● Multiple Environments (Workspaces)

Page 36: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

● Organizational adoption

● Multiple Environments (Workspaces)

$ terraform workspace new staging

You're now on a new, empty workspace. Workspaces isolate

their state, so if you run "terraform plan" Terraform

will not see any existing state for this configuration.

Page 37: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

● Organizational adoption

● Multiple Environments (Workspaces) - separate state files

●resource "aws_instance" "example" {

count = "${terraform.workspace == "prod" ? 5 : 1}"

# … other params

}

Page 38: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

● Organizational adoption

● Multiple Environments (Workspaces) - separate state filesresource "aws_vpc" "mycompany_vpc" {

name = "VPC ${terraform.workspace == "default" ?

“Prod” : “Staging”}"

# … other params

}

Page 39: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

● Workspaces

● Packaged Components

Page 40: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

Page 41: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

● Workspaces

● Packaged Components

● Modules

Page 42: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

Page 43: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

Page 44: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

$ tree base-mod/

├── README.md

├── main.tf

└── variables.tf

└── outputs.tf

Page 45: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks
Page 46: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks
Page 47: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

● Version control (PR)

● Remote state

Page 48: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks
Page 49: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

Technical Operational

Reproducibility Auditing

Change Management Consistency

Architecture Knowledge Sharing

State management Operations

Page 50: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

Technical Operational

Reproducibility Auditing

Change Management Consistency

Architecture Knowledge Sharing

State management Operations

Page 51: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 3

● Intro

● What is Terraform

● 4 Stages of Adoption

○ Stage 1 Manual

○ Stage 2 Semi automated

○ Stage 3

○ Stage 4

● Stage Next

Page 52: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Stage 4

Page 53: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

● VCS Integration

● Team permissions

● “Run Terraform for me”

Page 54: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Developer“I need to create new VMs for my new env; but i don’t know yet how many”

Page 55: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Operations“Ok, it’s not a problem!”

Page 56: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 4

Operations

Create new Reservation (Scheduled Reserved or Convertible)

Create new IAM and assign permission for this RI

Restrict IAM Policy for using RI and EC2 family

Page 57: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 4

Developers

Configure AWS CLI with IAM user

Create Terraform module for EC2 resources

Page 58: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Terraform Enterprise

Page 59: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Terraform Enterprise

Page 60: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

“Run Terraform for me”

Page 61: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 4

Page 62: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Scaling Terraform - Stage 4

Page 63: AWS Cloud Solution Architect Paolo Tonin @ Flowing From ... · Scaling Terraform - Stage 2 Semi automated Adopting Infrastructure As Code (also Dockerfiles) Machine images (also playbooks

Grazie!

Paolo ToninCloud & DevOps

[email protected]