Skip to main content

Terraform

  • Backend: gcp support locking by default, but s3 need dynamoDb for locking
  • module output can be used as variable referenc

Loop and conditions

  • List comprehension: [for name in var.names : upper(name)] if lenght(name) < 5, upcase all items in list
  • Map comprehension: [for name, role in var.heros : "${name} is the ${role}"]
  • Go template string for loop: %{~ for name in var.name } ${name} %{~ endfor }
  • Terraform(0.12) don't support if, but suppor ternary syntax
    • count = var.enable_autoscaling ? 1 : 0
    • count = format("%.1s", var.instance_type) == "t" ? 1 : 0
  • Terraform does lazy evaluation for conditional results, so the true value will be evaluated only if the condition was true and the false value will be evaluated if the condition was false.

TO LEARN