Terraform is an open-source infrastructure as code software tool created by HashiCorp. Users define and provide data center infrastructure using a declarative configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON. OpenTofu is a fork of Terraform and a fully open-source successor.
Project Layout
To see a typical Terraform project layout we can use tree command:
tree
. ├── README.md ├── main.tf ├── nginx │ ├── main.tf │ ├── variables.tf │ └── versions.tf └── versions.tf
- versions.tf: Specifies the providers (like Docker, Kubernetes etc) and versions used
- main.tf: specificies the resources that need to be created (could be containers, virtual machines etc.
- variables.tf: holds the variables (like username, password or default config like hard disk size or amount of CPUs)
Terraform Command Line Interface
To start, we need to issue the init command which will initialise the provider plugins.
terraform init
Then we need to validate the config:
terraform validate