Hi,
I have been using terraform with Azure and recently I have been using some isolation techniques. For instance I have the following folder hierarchy:
LAB>services>vm
LAB>vnet
The vnet (located in LAB>vnet) is quite simple and it only has a couple of subnets and I have used a variable and output files to manage input and output variables
The vm (located in LAB>services>vm) is also quite simple as it just sets up a simple linux machine
I have performed a terraform init and apply within the vnet folder and the vnet and subnets have been created, along with the resource group
However when I try and create the linux vm the terraform init runs fine but I get the following error when I run terraform apply:
“Error: A resource with the ID “” already exists - to be managed via Terraform
this resource needs to be imported into the State. Please see the resource documentation for “azurerm_resource_group” for more information.”
I am calling the vnet module within the vm.tf using:
module “vnet” {
source = “…/…/vnet/”
}
I plan to connect the network interface for the linux vm into a subnet within the vnet (LAB>vnet) by using:
resource “azurerm_network_interface” “example” {
name = “example-nic”
location = “west europe”
resource_group_name = “{module.vnet.resource_group_id}"
ip_configuration {
name = "internal"
subnet_id = "{module.vnet.subnet1_id}”
private_ip_address_allocation = “Dynamic”
}
}
However the bit the code does not like seems to be
resource_group_name = “${module.vnet.resource_group_id}”
I use the in two places, firstly on the network interface, as shown above and then for the vm, as show below
resource “azurerm_linux_virtual_machine” “example” {
name = “example-machine”
resource_group_name = “${module.vnet.resource_group_id}”
location = “westeurope”
size = “Standard_F2”
admin_username = “adminuser”
admin_password = “******”
network_interface_ids = [
azurerm_network_interface.example.id
]
}
Any ideas what I am doing wrong?