terraform-provider-logicmonitor icon indicating copy to clipboard operation
terraform-provider-logicmonitor copied to clipboard

Logicmonitor Preferred Collector ID is actually current collector ID

Open ChrisCAG opened this issue 4 months ago • 0 comments

Hi All, The logicmonitor preferred collector id is actually the current collector id, and therefore when using an auto balanced collector group (abcg) the preffered collector is constantly being requested to change. see an example of a plan below.

  # module.addc.logicmonitor_device.device[0] will be updated in-place
  ~ resource "logicmonitor_device" "device" {
      ~ custom_properties                = [
          + {
              + name  = "system.categories"
              + value = "MicrosoftDomainController,Windows_DNS,Windows_DHCP"
            },
            {
                name  = "patch"
                value = "7,21,Night"
            },
            {
                name  = "resolver.group"
                value = "Infrastructure & Cloud Operations"
            },
          - {
              - name  = "system.categories"
              - value = "MicrosoftDomainController,Windows_DNS,Windows_DHCP"
            },
        ]
      ~ host_group_ids                   = "272,107,174,284,5,50,189" -> "50"
        id                               = "595"
        name                             = "addc.network.com"
      ~ preferred_collector_id           = 16 -> 12
        # (34 unchanged attributes hidden)
    }

As you can see, it is trying to set the preferred collector from 16 to 12.

the code for the actual device is as follows.

module "addc" {
  ## These are ALWAYS Static, dont edit
  source      = "../../Modules/Device"
  environment = module.common.environment

  ## Variables for the device
  production      = true
  sandbox         = false
  enable_alerting = true
  display_name    = "ADDC - DHCP - FS - EQ DC"
  host_name       = "[removed]"
  host_group_ids  = data.terraform_remote_state.groups_state.outputs.domain_network_group_id
  resolver_group = "Infrastructure & Cloud Operations"
  custom_properties = [
    {
      name  = "system.categories"
      value = "MicrosoftDomainController,Windows_DNS,Windows_DHCP"
    },
    {
      name  = "patch"
      value = "7,21,Night"
    },
  ]
}

and the module defines a device_group as follows, I've also included the variable defaults below for the relevant parts.

resource "logicmonitor_device" "device" {
  count                            = var.environment ? local.production_int : local.sandbox_int
  display_name                     = var.display_name
  name                             = var.host_name
  auto_balanced_collector_group_id = var.abcg_collector_group_id != null ? var.abcg_collector_group_id : data.terraform_remote_state.collectors_state.outputs.bca_abcg_group_id
  preferred_collector_id           = var.preferred_collector_id != null ? var.preferred_collector_id : data.terraform_remote_state.collectors_state.outputs.dc_collector_1_id
  host_group_ids                   = var.host_group_ids
  disable_alerting                 = !var.enable_alerting
  related_device_id                = -1
  custom_properties                = [for obj in local.concatinated_custom_properties : obj if obj.name != "" && obj.value != ""]

  lifecycle {
    ignore_changes = [
      current_collector_id,
    ]
  }
}

variable "abcg_collector_group_id" {
  type        = number
  description = "The Auto Balanced Collector Group ID you wish to use"
  default     = null #data.terraform_remote_state.collectors_state.outputs.bca_abcg_collector_group_id
}

variable "preferred_collector_id" {
  type        = number
  description = "The preffered collector ID, use the first collector in the auto balanced group"
  default     = null #data.terraform_remote_state.collectors_state.outputs.dc_collector_1_id
}

as you can see, its defaulted to dc collector 1, which in our environment is pd-logcol-003 (see the screenshot below)

image

as you can see, this is changing the preffered collector (from logcol 001 to collector_dc_1/logcol 003 )

I'm aware this is a little unintuitive, but for reference, this is the collectors code configuration

resource "logicmonitor_collector" "dc_collector_1" {
  arch                                 = "Win64"
  collector_group_id                   = logicmonitor_collector_group.dc_collector_group.id
  collector_size                       = "medium"
  company                              = module.common.logic_monitor_instance_name
  description                          = "PD-LOGCOL-003"
  escalating_chain_id                  = data.terraform_remote_state.escalations_state.outputs.platform_tooling_chain_id
  monitor_others                       = false
  build                                = "36000"
  ea                                   = false
  enable_fail_back                     = true
  enable_fail_over_on_collector_device = true
  need_auto_create_collector_device    = true

  lifecycle {
    ignore_changes = [
      arch,
      build,
      collector_size,
      company,
      number_of_instances,
    ]
  }
}

Hopefully this is enough to show that the preferred collector, isn't actually a static value that you can set, but is actually the current collector that the device is assigned to, additionally, the fact the preferred collector must be set, but can also change due to an abcg, there's always going to be unnessecary changes, bloating the plan and slowing down deployment.

ChrisCAG avatar Oct 09 '24 10:10 ChrisCAG