Skip to content
Dom Clayton edited this page Feb 17, 2022 · 15 revisions

Fundamentals

Terraform Commands

Authentication

Local Development

Local authentication

# Login using Azure CLI
az login

# What is the default subscription?
az account show -o table

# List Subscriptions
az account list -o table

# Set subscription
az account set --subscription="SubscriptionId"

MSI authentication

SP authentication

Terraform state

Terraform state contains all resources Terraform knows about in your particular environment. To show the current state use:

terraform state list -state="/home/path/to/the/state/file"

for example

terraform state list -state="/home/domc/mysource/Terraform/OpenVPN/Learning/terraform.tfstate"

NOTE Messed up state by running Terraform init, then removing code which initialised a provider...use

terraform state rm -state="/home/path/to/the/state/file" state address

for example

terraform state rm -state="/home/domc/mysource/Terraform/OpenVPN/Learning/terraform.tfstate data.http.myIp"

Importing resources into Terraform state

terraform import -state="/home/path/to/the/state/file" resourcetype.resourcename application_id

for example

terraform import -state=/home/domc/mysource/Terraform/vNetGateway/Test/terraform.tfstate azuread_application.AzureVPN 00000000-0000-0000-0000-000000000000

Clone this wiki locally