Complete the code to define a virtual network with an address space.
resource "azurerm_virtual_network" "example" { name = "example-vnet" location = "eastus" resource_group_name = "example-resources" address_space = ["[1]"] }
The address space defines the IP range for the virtual network. "10.0.0.0/16" is a common private IP range used for VNets.
Complete the code to define a subnet within the virtual network.
resource "azurerm_subnet" "example_subnet" { name = "example-subnet" resource_group_name = "example-resources" virtual_network_name = azurerm_virtual_network.example.name address_prefixes = ["[1]"] }
The subnet address prefix must be a subset of the virtual network's address space. "10.0.1.0/24" fits inside "10.0.0.0/16".
Fix the error in the subnet address prefix to be valid within the VNet.
resource "azurerm_subnet" "wrong_subnet" { name = "wrong-subnet" resource_group_name = "example-resources" virtual_network_name = azurerm_virtual_network.example.name address_prefixes = ["[1]"] }
The subnet prefix must be within the VNet's address space (10.0.0.0/16). "10.0.2.0/24" is valid, while others are either too large or outside the range.
Fill both blanks to define a subnet with network security group association.
resource "azurerm_subnet" "secure_subnet" { name = "secure-subnet" resource_group_name = "example-resources" virtual_network_name = azurerm_virtual_network.example.name address_prefixes = ["[1]"] network_security_group_id = azurerm_network_security_group.example.[2] }
The subnet address prefix must be within the VNet range, here "10.0.3.0/24". The network security group ID property is "id" to link the NSG resource.
Fill all three blanks to define a virtual network with two subnets.
resource "azurerm_virtual_network" "multi_subnet_vnet" { name = "multi-subnet-vnet" location = "eastus" resource_group_name = "example-resources" address_space = ["[1]"] } resource "azurerm_subnet" "subnet1" { name = "subnet1" resource_group_name = "example-resources" virtual_network_name = azurerm_virtual_network.multi_subnet_vnet.name address_prefixes = ["[2]"] } resource "azurerm_subnet" "subnet2" { name = "subnet2" resource_group_name = "example-resources" virtual_network_name = azurerm_virtual_network.multi_subnet_vnet.name address_prefixes = ["[3]"] }
The VNet address space is "10.1.0.0/16". The two subnets must have prefixes inside this range, such as "10.1.1.0/24" and "10.1.2.0/24".