Terraform
Terraform is an open-source IaC (Infrastructure-as-Code) tool for configuring and deploying cloud infrastructure. It codifies infrastructure in configuration files that describe the desired state for your topology. Terraform allows you to use a consistent workflow over your infrastructure lifecycle, regardless of the resource provider. The infrastructure as code workflow lets you declaratively manage a variety of services and automate your changes to them, reducing the risk of human error through manual operations.
Advantages
- IAC is crucial because it helps to speed the deployment and release of the software.
- Terraforms support provides multi-cloud platforms like AWS, AZURE, Google, etc.
- IAC assists in restricting users from deleting resources accidentally.
- Provide a template to write code and use it many times.
- Unified templates also provide security.
Workflows
In HCP Terraform, your resources are organized by workspaces, which contain your resource definitions, environment and input variables, and state files. A Terraform operation occurs within a workspace, and Terraform uses the configuration and state for that workspace to modify your infrastructure.
HCP Terraform supports three workflows for your Terraform runs.
- The CLI-driven workflow uses Terraforms standard CLI tools to execute runs in HCP Terraform.
- The UI/Version Control System(VCS)-driven workflow, in which changes pushed to version control repositories trigger runs in the associated workspace.
- The API-driven workflow allows you to create tooling to interact with the HCP Terraform API programmatically.
Terraform Basic command
- Init: Validate working directory consisting of terraform config file. This is the first command to be executed after writing a new file.
- Validate: Check for syntax and validate the config file.
- Plan: Create an execution plan.
- Apply: Apply changes and execute the command to create resources.
- Destroy: Remove terraform managed resources. It will ask for confirmation before removing resources.