The document outlines essential Terraform CLI commands and their purposes, including initialization, planning, applying changes, and destroying infrastructure. It explains the functions of commands like terraform init, plan, apply, validate, and output, as well as how to manage state and resources. Additionally, it covers formatting code, upgrading providers, and enabling verbose logging.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
6 views
Terraform CLI Commands QA
The document outlines essential Terraform CLI commands and their purposes, including initialization, planning, applying changes, and destroying infrastructure. It explains the functions of commands like terraform init, plan, apply, validate, and output, as well as how to manage state and resources. Additionally, it covers formatting code, upgrading providers, and enabling verbose logging.
- terraform init – Initializes a working directory - terraform plan – Shows what will be created/changed/destroyed - terraform apply – Applies the changes to reach desired state - terraform destroy – Destroys all managed infrastructure - terraform validate – Checks syntax of Terraform files - terraform fmt – Formats .tf files for readability - terraform output – Displays output values - terraform providers – Lists required and used providers
2. What does terraform init do?
Initializes the current directory by: - Downloading provider plugins - Setting up backend configuration - Preparing the workspace for use
3. What is the purpose of terraform plan?
Generates and shows an execution plan of what Terraform will do, without making changes. Useful for reviewing changes before applying them.
4. What is the difference between terraform apply and terraform plan?
Command | Purpose | Changes Infrastructure
----------------|----------------------------------|-------------------------- terraform plan | Previews changes | No terraform apply | Executes the planned changes | Yes
5. What does terraform destroy do?
It removes all infrastructure managed by Terraform. Use with caution to delete all resources.
6. What does terraform validate check?
Checks whether the Terraform configuration is syntactically valid but does not check resource existence.
7. How do you format Terraform code?
Use: terraform fmt This reformats .tf files to a canonical style.
8. What does terraform output do?
Displays the values of output variables from your configuration, useful for extracting results. Example: terraform output vpc_id
9. How can you upgrade providers to the latest version?
Use: terraform init -upgrade
10. What does terraform state command do?
It inspects or modifies the Terraform state. Example subcommands: - terraform state list – Lists all resources in the state - terraform state show – Shows attributes of a resource - terraform state rm – Removes a resource from state (not from cloud) 11. How do you taint a resource in Terraform? Use: terraform taint <resource_name> Marks a resource for recreation on the next apply.
12. What does terraform import do?
Brings existing infrastructure into Terraform management without changing it: terraform import aws_instance.example i-1234567890abcdef0
13. What is terraform graph used for?
Generates a visual dependency graph of Terraform resources (in DOT format for visualization tools).
14. How do you remove a resource from Terraform without deleting it in the cloud? Use: terraform state rm <resource_name>
15. How do you enable verbose logging in Terraform?