Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reusable Infrastructure with Terraform

Reusable Infrastructure with Terraform

In this workshop, Mary Cutrali (Product Manager at HashiCorp) and I give an overview on how to build reusable infrastructure components using HashiCorp Terraform.

This version of the presentation was given at an AWS-internal summit in April 2021.

Avatar for Kerim Satirli

Kerim Satirli

April 29, 2021
Tweet

More Decks by Kerim Satirli

Other Decks in Technology

Transcript

  1. 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
  2. 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
    Learn more about Terraform Editions on <a href="https://www.terraform.io/docs/cloud/paid.html">terraform.io</a>.
  3. Building Modules TERMINAL > tree ./terraform-aws-cf-website . ├── examples/ ├──

    LICENSE ├── main.tf ├── outputs.tf ├── README.md ├── tests/ └── variables.tf
  4. Writing Modules MAIN.TF resource "aws_cloudfront_distribution" "this" { comment = var.comment

    enabled = var.enabled default_cache_behavior { ... } origin { ... } }
  5. 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" }
  6. 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 |
  7. 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 }
  8. Modules Program ▪ collab between HashiCorp and AWS IA team

    ▪ empowers SAs and engineers to build modules ▪ codifies best-practices for common workflows
  9. Tips and Tricks ▪ do one thing well ▪ think

    about composability ▪ bad documentation is a bug
  10. Find me on <a href="https://twitter.com/maryelizbeth">twitter.com/maryelizbeth</a>.
  11. Find me on <a href="https://twitter.com/maryelizbeth">twitter.com/maryelizbeth</a>.
  12. Find me on <a href="https://twitter.com/ksatirli">twitter.com/ksatirli</a>.
  13. Find me on <a href="https://twitter.com/ksatirli">twitter.com/ksatirli</a>.