Skip to content

Directory Structure

GlennChia edited this page Jul 12, 2021 · 2 revisions

Using the example of consumption_budget, a module has the following simplified structure in the caf_repo

├───.github
│   └───workflows
│       └───standalone-scenarios.json
├───examples
│   |───consumption_budget
│   |   └───100-consumption-budget-rg
|   |        └───configuration.tfvars
│   |───module.tf
│   └───variables.tf
│───modules
│   └───consumption_budget
│       └───resource_group
│               ├───main.tf
│               ├───output.tf
│               ├───resource_group_budget.tf
│               └───variables.tf
│───consumption_budgets.tf
│───main.tf
│───locals.combined_objects.tf
└───locals.tf

.github

  • Contains the files needed for automated tests via GitHub Actions.
  • Typically a path to the directory containing the configuration.tfvars file is inserted into the 4 files above when one of the following is added:
    • A new module is created that has a .tfvars file associated
    • Additional examples are added that have their own .tfvars file.

examples

  • Contains directories that contain the configuration.tfvars file that injects variables into the examples/variables.tf file
  • variables.tf is where the variable (typically an object) is initialized. This variable name corresponds to how it was declared in the .tfvars file
  • module.tf is where variables are injected and passed into the modules that the landingzone will initialize. This is a centralized module that controls which other modules are created based on the variables it receives from the respective .tfvars files

modules

  • Contains the definition of the resources
  • main.tf is where the providers are initialized. Typically at this level, only the aztfmod/azurecaf provider is initialized
  • output.tf is where output attributes are declared. Examples include the id which can be used in other modules that can be integrated
  • resource_group_budget.tf is where the Terraform registry resource is declared together with its attributes. The file name will depend on the resource created
  • variables.tf is where the variables are declared. These should correspond to the variables injected from the root consumption_budgets.tf file. In this case, depending on your module, the file that injects the variables could be different but should still be found in the root.

consumption_budgets.tf

  • Located in the root directory
  • This file contains the module that uses a for_each iteration to initialize the appropriate number of instances of the resource depending on the setup of the configuration.tfvars file.

main.tf

  • Where the providers are initialized. Typically at this level, the common pattern is to upgrade the version of azurerm.

locals.combined_objects.tf

  • Merges the local state and the remote state to give a combined object

locals.tf

  • Its values are directly injected from examples/module.tf

Putting them together, the diagram below illustrates the flow of variables from the configuration.tfvars file to the file containing the resource declaration.

For outputs, the diagram below illustrates the flow of outputs from the file containing the resource declaration to the locals.combined_objects.tf. The outputs are important especially if they are needed in other modules.

Clone this wiki locally