Provider: elastic/elasticstack 0.11.4
Terraform version: 1.9.4
Is this a problem with my code or a bug in the provider? Terraform plan returns correct values, but on apply it attempts to create with, again, the correct values, but does not create the resources and errors out. I have created a bug with the provider as well, but want to double check my code in tandem.
The full error:
│ Error: json: cannot unmarshal array into Go value of type map[string]interface {}
│
│ with elasticstack_elasticsearch_index_template.index_templates["the_index_template_name"],
│ on IndexTemplates.tf line 13, in resource "elasticstack_elasticsearch_index_template" "index_templates":
│ 13: resource "elasticstack_elasticsearch_index_template" "index_templates" {
│
locals.tf
locals {
features = {
feature0 = {
component_template = "true"
contextkey = "feature0"
ilm_policy = "policy0"
}
feature1 = {
component_template = "true"
contextkey = "feature1"
ilm_policy = "policy0"
}
feature2 = {
component_template = "true"
contextkey = "feature2"
ilm_policy = "policy2"
}
feature3 = {
component_template = "false"
contextkey = "feature3"
ilm_policy = "policy3"
}
feature4 = {
component_template = "true"
contextkey = "feature4"
ilm_policy = "policy4"
}
feature5 = {
component_template = "false"
contextkey = "feature5"
ilm_policy = "policy5"
}
}
}
index_templates.tf
resource "elasticstack_elasticsearch_component_template" "default_policy_component" {
name = "policy0"
template {
settings = file("component_templates/policy0_settings.json")
mappings = file("component_templates/policy0_mappings.json")
}
metadata = jsonencode({
description = "Terraform managed resource by DevOps Team"
})
}
resource "elasticstack_elasticsearch_index_template" "index_templates" {
for_each = local.features
composed_of = each.value.component_template ? [elasticstack_elasticsearch_component_template.default_policy_component.name] : []
index_patterns = ["${each.value.contextkey}_*"]
name = each.value.contextkey
template {
settings = jsonencode({
index = {
lifecycle = {
name = "${each.value.ilm_policy}"
rollover_alias = "${each.value.contextkey}_write"
}
}
})
mappings = each.value.component_template ? "[]" : file("index_templates/${each.value.contextkey}_mappings.json")
}
metadata = jsonencode({
description = "Terraform managed resource by DevOps Team"
})
}
terraform plan
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# elasticstack_elasticsearch_index_template.index_templates["feature0"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = [
+ "policy0",
]
+ id = (known after apply)
+ index_patterns = [
+ "feature0_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature0"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy0"
+ rollover_alias = "feature0_write"
}
}
}
)
}
}
# elasticstack_elasticsearch_index_template.index_templates["feature1"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = [
+ "policy0",
]
+ id = (known after apply)
+ index_patterns = [
+ "feature1_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature1"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy0"
+ rollover_alias = "feature1_write"
}
}
}
)
}
}
# elasticstack_elasticsearch_index_template.index_templates["feature2"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = [
+ "policy0",
]
+ id = (known after apply)
+ index_patterns = [
+ "feature2_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature2"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy2"
+ rollover_alias = "feature2_write"
}
}
}
)
}
}
# elasticstack_elasticsearch_index_template.index_templates["feature3"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = []
+ id = (known after apply)
+ index_patterns = [
+ "feature3_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature3"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy3"
+ rollover_alias = "feature3_write"
}
}
}
)
}
}
# elasticstack_elasticsearch_index_template.index_templates["feature4"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = [
+ "policy0",
]
+ id = (known after apply)
+ index_patterns = [
+ "feature4_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature4"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy4"
+ rollover_alias = "feature4_write"
}
}
}
)
}
}
# elasticstack_elasticsearch_index_template.index_templates["feature5"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = []
+ id = (known after apply)
+ index_patterns = [
+ "feature5_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature5"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy5"
+ rollover_alias = "feature5_write"
}
}
}
)
}
}
Plan: 6 to add, 0 to change, 0 to destroy.
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
terraform apply
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# elasticstack_elasticsearch_index_template.index_templates["feature0"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = [
+ "policy0",
]
+ id = (known after apply)
+ index_patterns = [
+ "feature0_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature0"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy0"
+ rollover_alias = "feature0_write"
}
}
}
)
}
}
# elasticstack_elasticsearch_index_template.index_templates["feature1"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = [
+ "policy0",
]
+ id = (known after apply)
+ index_patterns = [
+ "feature1_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature1"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy0"
+ rollover_alias = "feature1_write"
}
}
}
)
}
}
# elasticstack_elasticsearch_index_template.index_templates["feature2"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = [
+ "policy0",
]
+ id = (known after apply)
+ index_patterns = [
+ "feature2_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature2"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy2"
+ rollover_alias = "feature2_write"
}
}
}
)
}
}
# elasticstack_elasticsearch_index_template.index_templates["feature3"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = []
+ id = (known after apply)
+ index_patterns = [
+ "feature3_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature3"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy3"
+ rollover_alias = "feature3_write"
}
}
}
)
}
}
# elasticstack_elasticsearch_index_template.index_templates["feature4"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = [
+ "policy0",
]
+ id = (known after apply)
+ index_patterns = [
+ "feature4_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature4"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy4"
+ rollover_alias = "feature4_write"
}
}
}
)
}
}
# elasticstack_elasticsearch_index_template.index_templates["feature5"] will be created
+ resource "elasticstack_elasticsearch_index_template" "index_templates" {
+ composed_of = []
+ id = (known after apply)
+ index_patterns = [
+ "feature5_*",
]
+ metadata = jsonencode(
{
+ description = "Terraform managed resource by DevOps Team"
}
)
+ name = "feature5"
+ template {
+ mappings = jsonencode([])
+ settings = jsonencode(
{
+ index = {
+ lifecycle = {
+ name = "policy5"
+ rollover_alias = "feature5_write"
}
}
}
)
}
}
Plan: 6 to add, 0 to change, 0 to destroy.
elasticstack_elasticsearch_index_template.index_templates["feature0"]: Creating...
elasticstack_elasticsearch_index_template.index_templates["feature5"]: Creating...
elasticstack_elasticsearch_index_template.index_templates["feature1"]: Creating...
elasticstack_elasticsearch_index_template.index_templates["feature4"]: Creating...
elasticstack_elasticsearch_index_template.index_templates["feature3"]: Creating...
elasticstack_elasticsearch_index_template.index_templates["feature2"]: Creating...
╷
│ Error: json: cannot unmarshal array into Go value of type map[string]interface {}
│
│ with elasticstack_elasticsearch_index_template.index_templates["feature3"],
│ on IndexTemplates.tf line 13, in resource "elasticstack_elasticsearch_index_template" "index_templates":
│ 13: resource "elasticstack_elasticsearch_index_template" "index_templates" {
│
╵
╷
│ Error: json: cannot unmarshal array into Go value of type map[string]interface {}
│
│ with elasticstack_elasticsearch_index_template.index_templates["feature1"],
│ on IndexTemplates.tf line 13, in resource "elasticstack_elasticsearch_index_template" "index_templates":
│ 13: resource "elasticstack_elasticsearch_index_template" "index_templates" {
│
╵
╷
│ Error: json: cannot unmarshal array into Go value of type map[string]interface {}
│
│ with elasticstack_elasticsearch_index_template.index_templates["feature4"],
│ on IndexTemplates.tf line 13, in resource "elasticstack_elasticsearch_index_template" "index_templates":
│ 13: resource "elasticstack_elasticsearch_index_template" "index_templates" {
│
╵
╷
│ Error: json: cannot unmarshal array into Go value of type map[string]interface {}
│
│ with elasticstack_elasticsearch_index_template.index_templates["feature2"],
│ on IndexTemplates.tf line 13, in resource "elasticstack_elasticsearch_index_template" "index_templates":
│ 13: resource "elasticstack_elasticsearch_index_template" "index_templates" {
│
╵
╷
│ Error: json: cannot unmarshal array into Go value of type map[string]interface {}
│
│ with elasticstack_elasticsearch_index_template.index_templates["feature0"],
│ on IndexTemplates.tf line 13, in resource "elasticstack_elasticsearch_index_template" "index_templates":
│ 13: resource "elasticstack_elasticsearch_index_template" "index_templates" {
│
╵
╷
│ Error: json: cannot unmarshal array into Go value of type map[string]interface {}
│
│ with elasticstack_elasticsearch_index_template.index_templates["feature5"],
│ on IndexTemplates.tf line 13, in resource "elasticstack_elasticsearch_index_template" "index_templates":
│ 13: resource "elasticstack_elasticsearch_index_template" "index_templates" {
│
╵
Thank you in advance!