Reputation: 1
Here is my code block for creating the network interface and attaching security group in Azure with Terrfaorm. I have used the same in another module but I'm getting an error when running this:
resource "azurerm_network_interface" "myterraformnic" {
name = "${var.vm_name}-nic"
location = "${azurerm_resource_group.sdsterraformgroup.location}"
resource_group_name = "${azurerm_resource_group.sdsterraformgroup.name}"
network_security_group_id = "${azurerm_network_security_group.myterraformnsg.id}"
}
Here is the error I get when I run a plan or an apply.:
**"Error: azurerm_network_interface.myterraformnic: : invalid or unknown key: network_security_group_id"**
Upvotes: 0
Views: 1023
Reputation: 155
azurerm_network_interface resource in terraform does not have a network_security_group_id paramter.
If you are trying to associate network security group with a network interface, make change to terraform resource block as below
resource "azurerm_network_interface" "myterraformnic" {
name = "${var.vm_name}-nic"
location = "${azurerm_resource_group.sdsterraformgroup.location}"
resource_group_name = "${azurerm_resource_group.sdsterraformgroup.name}"
}
resource "azurerm_network_interface_security_group_association" "example" {
network_interface_id = azurerm_network_interface.myterraformnic.id
network_security_group_id = "${azurerm_network_security_group.myterraformnsg.id}"
}
By changing template as above, "azurerm_network_interface" resource block will create network interface and network security group will be associated to network interface in "azurerm_network_interface_security_group_association" resource block
Upvotes: 4