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

unmarshal computed property `field_names` on `field_extraction_rule`

Open hashi-breed opened this issue 4 months ago • 3 comments

The REST API documentation indicates that the list of identifiers projected from the parse expression configured in the field_extraction_rule resource. The json data for fieldNames will contain an array of strings for each named field projection.

we added FieldNames to the the terraform schema as field_names, extended the client, updated the acc tests, and updated docs

hashi-breed avatar Jul 23 '25 23:07 hashi-breed

terraform {
  required_providers {
    sumologic = {
      source = "sumologic/sumologic"
    }
  }
}
provider "sumologic" {}
data "sumologic_caller_identity" "this" {}
output "access_id" {
  value = data.sumologic_caller_identity.this.access_id
}
resource "sumologic_field_extraction_rule" "this" {
  name = "test_fer"
  scope = "_sourceHost=127.0.0.1 AND NOT _sourceCategory"
  parse_expression =<<-END_PARSE
    "sumologic" as device_vendor
    | "terraform-provider" as device_product
    | "unparsed-test" as device_facility
    | fields device_vendor,device_product,device_facility
  END_PARSE
  enabled = true
}
output "fer" {
  value = {
    name   = sumologic_field_extraction_rule.this.name
    scope  = sumologic_field_extraction_rule.this.scope
    parse  = sumologic_field_extraction_rule.this.parse_expression
    fields = sumologic_field_extraction_rule.this.field_names
  }
}

yields

fer = {
  "fields" = tolist([
    "device_vendor",
    "device_product",
    "device_facility",
  ])
  "name" = "test_fer"
  "parse" = <<-EOT
    "sumologic" as device_vendor
      | "terraform-provider" as device_product
      | "unparsed-test" as device_facility
      | fields device_vendor,device_product,device_facility
  EOT
  "scope" = "_sourceHost=127.0.0.1 AND NOT _sourceCategory"
}

hashi-breed avatar Jul 23 '25 23:07 hashi-breed

separately, i'm looking into the consequences of exporting this as a computed List of String instead of a Set of String elements. i'm not sure what role tolist([]) is doing here, (or if that's normal)

  "fields" = tolist([
    "device_vendor",
    "device_product",
    "device_facility",
  ])

but changing the underlying schema to a Set of String yields much the same result, except toset([])

  "fields" = toset([
    "device_facility",
    "device_product",
    "device_vendor",
  ])

state shows it in collection agnostic representation:

resource "sumologic_field_extraction_rule" "this" {
    enabled          = true
    field_names      = [
        "device_facility",
        "device_product",
        "device_vendor",
    ]
    id               = "00000000000206B8"
    name             = "test_fer"
    parse_expression = <<-EOT
        "sumologic" as device_vendor
        | "terraform-provider" as device_product
        | "unparsed-test" as device_facility
        | fields device_vendor,device_product
    EOT
    scope            = "_sourceHost=127.0.0.1 AND NOT _sourceCategory"
}

but doesn't update state.... so we're bugged on at least that part

hashi-breed avatar Jul 28 '25 21:07 hashi-breed

@SumoLogic/tf-platform-team I've been chatting with Ryan on Slack. To run the acceptance tests, I duplicated this PR and fixed the change log here: https://github.com/SumoLogic/terraform-provider-sumologic/pull/797. Recommend closing this one after the other is approved and merged.

ErikAtSumo avatar Jul 30 '25 23:07 ErikAtSumo