Use the Terraform CLI (outside of core workflow) Flashcards
What is command fmt?
The terraform fmt command is used to rewrite Terraform configuration
files to a canonical format and style. This command applies a subset
of the Terraform language style conventions, along with other minor
adjustments for readability.
What is the recommended approach after upgrading terraform?
The canonical format may change in minor ways between Terraform
versions, so after upgrading Terraform we recommend to proactively
run terraform fmt on your modules along with any other changes you
are making to adopt the new version.
What is the command usage?
terraform fmt [options] [DIR]
By default,
fmt
scans the current directory for configuration files. Is this true?
True
By default, fmt scans the current directory for configuration files.
If the dir argument is provided then it will scan that given
directory instead. If dir is a single dash (-) then fmt will read
from standard input (STDIN).
You are formatting the configuration files and what is the flag you should use to
see the differences?
terraform fmt -diff
You are formatting the configuration files and what is the flag you should use to
process the subdirectories as well?
terraform fmt -recursive
You are formatting configuration files in a lot of directories and you don’t want to
see the list of file changes. What is the flag that you should use?
terraform fmt -list=false
What is the command taint?
The terraform taint command manually marks a Terraform-managed
resource as tainted, forcing it to be destroyed and recreated on the
next apply.
This command will not modify infrastructure, but does modify the
state file in order to mark a resource as tainted. Once a resource is
marked as tainted, the next plan will show that the resource will be
destroyed and recreated and the next apply will implement this
change.
What is the command taint usage?
terraform taint [options] address
The address argument is the address of the resource to mark as
tainted. The address is in the resource address syntax syntax
When you are tainting a resource terraform reads the default state file
terraform.tfstate. What is the flag you should use to read from a different path?
terraform taint -state=path
Give an example of tainting a single resource?
terraform taint aws_security_group.allow_all The resource aws_security_group.allow_all in the module root has been marked as tainted.
Give an example of tainting a resource within a module?
terraform taint “module.couchbase.aws_instance.cb_node[9]”
Resource instance module.couchbase.aws_instance.cb_node[9] has been
marked as tainted.
What is the command import?
The terraform import command is used to import existing resources
into Terraform.
Terraform is able to import existing infrastructure. This allows you
take resources you’ve created by some other means and bring it under
Terraform management.
This is a great way to slowly transition infrastructure to Terraform,
or to be able to be confident that you can use Terraform in the
future if it potentially doesn’t support every feature you need
today.
What is the command import usage?
terraform import [options] ADDRESS ID
What is the default workspace name?
default
What are workspaces?
Each Terraform configuration has an associated backend that defines
how operations are executed and where persistent data such as the
Terraform state are stored.
The persistent data stored in the backend belongs to a workspace.
Initially the backend has only one workspace, called “default”, and
thus there is only one Terraform state associated with that
configuration.
Certain backends support multiple named workspaces, allowing multiple
states to be associated with a single configuration.
What is the command to list the workspaces?
terraform workspace list
What is the command to create a new workspace?
terraform workspace new