Terraform CLI cheat sheet
|
terraform fmt
|
Formats Terraform configuration files to a canonical format.
|
|
terraform validate
|
Validates the syntax and configuration of Terraform files.
|
|
terraform init
|
Initializes the working directory containing Terraform configuration files.
|
|
terraform init -upgrade
|
Updates provider plugins to the latest versions.
|
|
terraform plan
|
Generates an execution plan showing what Terraform will do.
|
|
terraform apply
|
Applies the changes required to reach the desired state.
|
|
terraform destroy
|
Destroy all remote objects managed.
|
|
terraform version
|
Displays the Terraform version information.
|
|
terraform console
|
Opens an interactive console to evaluate Terraform expressions.
|
|
terraform graph
|
Generates a visual representation of Terraform resources and dependencies.
|
provider "azurerm" {
features {}
subscription_id = "<subscription_id>"
client_id = "<application_id>"
client_secret = "<secret_value>"
tenant_id = "<tenant_id>"
}
terraform {
backend "azurerm" {
resource_group_name = "<resource_group_name>"
storage_account_name = "<storage_account_name>"
container_name = "<container_name>"
key = "<state_file_key>"
access_key = "<storage_account_access_key>"
}
}
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> x.xx.x "
}
}
}
|
terraform state list
|
Lists all resources in the Terraform state.
|
|
terraform state show <resource>
|
Shows the attributes of a specific resource in the Terraform state.
|
|
terraform state rm <resource>
|
Removes a resource from the Terraform state.
|
|
terraform state mv <old-resource> <new-resource>
|
Moves a resource within the Terraform state.
|
|
terraform init -backend-config=<config>
|
Initializes Terraform with a specific backend configuration.
|
|
terraform remote config
|
Configures remote state storage.
|
|
terraform remote pull
|
Retrieves the current state from the remote backend.
|
|
terraform remote push
|
Uploads the local state to the remote backend.
|
|
-upgrade
|
Opt to upgrade modules and plugins
|
|
-reconfigure
|
Disregards any existing configuration and state.
|
|
-input=true|false
|
Ask for input if necessary. If false, will error if input was required.
|
|
-no-color
|
Disable text coloring & formatting in the output.
|
|
-var 'NAME=VALUE'
|
Sets a value for a single input variable.
|
|
-var-file=FILENAME
|
Sets values for variables as TFVARS.
|
|
-target=ADDRESS
|
Focus its efforts only on specific resource instance.
|
moved {
from = azurerm_resource_group.example.rg01
to = azurerm_resource_group.example.rg02
}
import {
to = azurerm_resource_group.example.rg03
id = /subscriptions/<subscription_id>/resourceGroups/<resource_group_name>
}
removed {
from = azurerm_resource_group.example.rg02
lifecycle {
destroy = false
}
}
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.