Varible.tf
variable "vnet" {
type = map(any)
description = "creating rg and vmet"
default = {
"rg1" = {
vnet_name = "vnet1"
address = ["10.0.0.0/16"]
subnet_name = ["snet1", "snet2"]
subnet_address = ["10.1.0.0/24", "10.2.0.0/24"]
location = "south india"
}
}
}
main.tf
resource "azurerm_subnet" "mysubnet" {
for_each = var.vnet
name = each.value["subnet_name"]
address_prefixes = each.value["subnet_address"]
address_prefixes = each.value["subnet_address"]
virtual_network_name = each.value["vnet_name"]
resource_group_name = each.key
}
Error:
Error: Incorrect attribute value type
on main.tf line 25, in resource "azurerm_subnet" "mysubnet":
name = each.value["subnet_name"]
each.value["subnet_name"] is tuple with 2 elements
Inappropriate value for attribute "name": string required.
How to iterate to create multiple subnet ?
You have to flatten your variable first. For example:
locals {
vnet_flat = merge([
for group_name, details in var.vnet:
{for idx in range(length(details.subnet_name)):
"${group_name}-${idx}" => {
group_name = group_name
vnet_name = details.vnet_name
address = details.address
subnet_name = details.subnet_name[idx]
subnet_address = details.subnet_address[idx]
location = details.location
}
}
]...)
}
resource "azurerm_subnet" "mysubnet" {
for_each = local.vnet_flat
name = each.value.subnet_name
address_prefixes = [each.value.subnet_address]
virtual_network_name = each.value.vnet_name
resource_group_name = each.value.group_name
}
The ... is for Expanding Function Arguments.
Related
I am caught in a bit of a loop on this one. Need to provide the azure_windows_virtual_machine with a list of network interface IDs. The network interfaces are created using a separate resource block. In my variable definition for the windows vm, I provide an argument for the name[s] of said network interfaces so that we can correctly associate the nics that we want with each virtual machine. If we have 100 nics and 90 VMs, some of the VMs could get two NICs, so we want to be sure we provide some link between NIC name and VM name.
The network interface names are therefore a list(string).
I have been trying to use the values function to get the list of NIC IDs (given the names), but running into a failure: "The each object can be used only in "module" or "resource" blocks, and only when the "for_each" argument is set."
If I use a data source in the resource block, which seemed most logical, it fails too because I have a list(string) specified for the network_interface_names argument, but the data source cannot take that. It of course needs a single string. But it's never going to be a single string, it's always going to be a list (since we can have more than one NIC per VM).
I think the correct answer is to maybe create the list of IDs beforehand - trick is that it would need to almost be dynamic for each defined VM - because each VM will have a different list of network_interface_names. We therefore need to generate the new list on the fly for each VM.
Variables
variable "resource_groups" {
description = "Resource groups"
type = map(object({
location = string
}))
}
variable "virtual_networks" {
description = "virtual networks and properties"
type = map(object({
resource_group_name = string
address_space = list(string)
}))
}
variable "subnets" {
description = "subnet and their properties"
type = map(object({
resource_group_name = string
virtual_network_name = string
address_prefixes = list(string)
}))
}
variable "nic" {
description = "network interfaces"
type = map(object({
subnet_name = string
resource_group_name = string
}))
}
variable "admin_password" {
type = string
sensitive = true
}
variable "admin_user" {
type = string
sensitive = true
}
variable "windows_vm" {
description = "Windows virtual machine"
type = map(object({
network_interface_names = list(string)
resource_group_name = string
size = string
timezone = string
}))
}
INPUTS
resource_groups = {
rg-eastus-dev1 = {
location = "eastus"
}
}
virtual_networks = {
vnet-dev1 = {
resource_group_name = "rg-eastus-dev1"
address_space = ["10.0.0.0/16"]
}
}
subnets = {
snet-01 = {
resource_group_name = "rg-eastus-dev1"
virtual_network_name = "vnet-dev1"
address_prefixes = ["10.0.1.0/24"]
}
}
nic = {
nic1 = {
subnet_name = "snet-01"
resource_group_name = "rg-eastus-dev1"
}
}
admin_password = "s}8cpH96qa.1BQ"
admin_user = "padmin"
windows_vm = {
winvm1 = {
network_interface_names = ["nic1"]
resource_group_name = "rg-eastus-dev1"
size = "Standard_B2s"
timezone = "Eastern Standard Time"
}
}
MAIN
resource "azurerm_resource_group" "rgs" {
for_each = var.resource_groups
name = each.key
location = each.value["location"]
}
data "azurerm_resource_group" "rgs" {
for_each = var.resource_groups
name = each.key
depends_on = [
azurerm_resource_group.rgs
]
}
resource "azurerm_virtual_network" "vnet" {
for_each = var.virtual_networks
name = each.key
resource_group_name = each.value["resource_group_name"]
address_space = each.value["address_space"]
location = data.azurerm_resource_group.rgs[each.value["resource_group_name"]].location
}
resource "azurerm_subnet" "subnet" {
for_each = var.subnets
name = each.key
resource_group_name = each.value["resource_group_name"]
virtual_network_name = each.value["virtual_network_name"]
address_prefixes = each.value["address_prefixes"]
depends_on = [
azurerm_virtual_network.vnet
]
}
data "azurerm_subnet" "subnet" {
for_each = var.subnets
name = each.key
virtual_network_name = each.value["virtual_network_name"]
resource_group_name = each.value["resource_group_name"]
depends_on = [
azurerm_resource_group.rgs
]
}
resource "azurerm_network_interface" "nics" {
for_each = var.nic
ip_configuration {
name = each.key
subnet_id = data.azurerm_subnet.subnet[each.value["subnet_name"]].id
private_ip_address_allocation = "Dynamic"
}
location = data.azurerm_resource_group.rgs[each.value["resource_group_name"]].location
name = each.key
resource_group_name = each.value["resource_group_name"]
depends_on = [
azurerm_resource_group.rgs,
azurerm_subnet.subnet
]
}
data "azurerm_network_interface" "nics" {
for_each = var.nic
name = each.key
resource_group_name = each.value["resource_group_name"]
depends_on = [
azurerm_resource_group.rgs
]
}
resource "azurerm_windows_virtual_machine" "windows_vm" {
for_each = var.windows_vm
admin_password = var.admin_password
admin_username = var.admin_user
location = data.azurerm_resource_group.rgs[each.value["resource_group_name"]].location
name = each.key
network_interface_ids = values(data.azurerm_network_interface.nics[each.value["network_interface_names"]].id)
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
resource_group_name = each.value["resource_group_name"]
size = each.value["size"]
timezone = each.value["timezone"]
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
}
Current Error on Plan
╷
│ Error: Invalid index
│
│ on main.tf line 75, in resource "azurerm_windows_virtual_machine" "windows_vm":
│ 75: network_interface_ids = values(data.azurerm_network_interface.nics[each.value["network_interface_names"]].id)
│ ├────────────────
│ │ data.azurerm_network_interface.nics is object with 1 attribute "nic1"
│ │ each.value["network_interface_names"] is list of string with 1 element
│
│ The given key does not identify an element in this collection value: string required.
Possible Solution - But Not working
Provide a map, keyed off the VM name, of NIC IDs. Then, in the windows_vm resource, take that map and try to get the list of NIC ID values.
locals {
nic_ids {
[for k, v in var.windows_vm : k => v {data.azurerm_network_interface.nics[v.network_interface_names]}.id]
}
}
resource "azurerm_windows_virtual_machine" "windows_vm" {
for_each = var.windows_vm
admin_password = var.admin_password
admin_username = var.admin_user
location = data.azurerm_resource_group.rgs[each.value["resource_group_name"]].location
name = each.key
network_interface_ids = values(local.nic_ids[each.key])
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
resource_group_name = each.value["resource_group_name"]
size = each.value["size"]
timezone = each.value["timezone"]
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
}
First of all, you do not need to call data after creation of each resource. The resource itself will contain all the information that you need. So you should eliminate all data sources in your code and use resource directly.
But returning to the error you provided. One way to generate the list dynamically, would be:
network_interface_ids = [for ni_name in each.value["network_interface_names"]: azurerm_network_interface.nics[ni_name].id]
I'm having trouble referencing the output of a module as an input to another module.
I'm trying to output network_interface_id from vm.tf, and use it as input to lb.tf.
I get the error, each.value is tuple with 2 elements, Inappropriate value for attribute "network_interface_id": string required.
It works if I use network_interface_id = each.value[0], or[1] but obviously only adds one nic to the lb.
I've been going round in circles trying to figure this out so any help would be much appreciated.
Many thanks in advance ... :-)
This is the snippet of code I'm struggling with from lb.tf. Full code is below that.
resource "azurerm_network_interface_backend_address_pool_association" "nibapa" {
for_each = var.nic_ids
network_interface_id = each.value # <= This errors with each.value is tuple with 2 elements. It works using each.value[0] or [1]; but I need to loop through both.
ip_configuration_name = "internal"
backend_address_pool_id = azurerm_lb_backend_address_pool.lbap.id
}
main.tf
locals {
vm = {
"01" = {
zone = "1"
}
"02" = {
zone = "2"
}
}
}
resource "azurerm_resource_group" "rg" {
location = "northeurope"
name = "rg-test1"
}
module "vm" {
source = "./vm"
for_each = local.vm
location = "northeurope"
resource_group_name = azurerm_resource_group.rg.name
vm_name = "vm-${each.key}"
nic_name = "nic-vm-${each.key}"
os_disk_name = "osdisk-vm-${each.key}"
availability_zone = each.value.zone
}
output "nic_ids" { value = [ for k, nic in module.vm : nic.nic_id ] }
module "lb" {
source = "./lb"
location = "northeurope"
resource_group_name = azurerm_resource_group.rg.name
nic_ids = { value = [ for k, nic in module.vm : nic.nic_id ] }
}
vm.tf
variable "location" {}
variable "resource_group_name" {}
variable "vm_name" {}
variable "nic_name" {}
variable "os_disk_name" {}
variable "availability_zone" {}
resource "azurerm_network_interface" "ni" {
location = var.location
resource_group_name = var.resource_group_name
name = var.nic_name
ip_configuration {
name = "internal"
subnet_id = "/subscriptions/2bc7b65e-18d6-42ae-afb2-e66d50be6b05/resourceGroups/rg-core-01/providers/Microsoft.Network/virtualNetworks/vnet-prd-spoke-nteu-01/subnets/snet-app"
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_linux_virtual_machine" "lvm" {
location = var.location
resource_group_name = var.resource_group_name
name = var.vm_name
size = "Standard_B2ms"
zone = var.availability_zone
admin_username = "ladmin"
admin_password = "Password1234"
disable_password_authentication = false
network_interface_ids = [
azurerm_network_interface.ni.id,
]
os_disk {
name = var.os_disk_name
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}
output "nic_id" { value = azurerm_network_interface.ni.id }
lb.tf
variable "location" {}
variable "resource_group_name" {}
variable "nic_ids" {}
resource "azurerm_lb" "lb" {
location = var.location
resource_group_name = var.resource_group_name
name = "lbi-test1"
sku = "Standard"
sku_tier = "Regional"
frontend_ip_configuration {
name = "feip-test1"
subnet_id = "/subscriptions/2bc7b65e-18d6-42ae-afb2-e66d50be6b05/resourceGroups/rg-core-01/providers/Microsoft.Network/virtualNetworks/vnet-prd-spoke-nteu-01/subnets/snet-app"
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_lb_backend_address_pool" "lbap" {
loadbalancer_id = azurerm_lb.lb.id
name = "beap-test1"
}
resource "azurerm_network_interface_backend_address_pool_association" "nibapa" {
for_each = var.nic_ids
network_interface_id = each.value # <= This errors with each.value is tuple with 2 elements. It works using each.value[0] or [1]; but I need to loop through both.
ip_configuration_name = "internal"
backend_address_pool_id = azurerm_lb_backend_address_pool.lbap.id
}
The error code is:
Error: Incorrect attribute value type
on lb\lb.tf line 25, in resource "azurerm_network_interface_backend_address_pool_association" "nibapa":
25: network_interface_id = each.value
each.value is tuple with 2 elements
Inappropriate value for attribute "network_interface_id": string required.
I figured this out in the end. The key changes were mainly syntactical ...
main.tf
The key line here is 'nic_ids = module.vm'. This returns a map of nic_id's for each instance.
module "lb" {
depends_on = [ module.vm ]
source = "./lb"
location = "northeurope"
resource_group_name = azurerm_resource_group.rg.name
nic_ids = module.vm
}
output "nic_ids" { value = module.vm }; (so the output of the variable nic_ids to pass to the next module looks like this)
nic_ids = {
"01" = {
"nic_id" = "/subscriptions/2bc7b65e-18d6-42ae-afb2-e66d50be6b05/resourceGroups/rg-prd-oem-2208081500/providers/Microsoft.Network/networkInterfaces/nic-prdnteuoms01"
}
"02" = {
"nic_id" = "/subscriptions/2bc7b65e-18d6-42ae-afb2-e66d50be6b05/resourceGroups/rg-prd-oem-2208081500/providers/Microsoft.Network/networkInterfaces/nic-prdnteuoms02"
}
}
lb.tf
The key line here is 'network_interface_id = each.value.nic_id'.
resource "azurerm_network_interface_backend_address_pool_association" "nibapa" {
for_each = var.nic_ids
network_interface_id = each.value.nic_id
ip_configuration_name = "internal"
backend_address_pool_id = azurerm_lb_backend_address_pool.lbap.id
}
Simples when you know how ;-)
I have created a network module. Below is the code for it
variables.tf
variable "resource_group_name" {
description = "Name of the resource group to be imported."
type = string
}
variable "location" {
description = "The location of the vnet to create. Defaults to the location of the resource group."
type = string
default = null
}
variable "vnets" {
type = map(object({
address_space = string
subnets = list(object({
subnet_name = string
subnet_address = string
service_endpoints = list(string)
}))
}))
default = {
"bupavnet1" = {
address_space = "192.168.0.0/16",
subnets = []
},
"bupavnet2" = {
address_space = "10.0.0.0/16",
subnets = [
{
subnet_name = "subnet1_bupavnet1"
subnet_address = "10.0.2.0/24"
service_endpoints = []
},
{
subnet_name = "subnet2_bupavnet1"
subnet_address = "10.0.0.0/24"
service_endpoints = ["Microsoft.AzureCosmosDB","Microsoft.ContainerRegistry"]
}
]
},
"bupavnet3" = {
address_space = "10.80.0.0/16"
subnets = [
{
subnet_name = "subnet1_bupavnet3"
subnet_address = "10.80.2.0/24"
service_endpoints = ["Microsoft.AzureCosmosDB","Microsoft.ContainerRegistry"]
},
{
subnet_name = "subnet2_bupavnet3"
subnet_address = "10.80.1.0/24"
service_endpoints = ["Microsoft.AzureCosmosDB","Microsoft.ContainerRegistry"]
},
{
subnet_name = "subnet3_bupavnet3"
subnet_address = "10.80.0.0/24"
service_endpoints = ["Microsoft.AzureCosmosDB","Microsoft.ContainerRegistry"]
},
]
}
}
}
output.tf
output "vnet_names" {
description = "The name of the virtual networks"
value = tomap({for k, v in azurerm_virtual_network.vnets: k => v.name})
}
output "vnet_addresses" {
description = "The name of the virtual networks"
value = tomap({for k, v in azurerm_virtual_network.vnets: k => v.address_space})
}
output "subnet_names" {
description = "The name of the subnets"
value = tomap({for k, v in azurerm_subnet.subnets: k => v.name})
}
output "subnet_addresses" {
description = "The name of the subnet addresses"
value = {for k, v in azurerm_subnet.subnets: k => v.address_prefixes}
}
output "subnet_ids" {
description = "The name of the subnet addresses"
value = tomap({for k, v in azurerm_subnet.subnets: k => v.id})
}
main.tf
data "azurerm_resource_group" "network" {
name = var.resource_group_name
}
resource "azurerm_virtual_network" "vnets" {
for_each = var.vnets
name = each.key
resource_group_name = data.azurerm_resource_group.network.name
location = data.azurerm_resource_group.network.location
address_space = [each.value.address_space]
}
resource "azurerm_subnet" "subnets" {
for_each = local.subnets
name = each.value.subnet_name
resource_group_name = data.azurerm_resource_group.network.name
virtual_network_name = azurerm_virtual_network.vnets[each.value.vnet_name].name
address_prefixes = [each.value.subnet_address]
service_endpoints = [each.value.service_endpoints]
}
locals.tf
locals {
subnets_flatlist = flatten([for key, val in var.vnets : [
for subnet in val.subnets : {
vnet_name = key
subnet_name = subnet.subnet_name
subnet_address = subnet.subnet_address
service_endpoints = subnet.service_endpoints
}
]
])
subnets = { for subnet in local.subnets_flatlist : subnet.subnet_name => subnet }
}
main.tf
resource "azurerm_resource_group" "rg2" {
name = "rg2"
location = "Australia East"
}
module "network" {
source = "./network_resources"
resource_group_name = azurerm_resource_group.rg2.name
location = azurerm_resource_group.rg2.location
}
I am getting the below error when I am doing terraform plan
│ Error: Incorrect attribute value type
│
│ on network_resources\main.tf line 21, in resource "azurerm_subnet" "subnets":
│ 21: service_endpoints = [each.value.service_endpoints]
│ ├────────────────
│ │ each.value.service_endpoints is list of string with 2 elements
│
│ Inappropriate value for attribute "service_endpoints": element 0: string required.
Please can you let me know how service_endpoints can be added as part of variable vnets so that the module will start working fine
The reason you get this error is that your service_endpoints is already a list, but you are wrapping it in [] which is creating a list of lists. Remove the [] from service_endpoints:
resource "azurerm_subnet" "subnets" {
for_each = local.subnets
name = each.value.subnet_name
resource_group_name = data.azurerm_resource_group.network.name
virtual_network_name = azurerm_virtual_network.vnets[each.value.vnet_name].name
address_prefixes = [each.value.subnet_address]
service_endpoints = each.value.service_endpoints
}
I have a module that creates vnets and subnets (module vnet):
resource "azurerm_virtual_network" "xxx" {
count = length(var.vnets)
name = var.vnets[count.index].vnet_name
address_space = var.vnets[count.index].address_space
location = var.resource_location
resource_group_name = var.resource_group_name
dynamic "subnet" {
for_each = var.vnets[count.index].subnets
content {
name = subnet.value.name
address_prefix = subnet.value.address
security_group = azurerm_network_security_group.xxx.id
}
}
tags = var.tags
}
var.vnets is
vnets = [
{
vnet_name = "01-vnet"
address_space = ["10.0.0.0/23"]
subnets = [
{
name = "workloads-01"
address = "10.0.0.0/24"
}
]
},
{
vnet_name = "02-vnet"
address_space = ["10.0.2.0/23"]
subnets = [
{
name = "workloads-02"
address = "10.0.2.0/24"
}
]
}
]
And then I pass subnets to my root file
output "subnets" {
value = flatten(azurerm_virtual_network.xxx[*].subnet[*].id)
}
Resulted output
Outputs:
subnets = [
"/subscriptions/XXX/resourceGroups/EIS/providers/Microsoft.Network/virtualNetworks/eis-01-vnet/subnets/eis-workloads-01",
"/subscriptions/XXX/resourceGroups/EIS/providers/Microsoft.Network/virtualNetworks/eis-02-vnet/subnets/eis-workloads-02",
]
Now I want to use those subnets when I create VMs in another module (vm module):
resource "azurerm_network_interface" "nics" {
for_each = var.vms
name = "${each.value.name}-nic"
location = var.resource_location
resource_group_name = var.resource_group_name
ip_configuration {
name = "iface-${each.value.name}"
subnet_id = element(var.subnet_id, count.index)
private_ip_address_allocation = "Dynamic"
}
tags = var.tags
}
Where var.vms
vms = {
vm1 = {
name = "vm1"
vm_size = "Standard_B1ms"
username = "centos"
password = "222!"
disk_size = "30"
sku = "7_9"
ext_ip = "1"
},
vm2 = {
name = "vm2"
vm_size = "Standard_B1ls"
username = "centos"
password = "111!"
disk_size = "35"
sku = "7_9"
ext_ip = ""
}
}
And var.subnet_id is just, defined in vm module.
variable "subnet_id" {}
My root's main.tf
module "vm" {
source = "./modules/vm"
for_each = var.vms
vms = var.vms
publicip_name = var.publicip_name
subnet_id = module.vnet.subnets[*]
resource_group_name = azurerm_resource_group.xxx.name
resource_location = azurerm_resource_group.xxx.location
tags = local.common_tags
}
How can I pass subnet_ids from module vnet to module vm, so the resource "azurerm_network_interface" will use one subnet_ids for each key defined in vms?
I would use "element(var.subnet_id, count.index)" for the count, but how can I pass those subnet ids for a resource that will be created with for_each?
You can get iterate over your var.vms with index as follows:
resource "azurerm_network_interface" "nics" {
for_each = {for idx, vm in keys(var.vms): idx => var.vms[vm]}
name = "${each.value.name}-nic"
location = var.resource_location
resource_group_name = var.resource_group_name
ip_configuration {
name = "eis-iface-${each.value.name}"
subnet_id = element(var.subnet_id, each.key)
private_ip_address_allocation = "Dynamic"
}
tags = var.tags
}
Note: keys returns the map keys in alphabetical order if that meters.
I would like to run terraform plan -var-file -out and then apply the plan but I get the following error.
Here's my main.tf, variable.tf and networking.tfvars file below:
###### Resource Group ##############
resource "azurerm_resource_group" "resourcegroupname" {
name = "${var.resourcegrouprefix}-RG"
location = "${var.location}"
}
###### VNET ##############
resource "azurerm_virtual_network" "vnet" {
name = "${var.vnet-prefix}-vnet"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
location = "${azurerm_resource_group.resourcegroupname.location}"
address_space = "${var.vnetcidr}"
}
# address_space = ["10.0.0.0/20"]
###### Subnets ##############
resource "azurerm_subnet" "subnet1" {
name = "${var.subnet1-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_space = "${var.subnet1cidr}"
}
resource "azurerm_subnet" "subnet2" {
name = "${var.subnet2-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_space = "${var.subnet2cidr}"
}
resource "azurerm_subnet" "subnet3" {
name = "${var.subnet3-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_space = "${var.subnet3cidr}"
Variables File
variable "resourcegrouprefix" {
description = "The prefix used for all resources in VNET RG"
default = ""
}
variable "vnet-prefix" {
description = "The prefix used for VNET resource"
default = ""
}
variable "vnetcidr" {
default = ""
}
variable "subnet1cidr" {
default = ""
}
variable "subnet2cidr" {
default = ""
}
variable "subnet3cidr" {
default = ""
}
Networking.tfvars
resourcegrouprefix = "networking"
vnet-prefix = "networking"
vnetcidr = "10.0.0.0/20"
subnet1-prefix = "untrust"
subnet2-prefix = "trust"
subnet3-prefix = "mgmt"
subnet1cidr = "10.0.0.0/24"
subnet2cidr = "10.0.1.0/24"
subnet3cidr = "10.0.2.0/24"
Command that I'm trying to execute:
terraform plan -var-file="networking.tfvars" -out="networkingplan.out"
Error message:
azurerm_subnet.subnet1: "address_prefix": required field is not set
azurerm_subnet.subnet1: : invalid or unknown key: address_space
azurerm_subnet.subnet2: "address_prefix": required field is not set
azurerm_subnet.subnet2: : invalid or unknown key: address_space
azurerm_subnet.subnet3: "address_prefix": required field is not set
azurerm_subnet.subnet3: : invalid or unknown key: address_space
azurerm_subnet.subnet4: "address_prefix": required field is not set
azurerm_subnet.subnet4: : invalid or unknown key: address_space
azurerm_subnet.subnet5: "address_prefix": required field is not set
azurerm_subnet.subnet5: : invalid or unknown key: address_space
azurerm_subnet.subnet6: "address_prefix": required field is not set
azurerm_subnet.subnet6: : invalid or unknown key: address_space
azurerm_virtual_network.vnet: address_space: should be a list
Fixed the error message
###### Resource Group ##############
resource "azurerm_resource_group" "resourcegroupname" {
name = "${var.resourcegrouprefix}-RG"
location = "${var.location}"
}
###### VNET ##############
resource "azurerm_virtual_network" "vnet" {
name = "${var.vnet-prefix}-vnet"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
location = "${azurerm_resource_group.resourcegroupname.location}"
address_space = ["${var.vnetcidr}"]
}
# address_space = ["10.0.0.0/20"]
###### Subnets ##############
resource "azurerm_subnet" "subnet1" {
name = "${var.subnet1-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_prefix = "${var.subnet1cidr}"
}
resource "azurerm_subnet" "subnet2" {
name = "${var.subnet2-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_prefix = "${var.subnet2cidr}"
}
resource "azurerm_subnet" "subnet3" {
name = "${var.subnet3-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_prefix = "${var.subnet3cidr}"
}