canonical / terraform-provider-maas

Terraform MAAS provider
Mozilla Public License 2.0
60 stars 43 forks source link

VLAN Interfaces Conflict with Own Definition of Parent Crashing Provider #204

Closed sempervictus closed 2 months ago

sempervictus commented 2 months ago

Once VLAN interfaces have been created successfully:

data "maas_network_interface_physical" "metal-1" {
  for_each = maas_machine.metal-1
  machine  = each.value.id
  name     = "enp3s0"
}
resource "maas_network_interface_vlan" "metal-1" {
  for_each = data.maas_network_interface_physical.metal-1
  machine  = each.value.machine
  parent   = each.value.id
  vlan     = maas_vlan.default_50.id
  fabric   = maas_vlan.default_50.fabric
}

the next state update changes their parent attribute from the name of the NIC to its ID. When TF tries to actually perform that change, the provider crashes spectacularly:

  # maas_network_interface_vlan.metal-1["test-metal1-00"] will be updated in-place
  ~ resource "maas_network_interface_vlan" "metal-1" {
        id        = "16"
      ~ parent    = "enp3s0" -> "3"
        tags      = []
        # (5 unchanged attributes hidden)
    }

  # maas_network_interface_vlan.metal-1["test-metal1-01"] will be updated in-place
  ~ resource "maas_network_interface_vlan" "metal-1" {
        id        = "14"
      ~ parent    = "enp3s0" -> "11"
        tags      = []
        # (5 unchanged attributes hidden)
    }

  # maas_network_interface_vlan.metal-1["test-metal1-02"] will be updated in-place
  ~ resource "maas_network_interface_vlan" "metal-1" {
        id        = "15"
      ~ parent    = "enp3s0" -> "12"
        tags      = []
        # (5 unchanged attributes hidden)
    }

  # maas_network_interface_vlan.metal-1["test-metal1-03"] will be updated in-place
  ~ resource "maas_network_interface_vlan" "metal-1" {
        id        = "17"
      ~ parent    = "enp3s0" -> "10"
        tags      = []
        # (5 unchanged attributes hidden)
    }
...
╷
│ Error: Plugin did not respond
│ 
│   with maas_network_interface_vlan.metal-1["test-metal1-00"],
│   on maas-machines.tf line 16, in resource "maas_network_interface_vlan" "metal-1":
│   16: resource "maas_network_interface_vlan" "metal-1" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵
╷
│ Error: Request cancelled
│ 
│   with maas_network_interface_vlan.metal-1["test-metal1-03"],
│   on maas-machines.tf line 16, in resource "maas_network_interface_vlan" "metal-1":
│   16: resource "maas_network_interface_vlan" "metal-1" {
│ 
│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵
╷
│ Error: Plugin did not respond
│ 
│   with maas_network_interface_vlan.metal-1["test-metal1-01"],
│   on maas-machines.tf line 16, in resource "maas_network_interface_vlan" "metal-1":
│   16: resource "maas_network_interface_vlan" "metal-1" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with maas_network_interface_vlan.metal-1["test-metal1-02"],
│   on maas-machines.tf line 16, in resource "maas_network_interface_vlan" "metal-1":
│   16: resource "maas_network_interface_vlan" "metal-1" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵
╷
│ Error: Request cancelled
│ 
│   with maas_subnet.prov_50_subnet_1,
│   on maas-net.tf line 52, in resource "maas_subnet" "prov_50_subnet_1":
│   52: resource "maas_subnet" "prov_50_subnet_1" {
│ 
│ The plugin.(*GRPCProvider).ValidateResourceConfig request was cancelled.
╵
Stack trace from the terraform-provider-maas plugin:

panic: interface conversion: interface {} is int, not string

goroutine 30 [running]:
terraform-provider-maas/maas.resourceNetworkInterfaceVlanUpdate({0xf05830, 0x74f15426ed20}, 0x74f15468c800, {0xc43260, 0x74f1545c2008})
    /build/terraform-provider-maas-git-sv/src/src/github.com/terraform-providers/terraform-provider-maas/maas/resource_maas_network_interface_vlan.go:170 +0x4f4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x74f154177c00, {0xf05788, 0x74f1543f49f0}, 0x74f15468c800, {0xc43260, 0x74f1545c2008})
    /build/terraform-provider-maas-git-sv/src/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:840 +0x119
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x74f154177c00, {0xf05788, 0x74f1543f49f0}, 0x74f1543d5450, 0x74f15468c680, {0xc43260, 0x74f1545c2008})
    /build/terraform-provider-maas-git-sv/src/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:947 +0x83a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x74f1543ba648, {0xf05788?, 0x74f1543f4930?}, 0x74f1542a8af0)
    /build/terraform-provider-maas-git-sv/src/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xd5c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x74f1542af680, {0xf05788?, 0x74f1543f40f0?}, 0x74f154163a40)
    /build/terraform-provider-maas-git-sv/src/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:865 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xd93e00, 0x74f1542af680}, {0xf05788, 0x74f1543f40f0}, 0x74f15468c000, 0x0)
    /build/terraform-provider-maas-git-sv/src/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0x74f1541a5400, {0xf05788, 0x74f1543f4060}, {0xf0a560, 0x74f1542fc180}, 0x74f154195200, 0x74f1543e2000, 0x14b4a38, 0x0)
    /build/terraform-provider-maas-git-sv/src/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1369 +0xdf8
google.golang.org/grpc.(*Server).handleStream(0x74f1541a5400, {0xf0a560, 0x74f1542fc180}, 0x74f154195200)
    /build/terraform-provider-maas-git-sv/src/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1780 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
    /build/terraform-provider-maas-git-sv/src/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 15
    /build/terraform-provider-maas-git-sv/src/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1030 +0x125

Error: The terraform-provider-maas plugin crashed!
sempervictus commented 2 months ago

Actually not sure how it creates the interfaces that way in the first place given that the TF is passing in the ID :-.