Project structure
File types
main.tf
Starting point of the IaC logic, mainly containing resources.
variables.tf
- Defines
variablesused in config - Be referenced in
main.tfas${var.variable_name}
provider.tf
Declares the provider to be used for the configuration.
output.tf
Defines output values which show information about the resources created.
Modules
- Start writing your configuration with a plan for
modules. - Use local
modulesto organize and encapsulate your code. - Use the public
Terraform Registryto find usefulmodules.
States
-
Backend-
Instead of using version control, the best way to
manage shared storageforstatefiles is to useTerraform’s built-in support for remotebackends. -
A
Terraformbackenddetermines howTerraformloads and storesstate. -
The default
backendis the localbackend, which stores thestatefile on yourlocal disk. -
Caveats
- In the case of
AWS, becauseS3 bucketandDynamoDB tablemust be created beforehand, so it poses a chicken-and-egg problem. Separate bootstrap steps are required.
- In the case of
-
-
Workspace
Open Questions
- How to avoid provisioning duplicate resources?