Let's say I have a module, which generates some ids: module.tf:

resource "random_id" "etcdapiserver-id" {
  byte_length         = 4
  count               = "${var.etcd_apiserver_count}"


output "etcdapiserver_hostname_list" {
  value = ["${random_id.etcdapiserver-id.*.hex}"]

It seems to work fine and the list ends up in the output successfully:

terraform output --module=module

etcdapiserver_hostname_list = [

Now I want to use elements from this list in main terraform config. Let's say I'm creating several compute instances on openstack: main.tf:

resource "openstack_compute_instance_v2" "etcdapiserver" {
  count   = "3"
  name    = "etcdapi-node-${element(module.ignition.etcdapiserver_hostname_list.*, count.index)}"

But it would fail with

Error: resource 'openstack_compute_instance_v2.etcdapiserver' config: "etcdapiserver_hostname_list.*" is not a valid output for module "ignition"

Is there any way to do it? Thanks!


Terraform contributor answered my question on GitHub.

The general syntax for accessing the element of a list is list[index]. In your case, that would be something like module.ignition.etcdapiserver_hostname_list[count.index].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.