ToolDescription
TerragruntTerragrunt is a thin wrapper for Terraform that provides extra tools
TerracostCloud cost estimation for Terraform in your CLI
InfracostCloud cost estimates for Terraform in pull requests
TFLintTerraform Linter

Instalation

# Download
TER_VER=`curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'`
wget https://releases.hashicorp.com/terraform/${TER_VER}/terraform_${TER_VER}_linux_amd64.zip
 
# Unzip
unzip terraform_${TER_VER}_linux_amd64.zip
sudo mv terraform /usr/local/bin/
  • Display graph
export TF_VAR_rds_password=foobarbaz
terraform graph | dot -Tpng > infrastructure_graph.png
  • Terraform destroy AWS ECS
terraform destroy -target=aws_ecs_service.backend -target=aws_ecs_task_definition.backend -target=module.vpc.aws_eip.nat -target=aws_lb.lb -target=aws_autoscaling_group.ecs-cluster

OpenTF

OpenTofu is an OSS tool for building, changing, and versioning infrastructure safely and efficiently. OpenTofu can manage existing and popular service providers as well as custom in-house solutions.

Commands

Format and Validate

CommandDescription
terraform initPrepare your working directory for other commands
terraform fmtReformat your configuration in the standard style
terraform validateCheck whether the configuration is valid

Plan and apply

CommandDescription
terraform apply --auto-approveCreate or update infrastructure without confirmation prompt
terraform destroy --auto-approveDestroy previously-created infrastructure without confirmation prompt
terraform plan -out plan.outOutput the deployment plan to plan.out
terraform apply plan.outUse the plan.out to deploy infrastructure
terraform plan -destroyOutputs a destroy plan
terraform apply -target=aws_instance.myinstanceOnly apply/deploy changes to targeted resource
terraform apply -var myregion=us-east-1Pass a variable via CLI while applying a configuration
terraform apply -lock=trueLock the state file so it can’t be modified
terraform apply refresh=falseDo not reconcile state file with real-world resources
terraform apply --parallelism=5Number of simultaneous resource operations
terraform refreshReconcile the state in Terraform state file with real-world resources
terraform providersGet informatino about providers used in the current configuration

Workspaces

CommandDescription
terraform workspace new <workspace>Create a new workspace
terraform workspace select defaultChange to a workspace
terraform workspace listList all workspaces

State Manipulation

CommandDescription
terraform state show aws_instance.myinstanceShow details stored in the Terraform state file
terraform state pull > terraform.tfstateOutput Terraform state to a file
terraform state mv aws_iam_role.my_ssm_role module.mymoduleMove a resource tracked via state to different module
terraform state replace-provider hashicorp/aws registry.custom.com/awsReplace an existing provider with another
terraform state listList all resources tracked in the Terraform state file
terraform state rm aws_instance.myinstanceUnmanage a resource, delete it from the Terraform state file

Import and Outputs

CommandDescription
terraform import <resource_type>.<resource> <id>Import a Resource
terraform outputList all outputs
terraform output <output>List a specific output
terraform output -jsonList all outputs in JSON format