Learning Terraform
Intro to  v0.13

 

  • Changelog
  • Version Pinning
  • New Functionality - Highlights
    • Module `for_each`
    • Variable Validation
  • Exercises
  • Upgrading

Learning Terraform
Intro to  v0.13

 

Version Pinning

 

terraform {
  required_version = "~> 0.12"

  backend "s3" {
    # ... 
  }

  required_providers {
    # ... 
  }
}

Version ConStraints

 

  1. required_version = "0.12.29"
     
  2. required_version = "< 0.13",required_version = ">= 0.12.29, < 0.13", ect.
     
  3. required_version = "~> 0.12"
    • Referred to as the "pessimistic constraint operator"
    • Example: "~> 0.12" equates to ">= 0.12, < 0.13"

 

What Version are we Using?

 

terraform {
  required_version = "~> 0.12.4"
  # ...
}

A. Exclusively version 0.12.4

B. Anything greater version 0.12.4

C. Any other than version 0.12.4

D. Version 0.12.4 and up, excluding version 0.13 and above

 

What Version are we Using?

 

A. Any version below 0.14

B. Version 0.12.20 and up, including 0.14

C. Version 0.12.21 and up, excluding versions above 0.14.1

D. Version 0.12.20 and up, excluding version 0.14 and above

 

terraform {
  required_version = ">= 0.12.20, < 0.14"
  # ...
}

What Version are we Using?

 

A. Only version 0.13.1 

B. Version 0.13.1 and above

C. Any version below 0.13.1

D. Any version other than 0.13.1

 

terraform {
  required_version = "0.13.1"
  # ...
}

Version Pinning - PRO TIPS

  1. For "standard" projects:
    • ​​On larger Terraform projects -- pin a explicit version. e.g. "0.13.2"
    • On smaller Terraform projects -- use the pessimistic operator. e.g. "~> 0.13.2"
  2. ​For shared modules:
    • Pin using the "greater than" operator e.g ">= 0.12.0"​​

New in 0.13- Module For_Each

locals {
  repo_names = toset([
    "frontend",
    "backend",
    "auth",
    "payments",
    "reports",
    "notifications"
  ])
}

module "ecr" {
  for_each            = local.repos_name
  source              = "cloudposse/terraform-aws-ecr"
  version             = "0.24.0"
  
  name                = each.value
  scan_images_on_push = true
}

New in 0.13 - Module For_Each

variable "env" {
  type        = string
  description = "The name of the SDLC environment. e.g. dev, stage, prod."

  validation {
    condition     = contains(["dev", "stage", "prod"], var.env)
    error_message = "`var.env` must be a pre-approved environment name."
  }
}

New in 0.13 - INPUT VALIDATION

Whats New- Input Validation

0.13 - Exercises!

Made with Slides.com