Writing a Terraform Module: Difference between revisions
Jump to navigation
Jump to search
Line 29: | Line 29: | ||
** <code>main.tf</code> - this must contain all nested module calls, if any. | ** <code>main.tf</code> - this must contain all nested module calls, if any. | ||
** <code>variables.tf</code> - this must contain [[Hashicorp_Configuration_Language#Input_Variable|input variable]] declarations. | ** <code>variables.tf</code> - this must contain [[Hashicorp_Configuration_Language#Input_Variable|input variable]] declarations. | ||
** <code>outputs.tf</code> - this must contain outputs. | ** <code>outputs.tf</code> - this must contain [[Hashicorp_Configuration_Language#Output_Variable|outputs]]. | ||
* For a complex module, resource creation may be split into multiple files, but '''any nested module calls should be in the main file'''. | * For a complex module, resource creation may be split into multiple files, but '''any nested module calls should be in the main file'''. |
Revision as of 01:43, 14 November 2019
External
Internal
Reference Example
- https://registry.terraform.io/modules/hashicorp/consul/aws/0.7.3
- https://github.com/hashicorp/terraform-aws-consul
Playground
Procedure
To define a module, create a new root directory for it and place one or more .tf files inside it.
Standard Structure
Everything is optional, except for the root module:
- Root module - this is the only required element for the standard module structure, and it consists in .tf files - which must exist - in the root directory of the module.
- README or README.md. Should contain a description of the module. Examples can be included in an example directory.
- LICENSE
- Recommended file (they should exist even if they are empty):
main.tf
- this must contain all nested module calls, if any.variables.tf
- this must contain input variable declarations.outputs.tf
- this must contain outputs.
- For a complex module, resource creation may be split into multiple files, but any nested module calls should be in the main file.