I'm trying to set the "network_interface_ids" within "azurerm_virtual_machine" to the output of one of my modules, but am receiving the following error during the "terraform plan" and can't figure out where I'm going wrong:
│ Error: Incorrect attribute value type
│
│ on modules/virtualmachine/main.tf line 6, in resource "azurerm_virtual_machine" "vm":
│ 6: network_interface_ids = [var.nicid]
│ ├────────────────
│ │ var.nicid is a list of string, known only after apply
│
│ Inappropriate value for attribute "network_interface_ids": element 0:
│ string required.
╵
##[error]Bash exited with code '1'.
I'm sure this is something simple, I have it working without being split out into modules just can't quite figure it out. I've attached all of the relevant code below (obviously removed the bulk of the code to help with brevity):
main.tf
module "virtualmachine" {
source = "./modules/virtualmachine"
nicid = module.networking.nicidoutput
}
modules/networking/main.tf
resource "azurerm_network_interface" "nic" {
name = var.nicname
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}
modules/networking/outputs.tf
output "nicidoutput" {
value = azurerm_network_interface.nic.id
}
modules/virtualmachine/main.tf
resource "azurerm_virtual_machine" "vm" {
network_interface_ids = [var.nicid]
}
modules/virtualmachine/variables.tf
variable "nicid" {
type = list(string)
description = "network interface id"
}
CodePudding user response:
Your var.nicid
is already a list. So it should be:
network_interface_ids = var.nicid
update:
also the following should be changed in virtualmachine
nicid = [module.networking.nicidoutput] for virtualmachine