Slide 1

Slide 1 text

Creating Reusable Infrastructure with Terraform Modules

Slide 2

Slide 2 text

CODE EDITOR service "http" "proxy" { listen_addr = "127.0.0.1:${var.port}" process "server" { command = ["./server"] } } variable "port" { type = number description = "Port for proxy service" default = 8080 } HashiCorp Configuration Language

Slide 3

Slide 3 presenter notes

Learn more about Terraform Editions on terraform.io.

Slide 3 text

Terraform Editions Terraform Cloud Terraform OSS Terraform Enterprise ▪ freely available ▪ broad support ▪ common binary ▪ hosted option ▪ all OSS features ▪ team management ▪ module sharing ▪ audit logging ▪ cost estimation ▪ on-prem option ▪ all Cloud features ▪ team management ▪ module sharing ▪ audit logging

Slide 4

Slide 4 text

Building Modules for HashiCorp Terraform

Slide 5

Slide 5 text

Building Modules TERMINAL > mkdir ./terraform-aws-cf-website

Slide 6

Slide 6 text

TERMINAL > mkdir ./terraform-aws-cf-website Building Modules

Slide 7

Slide 7 text

TERMINAL > mkdir ./terraform-aws-cf-website Building Modules

Slide 8

Slide 8 text

Building Modules TERMINAL > tree ./terraform-aws-cf-website . ├── main.tf ├── outputs.tf └── variables.tf

Slide 9

Slide 9 text

Building Modules TERMINAL > tree ./terraform-aws-cf-website . ├── examples/ ├── LICENSE ├── main.tf ├── outputs.tf ├── README.md ├── tests/ └── variables.tf

Slide 10

Slide 10 text

Writing Modules MAIN.TF resource "aws_cloudfront_distribution" "this" { comment = var.comment enabled = var.enabled default_cache_behavior { ... } origin { ... } }

Slide 11

Slide 11 text

Writing Modules VARIABLES.TF variable "enabled" { type = bool description = "Toggle to enable CF Distribution" default = true } variable "comment" { type = string description = "Comment for CloudFront Distribution" default = "Terraform-managed" }

Slide 12

Slide 12 text

Writing Modules OUTPUTS.TF output "arn" { value = aws_cloudfront_distribution.this.arn description = "ARN of the CloudFront Distribution" }

Slide 13

Slide 13 text

Documenting Modules README.MD ### Inputs | Name | Description | Type | Default | |-----------|-------------------|----------|-------------------| | `comment` | Comment for [...] | `string` | Terraform-managed | | `enabled` | Toggle to [...] | `bool` | `true` | ### Outputs | Name | Description | |-------|------------------------------------| | `arn` | ARN of the CloudFront Distribution |

Slide 14

Slide 14 text

Using Modules EXAMPLE.TF module "my_website" { source = "aws-quickstart/cf-website/aws" }

Slide 15

Slide 15 text

Using Modules EXAMPLE.TF module "my_website" { source = "../.." }

Slide 16

Slide 16 text

Using Modules EXAMPLE.TF module "my_website" { source = "[email protected]/aws-quickstart/website" }

Slide 17

Slide 17 text

Using Modules EXAMPLE.TF module "my_website" { source = "aws-quickstart/cf-website/aws" version = "1.0.0" comment = "CF Website for example.com" enabled = true } output "my_website_arn" { value = module.my_website.arn }

Slide 18

Slide 18 text

Publishing Modules for HashiCorp Terraform

Slide 19

Slide 19 text

Tagging Modules TERMINAL > git tag "1.0.0"

Slide 20

Slide 20 text

Tagging Modules github.com/aws-quickstart/terraform-aws-cf-website

Slide 21

Slide 21 text

Publishing Modules registry.terraform.io/

Slide 22

Slide 22 text

Publishing Modules registry.terraform.io/github/create

Slide 23

Slide 23 text

registry.terraform.io/namespaces/aws-quickstart

Slide 24

Slide 24 text

Publishing Modules registry.terraform.io/modules/aws-quickstart/cf-website

Slide 25

Slide 25 text

AWS Terraform Modules Program

Slide 26

Slide 26 text

Modules Program ▪ collab between HashiCorp and AWS IA team ▪ empowers SAs and engineers to build modules ▪ codifies best-practices for common workflows

Slide 27

Slide 27 text

https://registry.terraform.io/namespaces/aws-quickstart

Slide 28

Slide 28 text

Tips and Tricks

Slide 29

Slide 29 text

Tips and Tricks ▪ do one thing well ▪ think about composability ▪ bad documentation is a bug

Slide 30

Slide 30 text

Materials ▪ slides: speakerdeck.com/ksatirli/reusable-infrastructure-with-terraform ▪ tutorial: learn.hashicorp.com/collections/terraform/modules ▪ docs generator: terraform-docs.io

Slide 31

Slide 31 presenter notes

Slide 31 text

Mary Cutrali (She/Her) Product Manager at HashiCorp

Slide 32

Slide 32 presenter notes

Slide 32 text

@maryelizbeth on GitHub Product Manager at HashiCorp

Slide 33

Slide 33 presenter notes

Slide 33 text

Kerim Satirli (He / Him) Sr. Developer Advocate at HashiCorp

Slide 34

Slide 34 presenter notes

Slide 34 text

@ksatirli on Twitter and GitHub Sr. Developer Advocate at HashiCorp

Slide 35

Slide 35 text