Skip to content

Support resource / module instances #208

@nm-devops

Description

@nm-devops
SUMMARY

A common feature of terraform is to use the for_each or count meta.argument in resource definition blocks, to create multiple instances from the same resource block.

I can't see that this is currently supported. Creating an inventory from such a state currently only imports the last instance of the resource definition into the dynamic inventory.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

inventory plugin: terraform_state

ADDITIONAL INFORMATION

Example terraform configuration.

locals {
  subnet_ids = toset([
    "subnet-abcdef",
    "subnet-012345",
  ])
}

resource "aws_instance" "server" {
  for_each = local.subnet_ids

  ami           = "ami-a1b2c3d4"
  instance_type = "t2.micro"
  subnet_id     = each.key

  tags = {
    Name = "Server ${each.key}"
  }
}

https://developer.hashicorp.com/terraform/language/meta-arguments/for_each#referring-to-instances

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions