The example recipes are located in the examples/ directory. These are also used for testing the infrastructure using terratest, nonetheless, they are meant to run independently and be checked directly using vanilla terraform commands.
The example's structure is described below:
tree examples/
examples/
├── README.md
└── [module-name]/
└── [example-name]/ # e.g., default/basic or default/complete
├── README.md
├── main.tf
├── variables.tf
├── outputs.tf
├── providers.tf
├── versions.tf
├── .terraform-docs.yml
├── .tflint.hcl
└── fixtures/
├── default.tfvars
└── disabled.tfvars
# Other fixture files as neededNOTE: The parent directory
examples/includes all the examples (previously referred to as recipes). For a module nameddefault, you would typically find examples underexamples/default/basic/,examples/default/complete/, etc. Thebasicexample represents the fundamental usage of the module.
Use Justfile for doing so. The Justfile is located in the root of the repo, and it's used for running the examples. The Justfile recipes related to these examples are customizable by passing arguments directly to the just command. Key parameters include:
MODULE: The module's name (directory name undermodules/andexamples/). Default:default.EXAMPLE: The example's name (directory name underexamples/<MODULE>/). Default:basic.FIXTURE: The name of the fixture file (e.g.,default.tfvars,disabled.tfvars) located in theexamples/<MODULE>/<EXAMPLE>/fixtures/directory. Default:default.tfvars.CLEAN: Whether to clean Terraform cache files before execution. Default:false.
Common Justfile recipes to run examples:
Initialize, Validate, and Plan an Example: This command performs static analysis on the module, initializes both the module and the specified example, validates the example's configuration, and then generates a plan using the specified fixture file.
just tf-dev MODULE="default" EXAMPLE="basic" FIXTURE="default.tfvars"Full Lifecycle (Init, Validate, Plan, Apply, Destroy) of an Example:
This command executes the full lifecycle: all steps from tf-dev, followed by terraform apply and terraform destroy for the specified example and fixture.
just tf-dev-full MODULE="default" EXAMPLE="basic" FIXTURE="default.tfvars"You can find more details and other available recipes by running just --list or inspecting the Justfile directly.