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

[Bug] elasticstack_fleet_integration_policy: cannot unmarshal json array into Go

Open Tim-herbie opened this issue 2 years ago • 1 comments

Describe the bug When I apply the terraform code, all resources will be created (also the elasticstack_fleet_integration_policy), but I get a error and can´t exeecute the terraform code again, because the resource will not added into the .tfstate file. If I apply the code again, it get another error message that the resource exists already.

To Reproduce Terraform configuration:

Steps to reproduce the behavior:

resource "elasticstack_fleet_agent_policy" "elastic-agent" {
  name            = "Elastic Agent Policy"
  namespace       = "default"
  description     = ""
  monitor_logs    = true
  monitor_metrics = true
  skip_destroy    = false
}

resource "elasticstack_fleet_integration" "custom-logs" {
  name    = "log"
  version = "2.3.0"
  force   = true
}

resource "elasticstack_fleet_integration_policy" "elastic-agent" {
  name                = "Custom Logs"
  namespace           = "default"
  description         = ""
  agent_policy_id     = elasticstack_fleet_agent_policy.elastic-agent.policy_id
  integration_name    = elasticstack_fleet_integration.custom-logs.name
  integration_version = elasticstack_fleet_integration.custom-logs.version

   input {
    input_id = "logs-logfile"
    enabled = true
    streams_json = jsonencode({
    "log.logs": {
          "enabled": true,
          "vars": {
            "paths": [
              "/var/log/syslog",
              "/var/log/messages"
            ],
            "exclude_files": [],
            "ignore_older": "72h",
            "data_stream.dataset": "syslog",
            "tags": [],
            "custom": ""
          }
        }
    })
  }

#depends_on = [ elasticstack_elasticsearch_ingest_pipeline.calico ]
}

terraform init terraform apply

Console Output:


│ Error: json: cannot unmarshal array into Go struct field PackagePolicy.item.inputs of type map[string]fleet.PackagePolicyInput
│
│   with elasticstack_fleet_integration_policy.elastic-agent,
│   on elastic-agent.tf line 18, in resource "elasticstack_fleet_integration_policy" "elastic-agent":
│   18: resource "elasticstack_fleet_integration_policy" "elastic-agent" {
│
╵

Expected behavior No errors

Versions (please complete the following information):

  • OS: MAC
  • Terraform Version: v1.5.7
  • Provider version: 0.11.0
  • Elasticsearch Version: 8.9.0

Tim-herbie avatar Jan 13 '24 13:01 Tim-herbie

IIRC the Fleet API became stable in 8.10. And this terraform provider is expecting that API responses from 8.10. So probably users of >= 8.10.0 are not affected by this.

andrewkroh avatar Apr 02 '24 18:04 andrewkroh

@andrewkroh I updated Elasticsearch to 8.10 and Kibana to 8.10.1 and it worked, Thank you!

Tim-herbie avatar Jun 22 '24 16:06 Tim-herbie