Terraform and its basic commands
Introduction to Terraform
Terraform is defined by HashiCorp, the creator of Terraform, as a tool for building, changing, and versioning infrastructure safely and efficiently. That sounds like an infrastructure as code solution, because Terraform is an infrastructure as code solution.Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can help with multi-cloud by having one workflow for all clouds. The infrastructure Terraform manages can be hosted on public clouds like Amazon Web Services, Microsoft Azure, and Google Cloud Platform, or on-prem in private clouds such as VMWare vSphere, OpenStack, or CloudStack.
Features of terraform
The key features of Terraform are:
Infrastructure as code
Infrastructure is described using a high-level configuration syntax. This allows a blueprint of your datacenter to be versioned and treated as you would any other code. Additionally, infrastructure can be shared and re-used.
Execution plans
Terraform has a “planning” step where it generates an execution plan. The execution plan shows what Terraform will do when you call apply. This lets you avoid any surprises when Terraform manipulates infrastructure.
Change Automation
Complex change sets can be applied to your infrastructure with minimal human interaction. With the previously mentioned execution plan and resource graph, you know exactly what Terraform will change and in what order, avoiding many possible human errors.
Five Commands of terraform are as follows:
1. Terraform show: The terraform show command is used to provide human-readable output from a state or plan file. This can be used to inspect a plan to ensure that the planned operations are expected, or to inspect the current state as Terraform sees it.
Command: terraform show -json This will show the output in JSON representation of the state.
2. Terraform get: The terraform get command is used to download and update modules mentioned in the root module.
Command: terraform get [options] [dir]
3. Terraform providers: The terraform providers command prints information about the providers used in the current configuration. This command gives an overview of all of the current dependencies, as an aid to understanding why a particular provider is needed.
Command: terraform providers [config-path]
4 .Terraform plan: The terraform plan command is used to create an execution plan. Terraform performs a refresh, unless explicitly disabled, and then determines what actions are necessary to achieve the desired state specified in the configuration files.
Command: terraform plan [options] [dir]
5. Terraform apply: The terraform apply command is used to apply the changes required to reach the desired state of the configuration, or the pre-determined set of actions generated by a terraform plan execution plan.
Command: terraform apply [options] [dir]