IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
340 stars 667 forks source link

Unable to spin BMS with multiple PCI network interfaces #5341

Open digvijay-ukirde opened 4 months ago

digvijay-ukirde commented 4 months ago

Community Note

Terraform CLI and Terraform IBM Provider Version

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

resource "ibm_is_bare_metal_server" "itself" {
  profile = local.profile
  name    = local.name
  image   = local.image
  zone    = local.zone
  keys    = [local.key]
  vpc     = local.vpc  
  primary_network_interface {
    name            = "dv-pri"
    subnet          = local.subnet
    security_groups = [local.sg]
  }
  # Trying to create second PCI interface without vLAN
  dynamic "network_interfaces" {
    for_each = [1]
    content {
      name                      = "dv-sec"
      subnet                    = local.subnet
      enable_infrastructure_nat = true
      allow_ip_spoofing         = true
      security_groups           = [local.sg]
      interface_type = "pci"
    }  
  } 
}

Debug Output

│ Error: [DEBUG] Create bare metal server err Expected only one oneOf fields to be set: got 0

│     "Result": {
│         "errors": [
│             {
│                 "code": "validation_failed_oneof",
│                 "message": "Expected only one oneOf fields to be set: got 0",
│                 "target": {
│                     "name": "BareMetalServerPrototype",
│                     "type": "field"
│                 }
│             },
│             {
│                 "code": "validation_failed_required",
│                 "message": "BareMetalServerByNetworkAttachment is invalid: Validation Failure for field: primary_network_attachment",
│                 "target": {
│                     "name": "BareMetalServerByNetworkAttachment.primary_network_attachment",
│                     "type": "field"
│                 }
│             },
│             {
│                 "code": "validation_failed_minimum",
│                 "message": "BareMetalServerByNetworkInterface is invalid: Validation Failure for field: vlan",
│                 "target": {
│                     "name": "BareMetalServerByNetworkInterface.vlan",
│                     "type": "field",
│                     "value": "0"
│                 }
│             }
│         ],
│         "trace": "beae1560-2a59-40b0-aaba-022b00e1055a"
│     },
│     "RawResult": null
│ }

Panic Output

Expected Behavior

A BMS with 2 PCI interfaces (without vLAN) should get created

Actual Behavior

It fails looking for allowed_vlans variable. If we provide a dummy vLAN -> allowed_vlans = [1], it works. Need to make allowed_vlans optional in such scenarios.

Steps to Reproduce

  1. terraform apply

Important Factoids

References

digvijay-ukirde commented 4 months ago

Response from BMS team member - It looks like it is making an assumption on PCI if the allowed_vlans is set. https://github.com/IBM-Cloud/terraform-provider-ibm/blob/master/ibm/service/vpc/resource_ibm_is_bare_metal_server.go#L1403 And it wrongly assumes there must be values in there (not an empty list) https://github.com/IBM-Cloud/terraform-provider-ibm/blob/master/ibm/service/vpc/resource_ibm_is_bare_metal_server.go#L1410

ujjwal-ibm commented 4 months ago

looking at it