CiscoDevNet / terraform-provider-fmc

Terraform Provider for FMC
https://registry.terraform.io/providers/CiscoDevNet/fmc/latest/docs
Mozilla Public License 2.0
16 stars 30 forks source link

Provider crashes when trying to update network group object #1

Closed richwats closed 2 years ago

richwats commented 3 years ago

I'm using the FMC 0.1.1 provider to dynamically create host objects and a couple of network object groups.

terraform {
  required_providers {
    fmc = {
      source = "CiscoDevNet/fmc"
      # version = "0.1.1"
    }
  }
}

provider "fmc" {
  # Configuration options
  fmc_username              = var.fmc_user
  fmc_password              = var.fmc_password
  fmc_host                  = var.fmc_server
  fmc_insecure_skip_verify  = true
}

locals {
  vm_group_a = {
      for vm in var.vm_group_a :
          vm.id => vm
  }
  vm_group_b = {
      for vm in var.vm_group_b :
          vm.id => vm
  }
}

### Build Host Objects per Server

resource "fmc_host_objects" "host-grp-a" {
  for_each = local.vm_group_a

  name = each.value.name
  value = each.value.clone.0.customize.0.network_interface.0.ipv4_address
  description = format("Host %s - Managed by Terraform", each.value.name)
}

resource "fmc_host_objects" "host-grp-b" {
  for_each = local.vm_group_b

  name = each.value.name
  value = each.value.clone.0.customize.0.network_interface.0.ipv4_address
  description = format("Host %s - Managed by Terraform", each.value.name)
}

resource "fmc_network_group_objects" "host-grp-a" {
  name          = "ist-host-group-a"
  description   = "Host Server Group A - Terraform Managed"

  dynamic "objects" {
    # for_each = each.value.attachments
    for_each = fmc_host_objects.host-grp-a
    content {
      id = objects.value["id"]
      type = objects.value["type"]
    }
  }
}

resource "fmc_network_group_objects" "host-grp-b" {
  name          = "ist-host-group-b"
  description   = "Host Server Group B - Terraform Managed"

  dynamic "objects" {
    # for_each = each.value.attachments
    for_each = fmc_host_objects.host-grp-a
    content {
      id = objects.value["id"]
      type = objects.value["type"]
    }
  }
}

I made a mistake and accidentally placed all host objects in a single group. I've now corrected this and the currently plan is attempting to remove 3 objects from the first group and then add these to the 2nd group.

Terraform Plan: run-fRWpdVTMckg6XCgq-plan-log.txt

It appears to crash when trying to remove the host objects from the group. The new group is correct but the old group still has all members present.

Provider Logs: run-fRWpdVTMckg6XCgq-apply-log.txt

adyanth commented 3 years ago

@richwats Looks like it is crashing at https://github.com/CiscoDevNet/terraform-provider-fmc/blob/d1db7f43d3ef95dd9aee01dd0c0b0f84831c997f/fmc/resource_fmc_network_group_objects.go#L254 because the name is empty.

Could you try passing in the name as well (as name = objects.value["name"]) along with id and type and see if it works?

adyanth commented 2 years ago

Closing for now as stale.