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

Unable to rename redistribution policy #667

Closed
nu11ptr opened this issue Sep 8, 2021 · 4 comments · Fixed by #686
Closed

Unable to rename redistribution policy #667

nu11ptr opened this issue Sep 8, 2021 · 4 comments · Fixed by #686
Labels
bug Bug crash Crash

Comments

@nu11ptr
Copy link

nu11ptr commented Sep 8, 2021

I tried to rename this:

resource "nsxt_policy_gateway_redistribution_config" "GW_T0_1_REDIST" {
    gateway_path = nsxt_policy_tier0_gateway.GW_T0_1.path
    bgp_enabled = true
    rule {
        name  = "rule1"
        types = ["TIER0_STATIC", "TIER0_CONNECTED", "TIER1_CONNECTED"]
    }
}

From GW_REDIST to GW_T0_1_REDIST and got this error:

nsxt_policy_gateway_redistribution_config.GW_REDIST: Destroying... [id=ebe374b2-d1d6-4ec7-90f6-020b8a0ec659]
nsxt_policy_gateway_redistribution_config.GW_T0_1_REDIST: Creating...
nsxt_policy_tier0_gateway.GW_T0_VRF-XYZ: Creating...
nsxt_policy_gateway_redistribution_config.GW_T0_1_REDIST: Creation complete after 1s [id=faad73a4-0630-44aa-a3ff-0564fc1fc341]
nsxt_policy_tier0_gateway.GW_T0_VRF-XYZ: Creation complete after 1s [id=348616fa-a208-4ec7-9e29-cb1cbbc3e6c7]
nsxt_policy_gateway_redistribution_config.GW_T0_VRF-XYZ_REDIST: Creating...
nsxt_policy_gateway_redistribution_config.GW_T0_VRF-XYZ_REDIST: Creation complete after 1s [id=a8e4bee5-366e-4b44-a813-3652b0e184fa]
╷
│ Error: com.vmware.vapi.std.errors.concurrent_change
│ 
│ 
╵

So I thought, I'll just comment it out and do it in two steps, but that resulted in this:

nsxt_policy_gateway_redistribution_config.GW_T0_1_REDIST: Destroying... [id=faad73a4-0630-44aa-a3ff-0564fc1fc341]
nsxt_policy_gateway_redistribution_config.GW_REDIST: Destroying... [id=ebe374b2-d1d6-4ec7-90f6-020b8a0ec659]
nsxt_policy_gateway_redistribution_config.GW_REDIST: Destruction complete after 1s
╷
│ Error:  Failed to delete Tier0 RedistributionConfig config faad73a4-0630-44aa-a3ff-0564fc1fc341: The policy object path=[/infra/tier-0s/365f9fac-cf14-41d2-a43a-b12a369c01dc/locale-services/default], used in this operation, has different version (2) than the current system version (3). Fetch the latest copy of the object and retry operation. (code 500071)
│ 
│ 
╵

At this point, I thought maybe I should try a terraform refresh, but that then yielded this crash:

nsxt_policy_gateway_redistribution_config.GW_T0_1_REDIST: Refreshing state... [id=faad73a4-0630-44aa-a3ff-0564fc1fc341]
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with data.nsxt_policy_edge_cluster.Edge1,
│   on main.tf line 20, in data "nsxt_policy_edge_cluster" "Edge1":
│   20: data "nsxt_policy_edge_cluster" "Edge1" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-nsxt_v3.2.4 plugin:

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

goroutine 130 [running]:
github.com/vmware/terraform-provider-nsxt/nsxt.resourceNsxtPolicyGatewayRedistributionConfigRead(0xc000314580, 0x1bc9100, 0xc000426ae0, 0x2728c40, 0xc000100000)
        github.com/vmware/terraform-provider-nsxt/nsxt/resource_nsxt_policy_gateway_redistribution_config.go:184 +0x4e6
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc000250b60, 0x1f45508, 0xc0004681c0, 0xc000314580, 0x1bc9100, 0xc000426ae0, 0x0, 0x0, 0x0)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:335 +0x1ee
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000250b60, 0x1f45508, 0xc0004681c0, 0xc000a98230, 0x1bc9100, 0xc000426ae0, 0xc00011e3b0, 0x0, 0x0, 0x0)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:624 +0x1cb
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc00014a510, 0x1f45508, 0xc0004681c0, 0xc000468200, 0xc0004681c0, 0x40b965, 0x1b91820)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:575 +0x43b
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ReadResource(0xc0008c2b80, 0x1f455b0, 0xc0004681c0, 0xc0004262a0, 0xc0008c2b80, 0xc0009cac90, 0xc0004a3ba0)
        github.com/hashicorp/[email protected]/tfprotov5/server/server.go:298 +0x105
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler(0x1bf3160, 0xc0008c2b80, 0x1f455b0, 0xc0009cac90, 0xc000426120, 0x0, 0x1f455b0, 0xc0009cac90, 0xc00061c300, 0x16f)
        github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:344 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00013f500, 0x1f527b8, 0xc0002df500, 0xc0004e6100, 0xc0001e5560, 0x26e7870, 0x0, 0x0, 0x0)
        google.golang.org/[email protected]/server.go:1194 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc00013f500, 0x1f527b8, 0xc0002df500, 0xc0004e6100, 0x0)
        google.golang.org/[email protected]/server.go:1517 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000034330, 0xc00013f500, 0x1f527b8, 0xc0002df500, 0xc0004e6100)
        google.golang.org/[email protected]/server.go:859 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/[email protected]/server.go:857 +0x1fd

Error: The terraform-provider-nsxt_v3.2.4 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.
@nu11ptr
Copy link
Author

nu11ptr commented Sep 8, 2021

Per the crash log, the problem seems to be here:

github.com/vmware/terraform-provider-nsxt/nsxt/resource_nsxt_policy_gateway_redistribution_config.go:184 +0x4e6

The reason for the nil pointer seems to be that the RouteRedistributionConfig field in var obj (type model.LocalServices) is nil (so that when BgpEnabled is referenced on the config var, a crash occurs. I'm not familiar with this codebase so can't take it further without more study.

	var obj model.LocaleServices
	if isPolicyGlobalManager(m) {
		client := gm_tier0s.NewDefaultLocaleServicesClient(connector)
		gmObj, err1 := client.Get(gwID, localeServiceID)
		if err1 != nil {
			return handleReadError(d, "Tier0 Redistribution Config", id, err1)
		}
		lmObj, err2 := convertModelBindingType(gmObj, model.LocaleServicesBindingType(), model.LocaleServicesBindingType())
		if err2 != nil {
			return err2
		}
		obj = lmObj.(model.LocaleServices)
	} else {
		var err error
		client := tier_0s.NewDefaultLocaleServicesClient(connector)
		obj, err = client.Get(gwID, localeServiceID)
		if err != nil {
			return handleReadError(d, "Tier0 Redistribution Config", id, err)
		}
	}

	config := obj.RouteRedistributionConfig
	d.Set("bgp_enabled", config.BgpEnabled)

@scila1996
Copy link

nsxt_policy_gateway_redistribution_config. I don't see config for Destination Protocol ? BGP or OSPF or Both, default it's will always set to BGP, while, my config is ospf

@annakhm annakhm added bug Bug crash Crash labels Sep 13, 2021
@annakhm
Copy link
Collaborator

annakhm commented Sep 16, 2021

Hi @nu11ptr, thank you for this report, and the crush is being fixed here #673.
As for the original problem - unfortunately this specific resource suffers from concurrency issues since it does not correspond to an API point in NSX. We hope to fix this (along with other intermittent errors) when native retry is implemented in the provider. For now, it is recommended to recreate the resource by deleting and creating it again, just as you did. I'm not sure why your resource was not refreshed which resulted in delete error - I'll try to repro and if unsuccessful, I might ask you for DEBUG logs, if possible. Thank you!

@annakhm
Copy link
Collaborator

annakhm commented Nov 3, 2021

I think what happened in your case is double redistribution resource that referred to the same router. This is bound to result in concurrency error, since both resources are attempting to destroy same resource.
Since the crush is fixed, subsequent reapply should fix the problem.

The best workaround for original concurrent_change problem is to reapply.
I'll keep this issue open until generic or resource-specific retry is implemented.

@annakhm annakhm linked a pull request Nov 3, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug crash Crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants