-2

I am working on creating NAT gateway in azure using terraform. I have existing virtual network having subnets which the virtual machines. I would like to associate this existing subnet with my NAT gateway.

I have created a root module for my NAT gateway where I imported my existing virtual network configuration using terraform import

Terraform plan is successful but I am getting below error while executing terraform apply

Error: A resource with the ID "/subscriptions/22e07cbf-2803-48ed-8dec-7db32f9f6103/resourceGroups/iomsaas-euc-play/providers/Microsoft.Network/virtualNetworks/iomsaas-euc-play-vnet" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_virtual_network" for more information.

I am new to terraform. Can anyone assist here. Any helps will be appreciated. Thanks in advance.

Expected Result

1 Create a NAT Gateway 2 Attach it with a public IP 3 Attach it with an existing subnet which contains the VMs

1 Answers1

0

You can import your VNET into state using terraform import.

Alternatively, You need to reference your VNET and Subnet with data blocks. Your error seems to imply your use of a resource block when getting your VNET. You should really provide your terraform code to help us better help you.

Derek Williams
  • 525
  • 6
  • 21