hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.53k stars 4.6k forks source link

azurerm_virtual_network_peering between virtual networks in different resource groups #18764

Closed danipber closed 1 year ago

danipber commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.2.4

AzureRM Provider Version

3.26.0

Affected Resource(s)/Data Source(s)

azurerm_virtual_network_peering

Terraform Configuration Files

resource "azurerm_virtual_network" "virtual_network" {
  name                = var.virtual_network_name
  location            = var.virtual_network_location
  resource_group_name = var.resource_group_name
  address_space       = [var.virtual_network_address_prefixes]

  tags = var.tags
}

output "virtual_network_name" {
  value = azurerm_virtual_network.virtual_network.name
}

resource "azurerm_virtual_network_peering" "windows_agent" {
  name                      = "peertowindowsagent"
  resource_group_name       = var.resource_group_name
  virtual_network_name      = azurerm_virtual_network.virtual_network.name
  remote_virtual_network_id = var.windows_agent_virtual_network_id
}

resource "azurerm_virtual_network_peering" "linux_agent" {
  name                      = "peertolinuxagent"
  resource_group_name       = var.resource_group_name
  virtual_network_name      = azurerm_virtual_network.virtual_network.name
  remote_virtual_network_id = var.linux_agent_virtual_network_id
}

Debug Output/Panic Output

module.virtual_network.azurerm_virtual_network_peering.linux_agent: Creating...
module.virtual_network.azurerm_virtual_network_peering.windows_agent: Creating...
╷
│ Error: Plugin did not respond
╵

╷
│ Error: Plugin did not respond
│ 
│   with module.virtual_network.azurerm_virtual_network_peering.linux_agent,
│   on modules/virtual-network/virtualnetwork.tf line 21, in resource "azurerm_virtual_network_peering" "linux_agent":
│   21: resource "azurerm_virtual_network_peering" "linux_agent" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵

Stack trace from the terraform-provider-azurerm_v3.26.0_x5 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x476d338]

goroutine 154 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/network.retryVnetPeeringsClientCreateUpdate.func1()
    github.com/hashicorp/terraform-provider-azurerm/internal/services/network/virtual_network_peering_resource.go:220 +0x298
github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource.RetryContext.func1()
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.18.0/helper/resource/wait.go:27 +0x56
github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource.(*StateChangeConf).WaitForStateContext.func1()
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.18.0/helper/resource/state.go:110 +0x207
created by github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource.(*StateChangeConf).WaitForStateContext
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.18.0/helper/resource/state.go:83 +0x1d8

Error: The terraform-provider-azurerm_v3.26.0_x5 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Expected Behaviour

Azure virtual network peering created

Actual Behaviour

Plugin did not respond https://dev.azure.com/bavelpay/Payments/_build/results?buildId=763&view=logs&j=30258c87-fa2d-5a55-b28f-ceed67c0ba10&t=c02799de-7530-5c13-7ab8-4e57dbaae743&l=72

Steps to Reproduce

module.virtual_network.azurerm_virtual_network.virtual_network will be updated in-place

~ resource "azurerm_virtual_network" "virtual_network" { id = "/subscriptions/xxxxxxxxxxxxxxx/resourceGroups/rg-bp-we-payments-d-01/providers/Microsoft.Network/virtualNetworks/vnet-bp-we-payments-d-01" name = "vnet-bp-we-pay-d-01"

module.virtual_network.azurerm_virtual_network_peering.linux_agent will be created

Plan: 2 to add, 1 to change, 0 to destroy.

Important Factoids

No response

References

No response

lonegunmanb commented 1 year ago

Thanks @danipber for opening this pr, I've tried the following code but I couldn't reproduce this issue:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "one" {
  location = "eastus"
  name     = "zjhe-f18764-1"
}

resource "azurerm_virtual_network" "virtual_network_1" {
  name                = "vnet-1"
  location            = "eastus"
  resource_group_name = azurerm_resource_group.one.name
  address_space       = ["192.168.0.0/16"]
}

resource "azurerm_resource_group" "two" {
  location = "eastus"
  name     = "zjhe-f18764-2"
}

resource "azurerm_virtual_network" "virtual_network_2" {
  address_space       = ["10.0.0.0/16"]
  location            = "eastus"
  name                = "vnet-2"
  resource_group_name = azurerm_resource_group.two.name
}

resource "azurerm_virtual_network_peering" "windows_agent" {
  name                      = "peertowindowsagent"
  resource_group_name       = azurerm_resource_group.one.name
  virtual_network_name      = azurerm_virtual_network.virtual_network_1.name
  remote_virtual_network_id = azurerm_virtual_network.virtual_network_2.id
}

resource "azurerm_virtual_network_peering" "linux_agent" {
  name                      = "peertolinuxagent"
  resource_group_name       = azurerm_resource_group.two.name
  virtual_network_name      = azurerm_virtual_network.virtual_network_2.name
  remote_virtual_network_id = azurerm_virtual_network.virtual_network_1.id
}

Could you please give me a minimum sample that could reproduce this issue with instructions for every step? Thanks!

rcskosir commented 1 year ago

Thanks for opening this issue. Since time has passed and @lonegunmanb was not able to reproduce this issue, I am going to mark this issue closed as “can’t reproduce”. If you are able to provide more information to help us reproduce this issue we may re-open this issue or open a new issue, thanks!

github-actions[bot] commented 4 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.