i wanted to update my exsiting subnet in Terraform, firstly i did this command
terraform import 'azurerm_subnet.example' /subscriptions/id-id-id-id/resourceGroups/tfeastus/providers/Microsoft.Network/virtualNetworks/myVnetTF/subnets/SUBNET-0
the import was successfull, so i made my terraform template
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>2.0"
}
}
}
provider "azurerm" {
features {}
}
variable "vnetName" {
type = string
}
variable "location" {
type = string
}
variable "resource_group_name" {
type = string
}
variable "subnetName" {
type = string
}
data "azurerm_virtual_network" "vnet" {
name = var.vnetName
location = var.location
resource_group_name = var.resource_group_name
}
resource "azurerm_subnet" "example" {
name = var.subnetName
resource_group_name = var.resource_group_name
virtual_network_name = var.vnetName
delegation {
name = "delegation"
service_delegation {
name = "Microsoft.Web/serverFarms"
}
}
}
Although, after terraform apply i get an error saying that │ "address_prefix": one of
address_prefix,address_prefixes must be specified
. If i already imported the subnet, and it is in the terraform.tfstate
why do i have to provide an already existing address_prefix?
2
Answers
address_prefixes is a required attribute. You have to specify it.