简体   繁体   中英

How do you pass Terraform count from a resource to a module?

How can I pass a list of values created from a resource to a module that expects a list of items? I've tried running [count.index] and reffering to the first item in the list [0] but I get the message that you can only pass a count object to resource & data blocks.

resource "aws_subnet" "private_subnets" {
  count                   = length(data.aws_availability_zones.available.names)
  vpc_id                  = data.aws_vpc.selected.id
  cidr_block              = "192.168.${10 + count.index}.0/24"
  availability_zone       = data.aws_availability_zones.available.names[count.index]
  map_public_ip_on_launch = false

  tags = {
    Name                  = "private-subnet"
  }

module "my_module" {
  source                        = "../../"
  cluster_name                  = local.cluster_name
  subnets                       = aws_subnet.public_subnets[count.index].id

Terraform version 0.12+ has all the goodies !

I updated my call to the resource to loop back like the following:

[ for subnet in aws_subnet.public_subnets: subnet.id ] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM