Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Importing existing vnets and peerings doesn't work #444

Open
stryktips opened this issue Mar 4, 2025 · 2 comments
Open

bug: Importing existing vnets and peerings doesn't work #444

stryktips opened this issue Mar 4, 2025 · 2 comments

Comments

@stryktips
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Versions

Please paste the output of terraform version command from within the initialized directory:

Terraform v1.11.0
on windows_amd64
+ provider registry.terraform.io/azure/azapi v1.15.0
+ provider registry.terraform.io/hashicorp/azuread v3.0.2
+ provider registry.terraform.io/hashicorp/azurerm v4.18.0
+ provider registry.terraform.io/hashicorp/random v3.6.3
+ provider registry.terraform.io/hashicorp/time v0.12.1

Please enter the module version that you are using:

  source  = "Azure/lz-vending/azurerm"
  version = "4.1.5"

Description

When importing virtual network peerings the following error message is returned for the imported vnet:

│ Error: Invalid configuration
│
│   with module.landing_zones["subscription-name.yaml"].module.lz_vending.module.virtualnetwork[0].azapi_resource.vnet["vnet-appgw-test"],
│   on .terraform\modules\landing_zones.lz_vending\modules\virtualnetwork\main.tf line 37, in resource "azapi_resource" "vnet":
│   37: resource "azapi_resource" "vnet" {
│
│ embedded schema validation failed: the argument "body" is invalid:
│ `properties.subnets.0.properties.applicationGatewayIPConfigurations` is not expected here. Do you mean
│ `properties.subnets.0.properties.applicationGatewayIpConfigurations`?
│ `properties.virtualNetworkPeerings.0.properties.peerCompleteVnets` is not expected here. Do you mean
│ `properties.virtualNetworkPeerings.0.properties.peeringState`?
│  You can try to update `azapi` provider to the latest version or disable the validation using the feature flag `schema_validation_enabled = false` within the resource block

This seems to be because the virtualnetwork module is using old API versions. If I update the virtualNetworks version in the module source in the .terraform directory like this:

resource "azapi_resource" "vnet" {
  for_each  = var.virtual_networks
  parent_id = "${local.subscription_resource_id}/resourceGroups/${each.value.resource_group_name}"
  type      = "Microsoft.Network/virtualNetworks@2024-01-01"

Then the error disappears.

Steps to Reproduce

  1. Create import statements for an existing vnet. E.g.
import {
    id = "/subscriptions/xxxx/resourceGroups/tst_rg/providers/Microsoft.Network/virtualNetworks/TSTNET-01"
    to = module.landing_zones["subscription-name.yaml"].module.lz_vending.module.virtualnetwork[0].azapi_resource.vnet["TSTNET-01"]
}
  1. Specify the required parameters for peering:
      # peering configuration
      hub_peering_enabled      = true
      hub_network_resource_id  = var.hub_vnets[vnet.hub_name].id
      hub_peering_name_tohub   = vnet.outbound_peering_override != null ? vnet.outbound_peering_override : format("%s-TO-%s", vnet.name, var.hub_vnets[vnet.hub_name].name)
      hub_peering_name_fromhub = vnet.inbound_peering_override != null ? vnet.inbound_peering_override : format("%s-TO-%s", var.hub_vnets[vnet.hub_name].name, vnet.name)
  1. Run terraform plan

Screenshots

Additional context

@matt-FFFFFF
Copy link
Member

Hi there,

This is an issue with the provider I think, rather than the module. I think the import statement uses the latest api version, which may be different from the resource config.

@matt-FFFFFF
Copy link
Member

In the next major version we will update the api versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants