Skip to content

[Bug] SLM Policies that contain metadata cause terraform apply to fail #1409

@herrBez

Description

@herrBez

Describe the bug
An SLM Policy that contain metadata will cause the terraform apply command to fail with a type issue.

To Reproduce
Steps to reproduce the behavior:

  1. TF configuration used:
resource "elasticstack_elasticsearch_snapshot_lifecycle" "slm_policy" {
  name = "my_slm_policy"

  schedule      = "0 30 1 * * ?"
  snapshot_name = "<daily-snap-{now/d}>"
  repository    = "found-snapshots"

  indices              = ["data-*", "important"]
  ignore_unavailable   = false
  include_global_state = false

  expire_after = "30d"
  min_count    = 5
  max_count    = 50

  metadata = jsonencode({
    created_by = "terraform"
    purpose    = "daily backup"
  })
}
  1. TF operations to execute to get the error terraform apply

  2. See the error in the output

elasticstack_elasticsearch_snapshot_lifecycle.slm_policy: Creating...
╷
│ Error: metadata: '' expected type 'string', got unconvertible type '[]uint8', value: '[123 34 99 114 101 97 116 101 100 95 98 121 34 58 34 116 101 114 114 97 102 111 114 109 34 44 34 112 117 114 112 111 115 101 34 58 34 100 97 105 108 121 32 98 97 99 107 117 112 34 125]'

Expected behavior
The SLM Policy should work and add the metadata as documented

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

2025-10-31T12:21:12.419+0100 [INFO]  Terraform version: 1.5.7
2025-10-31T12:21:12.419+0100 [DEBUG] using github.com/hashicorp/go-tfe v1.26.0
2025-10-31T12:21:12.419+0100 [DEBUG] using github.com/hashicorp/hcl/v2 v2.16.2
2025-10-31T12:21:12.419+0100 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.0
2025-10-31T12:21:12.419+0100 [DEBUG] using github.com/zclconf/go-cty v1.12.2
2025-10-31T12:21:12.419+0100 [INFO]  Go runtime version: go1.22.2
2025-10-31T12:21:12.419+0100 [INFO]  CLI args: []string{"terraform", "apply"}
2025-10-31T12:21:12.419+0100 [DEBUG] Attempting to open CLI config file: /Users/mirko/.terraformrc
2025-10-31T12:21:12.419+0100 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2025-10-31T12:21:12.420+0100 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2025-10-31T12:21:12.420+0100 [DEBUG] ignoring non-existing provider search directory /Users/mirko/.terraform.d/plugins
2025-10-31T12:21:12.420+0100 [DEBUG] ignoring non-existing provider search directory /Users/mirko/Library/Application Support/io.terraform/plugins
2025-10-31T12:21:12.420+0100 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2025-10-31T12:21:12.420+0100 [INFO]  CLI command args: []string{"apply"}
2025-10-31T12:21:12.421+0100 [DEBUG] New state was assigned lineage "8497a581-1365-b3f8-a545-33079e84fa96"
2025-10-31T12:21:12.450+0100 [DEBUG] checking for provisioner in "."
2025-10-31T12:21:12.453+0100 [DEBUG] checking for provisioner in "/opt/homebrew/bin"
2025-10-31T12:21:12.454+0100 [INFO]  backend/local: starting Apply operation
2025-10-31T12:21:12.457+0100 [DEBUG] created provider logger: level=debug
2025-10-31T12:21:12.457+0100 [INFO]  provider: configuring client automatic mTLS
2025-10-31T12:21:12.462+0100 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1 args=[.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1]
2025-10-31T12:21:12.464+0100 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1 pid=41868
2025-10-31T12:21:12.464+0100 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1
2025-10-31T12:21:12.532+0100 [INFO]  provider.terraform-provider-elasticstack_v0.12.1: configuring server automatic mTLS: timestamp=2025-10-31T12:21:12.532+0100
2025-10-31T12:21:12.537+0100 [DEBUG] provider: using plugin: version=6
2025-10-31T12:21:12.537+0100 [DEBUG] provider.terraform-provider-elasticstack_v0.12.1: plugin address: address=/var/folders/fm/fdrb64891ll3z3j0vn23rc_40000gn/T/plugin809206985 network=unix timestamp=2025-10-31T12:21:12.537+0100
2025-10-31T12:21:12.554+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-10-31T12:21:12.555+0100 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1 pid=41868
2025-10-31T12:21:12.555+0100 [DEBUG] provider: plugin exited
2025-10-31T12:21:12.555+0100 [DEBUG] Building and walking validate graph
2025-10-31T12:21:12.555+0100 [DEBUG] ProviderTransformer: "elasticstack_elasticsearch_snapshot_lifecycle.slm_policy" (*terraform.NodeValidatableResource) needs provider["registry.terraform.io/elastic/elasticstack"]
2025-10-31T12:21:12.555+0100 [DEBUG] ReferenceTransformer: "elasticstack_elasticsearch_snapshot_lifecycle.slm_policy" references: []
2025-10-31T12:21:12.555+0100 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/elastic/elasticstack\"]" references: []
2025-10-31T12:21:12.555+0100 [DEBUG] Starting graph walk: walkValidate
2025-10-31T12:21:12.555+0100 [DEBUG] created provider logger: level=debug
2025-10-31T12:21:12.555+0100 [INFO]  provider: configuring client automatic mTLS
2025-10-31T12:21:12.557+0100 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1 args=[.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1]
2025-10-31T12:21:12.559+0100 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1 pid=41869
2025-10-31T12:21:12.559+0100 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1
2025-10-31T12:21:12.572+0100 [INFO]  provider.terraform-provider-elasticstack_v0.12.1: configuring server automatic mTLS: timestamp=2025-10-31T12:21:12.571+0100
2025-10-31T12:21:12.576+0100 [DEBUG] provider.terraform-provider-elasticstack_v0.12.1: plugin address: address=/var/folders/fm/fdrb64891ll3z3j0vn23rc_40000gn/T/plugin1198376718 network=unix timestamp=2025-10-31T12:21:12.576+0100
2025-10-31T12:21:12.576+0100 [DEBUG] provider: using plugin: version=6
2025-10-31T12:21:12.594+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-10-31T12:21:12.594+0100 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1 pid=41869
2025-10-31T12:21:12.594+0100 [DEBUG] provider: plugin exited
2025-10-31T12:21:12.595+0100 [INFO]  backend/local: apply calling Plan
2025-10-31T12:21:12.595+0100 [DEBUG] Building and walking plan graph for NormalMode
2025-10-31T12:21:12.595+0100 [DEBUG] ProviderTransformer: "elasticstack_elasticsearch_snapshot_lifecycle.slm_policy (expand)" (*terraform.nodeExpandPlannableResource) needs provider["registry.terraform.io/elastic/elasticstack"]
2025-10-31T12:21:12.595+0100 [DEBUG] ReferenceTransformer: "elasticstack_elasticsearch_snapshot_lifecycle.slm_policy (expand)" references: []
2025-10-31T12:21:12.595+0100 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/elastic/elasticstack\"]" references: []
2025-10-31T12:21:12.595+0100 [DEBUG] Starting graph walk: walkPlan
2025-10-31T12:21:12.595+0100 [DEBUG] created provider logger: level=debug
2025-10-31T12:21:12.595+0100 [INFO]  provider: configuring client automatic mTLS
2025-10-31T12:21:12.597+0100 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1 args=[.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1]
2025-10-31T12:21:12.598+0100 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1 pid=41870
2025-10-31T12:21:12.598+0100 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1
2025-10-31T12:21:12.608+0100 [INFO]  provider.terraform-provider-elasticstack_v0.12.1: configuring server automatic mTLS: timestamp=2025-10-31T12:21:12.608+0100
2025-10-31T12:21:12.613+0100 [DEBUG] provider: using plugin: version=6
2025-10-31T12:21:12.613+0100 [DEBUG] provider.terraform-provider-elasticstack_v0.12.1: plugin address: address=/var/folders/fm/fdrb64891ll3z3j0vn23rc_40000gn/T/plugin524751362 network=unix timestamp=2025-10-31T12:21:12.613+0100
2025-10-31T12:21:12.629+0100 [DEBUG] ReferenceTransformer: "elasticstack_elasticsearch_snapshot_lifecycle.slm_policy" references: []
2025-10-31T12:21:13.100+0100 [DEBUG] provider.terraform-provider-elasticstack_v0.12.1: elasticsearch request [GET https://test-bcf426.es.us-central1.gcp.cloud.es.io:443/_slm/policy/my_slm_policy] executed. Took 469.504ms. <nil>: tf_mux_provider=tf5to6server.v5tov6Server tf_provider_addr=registry.terraform.io/elastic/elasticstack tf_req_id=773ec5a0-1de9-a293-6aa3-f7791f3106dc tf_rpc=ReadResource @caller=github.com/elastic/terraform-provider-elasticstack/internal/clients/config/debug.go:37 @module=elasticstack tf_resource_type=elasticstack_elasticsearch_snapshot_lifecycle timestamp=2025-10-31T12:21:13.099+0100
2025-10-31T12:21:13.100+0100 [DEBUG] provider.terraform-provider-elasticstack_v0.12.1: elasticsearch API Response for [GET https://test-bcf426.es.us-central1.gcp.cloud.es.io:443/_slm/policy/my_slm_policy] Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 200 OK
Content-Type: application/json
Date: Fri, 31 Oct 2025 11:21:13 GMT
X-Cloud-Request-Id: tCwgc3zETKutbFRZ4F6KWA
X-Elastic-Product: Elasticsearch
X-Found-Handling-Cluster: 4a00a1361aa34b109a5d0b8f816fdfcf
X-Found-Handling-Instance: instance-0000000005

{
 "my_slm_policy": {
  "version": 1,
  "modified_date_millis": 1761845599817,
  "policy": {
   "name": "<daily-snap-{now/d}>",
   "schedule": "0 30 1 * * ?",
   "repository": "found-snapshots",
   "config": {
    "include_global_state": false,
    "indices": [
     "data-*",
     "important"
    ],
    "metadata": {
     "purpose": "daily backup",
     "created_by": "terraform"
    },
    "expand_wildcards": "open,hidden",
    "ignore_unavailable": false
   },
   "retention": {
    "expire_after": "30d",
    "min_count": 5,
    "max_count": 50
   }
  },
  "last_failure": {
   "snapshot_name": "daily-snap-2025.10.31-yutepwqas_ycfhljwl_kfa",
   "time": 1761874200290,
   "details": "{\"type\":\"index_not_found_exception\",\"reason\":\"no such index [important]\",\"resource.type\":\"index_or_alias\",\"resource.id\":\"important\",\"index_uuid\":\"_na_\",\"index\":\"important\"}"
  },
  "next_execution_millis": 1761960600000,
  "stats": {
   "policy": "my_slm_policy",
   "snapshots_taken": 0,
   "snapshots_failed": 1,
   "snapshots_deleted": 0,
   "snapshot_deletion_failures": 0
  }
 }
}
-----------------------------------------------------: tf_mux_provider=tf5to6server.v5tov6Server tf_req_id=773ec5a0-1de9-a293-6aa3-f7791f3106dc tf_resource_type=elasticstack_elasticsearch_snapshot_lifecycle @module=elasticstack tf_provider_addr=registry.terraform.io/elastic/elasticstack tf_rpc=ReadResource @caller=github.com/elastic/terraform-provider-elasticstack/internal/clients/config/debug.go:70 timestamp=2025-10-31T12:21:13.100+0100
2025-10-31T12:21:13.101+0100 [DEBUG] provider.terraform-provider-elasticstack_v0.12.1: 2025/10/31 12:21:13 [ERROR] setting state: metadata: '' expected type 'string', got unconvertible type '[]uint8', value: '[123 34 99 114 101 97 116 101 100 95 98 121 34 58 34 116 101 114 114 97 102 111 114 109 34 44 34 112 117 114 112 111 115 101 34 58 34 100 97 105 108 121 32 98 97 99 107 117 112 34 125]'
2025-10-31T12:21:13.101+0100 [ERROR] provider.terraform-provider-elasticstack_v0.12.1: Response contains error diagnostic: tf_resource_type=elasticstack_elasticsearch_snapshot_lifecycle tf_rpc=ReadResource @caller=github.com/hashicorp/terraform-plugin-go@v0.29.0/tfprotov6/internal/diag/diagnostics.go:58 @module=sdk.proto diagnostic_detail= tf_provider_addr=registry.terraform.io/elastic/elasticstack diagnostic_summary="metadata: '' expected type 'string', got unconvertible type '[]uint8', value: '[123 34 99 114 101 97 116 101 100 95 98 121 34 58 34 116 101 114 114 97 102 111 114 109 34 44 34 112 117 114 112 111 115 101 34 58 34 100 97 105 108 121 32 98 97 99 107 117 112 34 125]'" tf_proto_version=6.10 tf_req_id=773ec5a0-1de9-a293-6aa3-f7791f3106dc diagnostic_severity=ERROR timestamp=2025-10-31T12:21:13.100+0100
2025-10-31T12:21:13.101+0100 [ERROR] vertex "elasticstack_elasticsearch_snapshot_lifecycle.slm_policy" error: metadata: '' expected type 'string', got unconvertible type '[]uint8', value: '[123 34 99 114 101 97 116 101 100 95 98 121 34 58 34 116 101 114 114 97 102 111 114 109 34 44 34 112 117 114 112 111 115 101 34 58 34 100 97 105 108 121 32 98 97 99 107 117 112 34 125]'
2025-10-31T12:21:13.101+0100 [ERROR] vertex "elasticstack_elasticsearch_snapshot_lifecycle.slm_policy (expand)" error: metadata: '' expected type 'string', got unconvertible type '[]uint8', value: '[123 34 99 114 101 97 116 101 100 95 98 121 34 58 34 116 101 114 114 97 102 111 114 109 34 44 34 112 117 114 112 111 115 101 34 58 34 100 97 105 108 121 32 98 97 99 107 117 112 34 125]'
╷
│ Error: metadata: '' expected type 'string', got unconvertible type '[]uint8', value: '[123 34 99 114 101 97 116 101 100 95 98 121 34 58 34 116 101 114 114 97 102 111 114 109 34 44 34 112 117 114 112 111 115 101 34 58 34 100 97 105 108 121 32 98 97 99 107 117 112 34 125]'
│ 
│   with elasticstack_elasticsearch_snapshot_lifecycle.slm_policy,
│   on main.tf line 16, in resource "elasticstack_elasticsearch_snapshot_lifecycle" "slm_policy":
│   16: resource "elasticstack_elasticsearch_snapshot_lifecycle" "slm_policy" {
│ 
╵
2025-10-31T12:21:13.105+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-10-31T12:21:13.108+0100 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/elastic/elasticstack/0.12.1/darwin_arm64/terraform-provider-elasticstack_v0.12.1 pid=41870
2025-10-31T12:21:13.108+0100 [DEBUG] provider: plugin exited

Screenshots

Versions (please complete the following information):

  • OS: MacOS
  • Terraform Version 1.5.7
  • Provider version v0.12.1
  • Elasticsearch Version 9.2.0

Additional context

Metadata

Metadata

Assignees

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