AzureCode01-InfraSetup - To setup RG, Vnet, Subnet, NIC, NSG, Public IP, VM by dynacally providing resource group name.
📝 .\INFRA01\backend-config-infra01.hcl
---------------------------------------------------------------------------------------------------
# ✅ Update the values to be used to backend configuration.
# ⚠️ This is pre-requisite to execute the code.
# ❌ If the below resources are not present in the Azure Cloud, the terraform code will ❌ FAIL.
resource_group_name = <ENTER backend - Resource Group> # Example: "rg-backend"
storage_account_name = <ENTER backend - Storage Account> # Example: "storageaccount"
container_name = <ENTER backend - Storage Container Name> # Example: "storagecontainer"
key = <ENTER backend - State File Name> # Example: "a.terraform.tfstate"
📝 infra01.auto.tfvars
---------------------------------------------------------------------------------------------------
# ✅ Update this with your own subscription ID.
main_provider_subscription_id = "00000000-0000-0000-00000000"
📝 infra01.auto.tfvars
---------------------------------------------------------------------------------------------------
# ✅ Update this with your own Azure region.
root_resource_location = "East US"
# ✅ Update this with your own VNet address space.
root_vnet_address_space = ["46.87.0.0/24"]
# ✅ Update this with your own subnet address prefixes.
root_subnet_address_prefixes = ["46.87.0.0/28"]
terraform init -backend-config='backend-config-infra01.hcl'
terraform validate
terraform plan
terraform apply
# ❌ Do Not run terraform apply -auto-approve
PS D:\TerraformCode\AzureCode01-InfraSetup\INFRA01> terraform apply
Acquiring state lock. This may take a few moments...
var.user_prefix
Enter an 8-character alphanumeric prefix for the resource names.
✅ Example Valid Inputs:
>> lion1234 ✅ (valid)
>> eagle987 ✅ (valid)
❌ Invalid Inputs:
>> 123abcdz ❌ (starts with a number)
>> abc123 ❌ (less than 8 characters)
>> abcdefgh9 ❌ (too long)
Enter a value: lion9876 # ✅ User enters 8 character alphanumeric value
Apply complete! Resources: 8 added, 0 changed, 0 destroyed.
Outputs:
root_output_virtual_machine_password = "lion9876-Pass1@" # ⚠️ For training purpose only. # ❌ Not recommended to use a hardcoded password in production. 🔐
root_output_virtual_machine_username = "lion9876-User1" # ⚠️ For training purpose only. # ❌ Not recommended to use a hardcoded username in production. 🔐
root_output_public_ip = "17.x.x.x" # ⚠️ For information purpose only.
root_output_resource_group_name = "rg-lion9876" # ✅ Resource group created with 'rg-' as prefix and user input as suffix.
root_output_virtual_machine = "lion9876-VM" # ✅ Virtual Machine user input as prefix and '-VM' as suffix.