Azurerm CDKTF C# can not parse Virtual_network_id

How can I assign the Id of a VirtualNetwork to another resource which requires it?

Hi there, I am experiencing some issues whenever I execute Terraform plan on my CDKTF C# generated JSON plan.

Error: Can not parse "virtual_network_id" as a resource id: Cannot parse Azure ID: parse "azurerm_virtual_network": invalid URI for request

This error happens on the azurem_private_dns_zone_virtual_network_link resource.
The resource definition in my class:

            new PrivateDnsZoneVirtualNetworkLink(this, "azurerm_private_dns_zone_virtual_network_link", new PrivateDnsZoneVirtualNetworkLinkConfig
                Name = ng.EnvironmentName("long", env: "env") + "",
                ResourceGroupName = ng.GetResNames()["RgName"],
                PrivateDnsZoneName = "azurerm_private_dns_zone.private-dns-zone",
                VirtualNetworkId = "azurerm_virtual_network"

The VirtualNetwork resource definition:

            new VirtualNetwork(this, "azurerm_virtual_network", new VirtualNetworkConfig
                Name = ng.GetResNames()["VNetName"],
                Location = ng.Region[1],
                ResourceGroupName = ng.GetResNames()["RgName"],
                AddressSpace = new[] { "" },
                Tags = new Dictionary<string, string> {
                    { "application", ng.EnvironmentName("long")},
                    {"environment", ng.EnvironmentName("long", env:"env") }

My first idea was to simply use the string which is defined as azurerm_virtual_network
As per the provider definition:
But this did not seem to work. Could anyone give me a hand regarding this issue?
Thank you!

Bumping just in case

You’ll want to assign your created VirtualNetwork to a local variable, say network. Then you can have VirtualNetworkId = network.Id.

1 Like

That worked, thanks!