puppetlabs / puppetlabs-terraform

Bolt Terraform plugin
Apache License 2.0
6 stars 18 forks source link

Inventory plugin doesn't seem to honour module boundaries #26

Open bodgit opened 2 years ago

bodgit commented 2 years ago

Describe the Bug

I've got some Terraform that provisions a mix of Linux and Windows EC2 instances using separate private modules such that the module outputs provide the private IP address and FQDN and hide the differences in OS provisioning and instance configuration.

I'd like to use your module to retrieve this output information from the state file for running further Bolt plans but I need to be able to differentiate between the two operating systems for the purposes of configuring the transport (SSH vs WinRM, etc.). The problem is both modules contain a Terraform resource like so:

resource "aws_instance" "server" {
...
}

I can't find a way to only find the aws_instance resources that are in the linux module versus only finding the aws_instance resources in the windows module. If I configure the inventory.yaml like so:

---
groups:
  - name: linux
    targets:
      - _plugin: terraform
        resource_type: aws_instance.server  

I get every instance. I was perhaps expecting the inventory plugin to stick to the interface of using the top-level/root module Terraform outputs rather than potentially find any resources encapsulated within the modules. It also means should the Terraform code change internally (but maintain the same output names), this inventory configuration will break.

Expected Behavior

One solution might be to allow access to the outputs, i.e. to access the private_dns output on both modules:

---
groups:
  - name: linux
    targets:
      - _plugin: terraform
        resource_type: module.linux
        target_mapping:
          uri: private_dns
  - name: windows
    targets:
      - _plugin: terraform
        resource_type: module.windows
        target_mapping:
          uri: private_dns

Environment