Versioning
The required_version setting can be used to constrain which version of the Terraform CLI can be used with your configuration. If the running version of Terraform doesn't match the constraints specified, Terraform will produce an error and exit without taking any further actions.
terraform {
required_version = ">= 0.12"
}
We can also specify a provider version requirement
provider "aws" {
region = "us-east-1"
version = ">= 2.9.0"
}
We can also specify a provider version requirement
provider "aws" {
region = "us-east-1"
version = ">= 2.9.0"
}
Terraform Workflow
Terraform Init
The terraform init command is used to initialise a working directory containing Terraform configuration files.
During init, the configuration is searched for module blocks, and the source code for referenced modules is retrieved from the locations given in their source arguments. Terraform must initialize the provider before it can be used. Initialization downloads and installs the provider’s plugin so that it can later be executed.
Initializes the backend configuration. It will not create any sample files like example.tf
Terraform plan
The terraform plan command is used to create an execution plan. It will not modify things in infrastructure.
Terraform performs a refresh, unless explicitly disabled, and then determines what actions are necessary to achieve the desired state specified in the configuration files.
This command is a convenient way to check whether the execution plan for a set of changes matches your expectations without making any changes to real resources or to the state.
Terraform Apply
The terraform apply command is used to apply the changes required to reach the desired state of the configuration. Terraform apply will also write data to the terraform.tfstate file.
Once the application is completed, resources are immediately available.
Terraform Refresh
The terraform refresh command is used to reconcile the state Terraform knows about (via its state file) with the real-world infrastructure. This does not modify infrastructure but does modify the state file.
Terraform Destroy
The terraform destroy command is used to destroy the Terraform-managed infrastructure. terraform destroy command is not the only command through which infrastructure can be destroyed.
You can remove the resource block from the configuration and run terraform apply this way you can destroy the infrastructure.
Terraform Validate
The terraform validate command validates the configuration files in a directory. Validate runs checks that verify whether a configuration is syntactically valid and thus primarily useful for general verification of reusable modules, including the correctness of attribute names and value types.
It is safe to run this command automatically, for example, as a post-save check in a text editor or as a test step for a reusable module in a CI system. It can run before the terraform plan. Validation requires an initialized working directory with any referenced plugins and modules installed
That's a wrap......