Skip to content

[Bug] Error: failed to import saved objects - 400 Bad Request #702

Closed
@Alfaxomo

Description

@Alfaxomo

Describe the bug
Creating a dashboard and query saved object results in in a 400 Bad Request error. A tag saved object works fine.

To Reproduce
Steps to reproduce the behavior:

  1. TF configuration used '...'

main.tf

terraform {
  required_version = ">= 1.0.0"
  required_providers {
    elasticstack = {
      source = "elastic/elasticstack"
      version = "0.11.4"
    }
  }
}

provider "elasticstack" {
  elasticsearch {
    username  = var.elastic_username
    password  = var.elastic_password
    endpoints = [var.elastic_endpoint]
  }
  kibana {
    username  = var.elastic_username
    password  = var.elastic_password
    endpoints = [var.kibana_endpoint]
  }
}

locals.tf

locals {
  dashboards = toset([
    "dashboard0",
  ])
}

locals {
  queries = toset([
    "query0"
  ])
}

locals {
  tags = toset([
    "tag0"
  ])
}

saved_objects.tf

resource "elasticstack_kibana_import_saved_objects" "dashboards" {
  for_each      = local.dashboards
    overwrite     = true
    file_contents = file("saved_objects/dashboard-${each.value}.ndjson")
}

resource "elasticstack_kibana_import_saved_objects" "queries" {
  for_each      = local.queries
    overwrite     = true
    file_contents = file("saved_objects/query-${each.value}.ndjson")
}

resource "elasticstack_kibana_import_saved_objects" "tags" {
  for_each      = local.tags
    overwrite     = true
    file_contents = file("saved_objects/tag-${each.value}.ndjson")
}

Same behavior if I remove the for_each/locals and explicitly define the saved objects.

  1. TF operations to execute to get the error '...' [e.g terraform plan,terraform apply, terraform destroy]
terraform apply
  1. See the error in the output '...'

terraform plan

  # elasticstack_kibana_import_saved_objects.queries["query0"] will be created
  + resource "elasticstack_kibana_import_saved_objects" "queries" {
      + errors          = (known after apply)
      + file_contents   = jsonencode(
            {
              + attributes           = {
                  + description  = ""
                  + filters      = [
                      + {
                          + "$state" = {
                              + store = "appState"
                            }
... more jsonencoded json

  # elasticstack_kibana_import_saved_objects.dashboards["dashboard0"] will be created
  + resource "elasticstack_kibana_import_saved_objects" "dashboards" {
      + errors          = (known after apply)
      + file_contents   = jsonencode(
            {
              + attributes           = {
                  + description           = ""
                  + hits                  = 0
                  + kibanaSavedObjectMeta = {
                      + searchSourceJSON = jsonencode(
                            {
                              + filter = []
                              + query  = {
                                  + language = "kuery"
                                  + query    = ""
                                }
                            }
                        )
                    }
... more jsonencoded json

terraform apply

  # elasticstack_kibana_import_saved_objects.dashboards["dashboard0"] will be created
  + resource "elasticstack_kibana_import_saved_objects" "dashboards" {
      + errors          = (known after apply)
      + file_contents   = jsonencode(
            {
              + attributes           = {
                  + description           = ""
                  + hits                  = 0
                  + kibanaSavedObjectMeta = {
                      + searchSourceJSON = jsonencode(
                            {
                              + filter = []
                              + query  = {
                                  + language = "kuery"
                                  + query    = ""
                                }
                            }
                        )
                    }
... more jsonencoded json

  # elasticstack_kibana_import_saved_objects.queries["query0"] will be created
  + resource "elasticstack_kibana_import_saved_objects" "queries" {
      + errors          = (known after apply)
      + file_contents   = jsonencode(
            {
              + attributes           = {
                  + description  = ""
                  + filters      = [
                      + {
                          + "$state" = {
                              + store = "appState"
                            }
... more jsonencoded json

│ Error: failed to import saved objects
│
│   with elasticstack_kibana_import_saved_objects.dashboards["dashboard0"],
│   on SavedObjects.tf line 3, in resource "elasticstack_kibana_import_saved_objects" "dashboards":
│    3: resource "elasticstack_kibana_import_saved_objects" "dashboards" {
│
│ 400 Bad Request

│ Error: failed to import saved objects
│
│   with elasticstack_kibana_import_saved_objects.queries["query0"],
│   on SavedObjects.tf line 9, in resource "elasticstack_kibana_import_saved_objects" "queries":
│    9: resource "elasticstack_kibana_import_saved_objects" "queries" {
│
│ 400 Bad Request
```

**Expected behavior**
terraform apply completes successfully

**Debug output**
Run `terraform` command with `TF_LOG=trace` and provide extended information on TF operations. **Please ensure you redact any base64 encoded credentials from your output**. 
eg
```
[DEBUG] provider.terraform-provider-elasticstack_v0.11.0: Authorization: Basic xxxxx==
```

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Versions (please complete the following information):**
- OS: Ubuntu Linux (WSL) bookworm/sid
- Terraform Version: v1.3.7 (same behaviour on latest version)
- Provider version: 0.11.4
- Elasticsearch Version: 8.14.3

**Additional context**
Add any other context about the problem here.

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