Skip to content
Go back

Terraform Quick Notes

Table of contents

Open Table of contents

Inheritance

There is no implicit inheritance. Things do not inherit from each other. In essence, imagine a bunch of blocks and those blocks can only communicate but attaching them to each other.

Module Definition

Consider the following snippet”

module "this" {
  selfdefined = "hi"
  enabled = var.enabled
  ...
}

We have a defined a variable here; selfdefined. Defined locally within the module.

But we can also define it separately enabled in a variable file as is convention. The variables.tf using the keyword variable adds variables to the variable namespace which is scoped to the module the file belongs to.

Variable Resolution Order

  1. -var CLI flags
terraform apply -var="enabled=false"
terraform apply -var-file=prod.tfvars
  1. Auto-loaded tfvars
  1. Environmental variables
export TF_VAR_enabled=false
  1. Default value In the terraform code; if not present, an error will be thrown

Module Intercommunication

The major thing to understand is that implicit sharing is impossible. A child modules can NEVER access a variable, resource, or state from its parents or sibling modules without explicitly beging passed.

That means


Share this post on:

Previous Post
Base64Encoding
Next Post
Yaml