Terraform:
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.
Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied.
Terraform Installation:
curl -O https://releases.hashicorp.com/terraform/0.13.2/terraform_0.13.2_linux_amd64.zip
sudo unzip terraform_0.13.2_linux_amd64.zip -d /usr/local/bin/
rm terraform_0.13.2_linux_amd64.zip
You select the latest version of using above link terraform link, right now the latest version is 13.2
Version:
$ terraform --version
Terraform v0.13.2Terraform Prerequisites:
You need to set Cloud credentials depends on the cloud you are using.
$ export ALI_ACCESS_KEY_ID="ali_access_key"
$ export ALI_SECRET_ACCESS_KEY="ali_secret_key"
$ export ALI_DEFAULT_REGION="eu-west-1"
Terraform Commands:
After writing the terraform below is the first command to execute to initialize a working directory containing terraform configuration files. It is safe to run multiple times.
$ terraform init
Plan:
$ terraform plan -out plan.out
or
$ terraform plan
It's an important feature of terraforming that allows a user to see which actions Terraform will perform prior to making any changes,
$ terraform apply plan.out
or
$ terraform apply
or
$ terraform apply -out-approve
It will apply the changes to the instances.
Define variable while applying the changes
$ terraform apply -out-approve -var tags-repository_url=${git_url}
Destroy:
$ terraform destroy
Which will delete all the resources that have been created
If I want to destroy one resource
$ terraform destroy -target bucket_name
Validate:
The validate command is used to validate/check the syntax of the terraform files.
$ terraform validate
Providers:
The terraform providers command prints information about the providers used in the current configuration
$ terraform providers
You and add plugins using terraform.tf file as shown below.
A provider configuration is created using a provider block:
provider "alicloud"{
version: "1.58.0"
}
In this example, I have updated the alicould provider version to 1.58.0.