Skip to content

Terraform Input Variables Assign when prompted

Step-01: Introduction

  • Provide Input Variables when prompted during terraform plan or apply in CLI

Step-02: Input Variables Assign When Prompted

  • Add a new variable in named subnet_name without any default value.
  • As the variable doesn't have any default value when you execute terraform plan or terraform apply it will prompt for the variable.
# 6. Subnet Name: Assign When Prompted using CLI
variable "subnet_name" {
  description = "Virtual Network Subnet Name"
  type = string 

Step-03: Update Subnet Resource

# Create Subnet
resource "azurerm_subnet" "mysubnet" {
  #name                 = var.subnet_name
  name                 = "${}-${var.subnet_name}"
  resource_group_name  =
  virtual_network_name =
  address_prefixes     = [""]

Step-04: Execute Terraform Commands

# Initialize Terraform
terraform init

# Validate Terraform configuration files
terraform validate

# Format Terraform configuration files
terraform fmt

# Review the terraform plan
terraform plan

# Observation
1. Verify Resource Group Name
2. Verify Virtual Network Name
3. Verify Virtual Network Subnet Name

Step-05: Clean-Up

# Delete Files
rm -rf .terraform*