DevOps Rich DevOps content for Infrastructure Engineers

Terraform Commands

Remote State Storage & Locking


  backend "azurerm" {
    resource_group_name   = "rg1"
    storage_account_name  = "sta1"
    container_name        = "tfstatefiles"
    key                   = "terraform.tfstate"
  } 

Remote State Data Source

data "terraform_remote_state" "Project-1" {
  backend = "azurerm"
  config = {
    resource_group_name   = "rg1"
    storage_account_name  = "sta1"
    container_name        = "tfstatefiles"
    key                   = "terraform.tfstate"
  }
}
resource_group_name = data.terraform_remote_state.Project-1.outputs.resource_group_name

State Commands

Import

Debug

Note: The typical format of $env:TF_VAR_<variable_name>=value that is the equivalent to .tfvars does not apply.


$env:TF_LOG='TRACE'
$env:TF_LOG_PATH='terraform-trace.log'
Dir env:

CLI User Settings

Initializing provider plugins...
- Reusing previous version of hashicorp/external from the dependency lock file
- Reusing previous version of hashicorp/azurerm from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Using previously-installed hashicorp/external v2.2.0
- Using previously-installed hashicorp/azurerm v2.93.1
- Using previously-installed hashicorp/random v3.1.0

Terraform has been successfully initialized!

Manage Providers