Hi all,
I’m currently building a custom Terraform plugin to provision ES clusters. I want to read in an input that contains a series of maps and lists nested inside an outer list like so:
tf file:
resource "cluster" "my-cluster" {
api_key = <api_key>
cluster_name = "my cluster"
elasticsearch {
region = "us-east-1"
ref_id = "main-elasticsearch"
plan = {
cluster_topology {
node_type = {
data = true
master = true
ingest = true
}
instance_configuration_id = "aws.data.highio.i3"
zone_count = 2
size = {
resource = "memory"
value = 4096
}
}
}
}
In this example, the outer elasticsearch
attribute is a block of TypeList
, the inner plan
attribute is of TypeMap
, cluster_topology
inside of it is of TypeList
, and both node_type
and size
are of TypeMap
.
When I run terraform init
, I get the following error message:
Error: Missing key/value separator
on cluster.tf line 8, in resource "cluster" "my-cluster":
7:
8: cluster_topology {
Expected an equals sign ("=") to mark the beginning of the attribute value.
Given that I can use tf syntax to describe a TypeList
object as a block and a TypeMap
object with an =
to indicate that it’s an attribute, I’m curious to know why I’m seeing this error. Would love some input on how to fix it as well.
When I include the =
as part of cluster_topology
's declaration, I see the following error message:
Inappropriate value for attribute "plan": element "cluster_topology": string
required.
Here’s a snippet of the schema definitions in my resource
file:
"elasticsearch": &schema.Schema{
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"region": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"ref_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"plan": &schema.Schema{
Type: schema.TypeMap,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cluster_topology": &schema.Schema{
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"node_type": &schema.Schema{
Type: schema.TypeMap,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"data": &schema.Schema{
Type: schema.TypeBool,
Required: true,
},
"master": &schema.Schema{
Type: schema.TypeBool,
Required: true,
},
"ingest": &schema.Schema{
Type: schema.TypeBool,
Required: true,
},
},
},
Required: true,
},