Skip to content

[Bug] When importing elasticstack_kibana_synthetics_monitor resources locations appear as changes when running terraform plan #1471

@kstergiopoulos

Description

@kstergiopoulos

Describe the bug
When importing existing elasticstack_kibana_synthetics_monitor resources, the locations argument, instead of matching the existing configuration, is counted as a change when running terraform plan.

To Reproduce
Steps to reproduce the behavior:

  1. TF configuration used:
    Terraform .tfvars content example. Only one item in the object for the sake of readability. If more items of the same nature (browser monitors) with a public location where present they were going to produce the same error.
syntheticsMonitors = {

  a_synthetic_mon_browser_1 = {
    id        = "default/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    name      = "www.somesite.com"
    space_id  = "default"
    schedule  = 10
    locations = ["germany", "united_kingdom"]
    enabled   = true
    tags      = ["website", "prd"]
    alert = {
      status = {
        enabled = true
      }
      tls = {
        enabled = true
      }
    }
    browser = {
      url           = "https://www.somesite.com/"
      inline_script = "step('Go to https://www.somesite.com/', async () => {await page.goto('https://www.somesite.com/');});"
      ignore_https_errors     = false
      screenshots             = "on"
      ssl_verification_mode   = "full"
      ssl_supported_protocols = ["TLSv1.2", "TLSv1.3"]
      max_attempts            = 2
      max_redirects           = 0
      mode                    = "any"
      ipv4                    = true
      ipv6                    = true
      retest_on_failure       = true
    }
  }
}

main.tf file contents example

import {
  for_each = var.syntheticsMonitors
  to       = elasticstack_kibana_synthetics_monitor.monitors[each.key]
  id       = each.value.id
}

resource "elasticstack_kibana_synthetics_monitor" "monitors" {
  for_each = var.syntheticsMonitors
  name     = each.value.name
  alert    = lookup(each.value, "alert", null)
  browser  = lookup(each.value, "browser", null)
  enabled  = lookup(each.value, "enabled", true)
  http     = lookup(each.value, "http", null)
  icmp     = lookup(each.value, "icmp", null)
  locations = lookup(each.value, "locations", null)
  params            = lookup(each.value, "params", null)
  private_locations = lookup(each.value, "private_locations", null)
  retest_on_failure = lookup(each.value, "retest_on_failure", true)
  schedule          = lookup(each.value, "schedule", null)
  service_name      = lookup(each.value, "service_name", null)
  space_id          = lookup(each.value, "space_id", "default")
  tags              = lookup(each.value, "tags", null)
  tcp               = lookup(each.value, "tcp", null)
  timeout           = lookup(each.value, "timeout", 16)
}

Providers configuration

terraform {
  required_version = "> 1.7"
  required_providers {
    elasticstack = {
      source  = "elastic/elasticstack"
      version = "0.12.2"
    }
  }
}

provider "elasticstack" {
  elasticsearch {
    api_key   = var.elastic_api_key
    endpoints = ["https://xxxxx-xxxxx-xxxxx.xxx.xxxx.xxxxx.xxxxx.elastic-cloud.com:443"]
  }
  kibana {
    endpoints = ["https://xxxxx-xxxxx-xxxxx.xxx.xxxx.xxxxx.xxxxx.elastic-cloud.com:443"]
  }
  fleet {
    endpoint = "https://xxxxx-xxxxx-xxxxx.xxx.xxxx.xxxxx.xxxxx.elastic-cloud.com:443"
  }
}

Locations part of the API response of the existing monitor which we are trying to import:

"locations": [
    {
      "id": "europe-west3-a",
      "label": "Europe - Germany",
      "geo": {
        "lat": 50.110924,
        "lon": 8.682127
      },
      "isServiceManaged": true
    },
    {
      "id": "europe-west2-a",
      "label": "Europe - United Kingdom",
      "geo": {
        "lat": 51.18281,
        "lon": -0.14835
      },
      "isServiceManaged": true
    }
  ],
  1. TF operations to execute to get the error: terraform plan
  2. Plan output example:
# elasticstack_kibana_synthetics_monitor.monitors["a_synthetic_mon_browser_1"] will be updated in-place
  # (imported from "default/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
  ~ resource "elasticstack_kibana_synthetics_monitor" "monitors" {
        alert     = {
            status = {
                enabled = true
            }
            tls    = {
                enabled = true
            }
        }
        browser   = {
            ignore_https_errors = false
          + inline_script       = "step('Go to https://www.somesite.com/', async () => {await page.goto('https://www.somesite.com/');});"
            screenshots         = "on"
        }
        enabled   = true
        id        = "default/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      + locations = [
          + "germany",
          + "united_kingdom",
        ]
        name      = "www.somesite.com"
        namespace = "default"
        schedule  = 10
        space_id  = "default"
        tags      = [
            "website",
            "prd",
        ]
        timeout   = 0
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions