I am trying to create an AWS ElasticSearch domain
module "es_xxx" {
source = "../modules/aws_elasticsearch_domain"
providers = {
aws = "aws.default"
}
domain_name = "${var.env_name}-offers"
tags = {
env = "${var.env_name}"
}
elasticsearch_version = "7.9"
instance_type = "t3.small.elasticsearch"
subnet_ids = ["${module.p2s_vpc.elasticsearch_subnets}"]
}
terraform plan shows only one subnet:
vpc_options.0.subnet_ids.#: “1”
In the module output I have:
output “elasticsearch_subnets” {
description = “List of IDs of elasticsearch subnets”
value = ["${aws_subnet.elasticsearch.*.id}"]
}
Is there anything wrong in the above code? Is there a better way to use the array in subnet_ids?
Hi @bngsudheer,
In your example you are assigning subnet_ids
a list containing a single string, which I assume is why the plan is showing a single subnet to be created.
If module.p2s_vpc.elasticsearch_subnets
is a list of subnets already (provided the elements are of the correct type), then you should be able to assign it directly:
subnet_ids = module.p2s_vpc.elasticsearch_subnets
Hi @jbardin ,
I am using an older version of Terraform: 0.11.14. Unfortuantely, I cannot update to a recent version immediately. But I need to create this AWS resource using existing version in place.
Therefore, I cannot use the variable name like you stated: module.p2s_vpc.elasticsearch_subnets
I have also tried: subnet_ids = “${module.p2s_vpc.elasticsearch_subnets}”
I think module.p2s_vpc.elasticsearch_subnets is a list. This is what I see in terraform show output:
module.p2s_vpc.aws_subnet.elasticsearch.0:
id = subnet-xxx
module.p2s_vpc.aws_subnet.elasticsearch.1:
id = subnet-yyy
From this output, I am assuming I have the list.
And the VPC module output has this:
output "elasticsearch_subnets" {
description = "List of IDs of elasticsearch subnets"
value = ["${aws_subnet.elasticsearch.*.id}"]
}
Is there a way I can verity that “${module.p2s_vpc.elasticsearch_subnets}” is a list?
It’s hard to say what exactly is happening there, since that configuration appears to be relying on bugs from earlier versions if terraform. Depending on the context, that may be a list, or it may be a list containing a single list, but I don’t recall exactly which cases could evaluate differently. The plan here may simply not be able to show the correct value, and it will expand out during apply.
You may be able to see what the value is by assigning to a root level output. If it is a list already, I would suggest trying to remove the extra square brackets. Unfortunately with versions prior to 0.12, it’s going to take some trial and error to sort it out.