Running Terraform
Once Terraform is installed and you have initialized a configuration,
you can run its command line interface (CLI) while developing and using that configuration.
The Terraform CLI
is invoked with the terraform
command,
followed by one of its many sub-commands.
We have already used the terraform init
sub-command.
Here are the other major sub-commands that will be used throughout this topic:
-
terraform plan
assesses the configuration that is specified by your.tf
files and compares that specification to the current state of the deployment on your cloud platform. If there are differences between the two, it evaluates the dependencies between the objects in your configuration to come up with a plan for updating your cloud platform deployment to match your configuration. It then outputs a list of all the steps it thinks must be taken, but does not actually perform them. This command is very useful for safely checking the validity of your configuration code. -
terraform apply
performs the same planning step asterraform plan
, displaying the list of steps it is prepared to take. It then prompts you to approve the plan before it executes it. If Terraform encounters any errors while executing the plan, it displays messages in your terminal. When it finishes executing the plan, it updates the current state of your configuration to match the deployment. This information is kept in the fileterraform.tfstate
in your configuration directory and is used when the next planning operation is performed. Note that if you alter the state of your cloud deployment by other means (such as through the web interface for the OpenStack CLI), your configuration's state information may become out of date and cause your next Terraform plan to be wrong. -
terraform destroy
reverses the work done byterraform apply
, tearing down whatever cloud platform objects were created by deploying your configuration. As with applying the configuration, Terraform determines a set of steps it will take, asks for your approval, and then executes those steps. Error messages are displayed in the terminal and the configuration state is updated afterwards. This command provides an often overlooked benefit of using an orchestration system - easy, fast and complete cleanup after your work in the cloud.
You will be using these three commands in the remaining topics of this roadmap as you explore the example configuration.
©
|
Cornell University
|
Center for Advanced Computing
|
Copyright Statement
|
Access Statement
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)