Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform Resources of "mode" "data" Are Included by Default #167

Open
timway opened this issue Oct 23, 2024 · 0 comments
Open

Terraform Resources of "mode" "data" Are Included by Default #167

timway opened this issue Oct 23, 2024 · 0 comments
Labels
type/enhancement New feature or request

Comments

@timway
Copy link

timway commented Oct 23, 2024

SUMMARY

The inventory plugin adds any matching resource to the inventory. A number of resource types have "lookup" (aka data) and "concrete" (aka managed) resources. It's not an uncommon process to "lookup" a similar resource to apply some or all of it's settings to a managed resource. This can be seen in AWS (a supported cloud) with the aws_instance data source and resource.

My opinion is the data resources should be excluded by default (breaking change). A sub-option should be added to provider-mapping to specify the mode. It could be restricted to 2 values, "data", and "managed", or 3 including - "any". I'd advocate for the breaking change as it is closer to my expectation as a user of the collection. Being able to add an additional provider mapping to select data or catch both via an "any" value would ensure no existing use cases are left uncovered.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

plugins/inventory/terraform_state.py

ANSIBLE VERSION
ansible [core 2.16.11]
  config file = /tmp/tmp.ft7auWhZ7g/ansible.cfg
  configured module search path = ['/home/xyz/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /tmp/tmp.ft7auWhZ7g
  executable location = /usr/bin/ansible
  python version = 3.12.6 (main, Sep  9 2024, 00:00:00) [GCC 14.2.1 20240801 (Red Hat 14.2.1-1)] (/usr/bin/python3)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION

At the time of testing I was using this version from git dcb5408.

# /tmp/tmp.ft7auWhZ7g/ansible_collections
Collection      Version   
--------------- ----------
cloud.terraform 4.0.0-dev0
CONFIGURATION
COLLECTIONS_PATHS(/tmp/tmp.ft7auWhZ7g/ansible.cfg) = ['/tmp/tmp.ft7auWhZ7g']
CONFIG_FILE() = /tmp/tmp.ft7auWhZ7g/ansible.cfg
EDITOR(env: EDITOR) = /usr/bin/nano
OS / ENVIRONMENT

Fedora Workstation 40, ansible-core and tofu from packages

STEPS TO REPRODUCE

main.tf

terraform {
  required_providers {
    local = {
      source = "hashicorp/local"
      version = "2.5.2"
    }
  }
}

data "local_file" "foo" {
  filename = "${path.module}/foo"
}

resource "local_file" "bar" {
  content  = data.local_file.foo.content
  filename = "${path.module}/bar"
}

hosts.terraform_state.yml

---
plugin: cloud.terraform.terraform_state
backend_type: local
backend_config:
  path: /tmp/tmp.ft7auWhZ7g/terraform.tfstate
binary_path: /usr/bin/tofu
hostnames:
  - filename
provider_mapping:
  - provider_name: registry.opentofu.org/hashicorp/local
    types:
      - local_file
EXPECTED RESULTS
$ ansible-inventory --graph --inventory hosts.terraform_state.yml 
@all:
  |--@ungrouped:
  |  |--./bar
ACTUAL RESULTS
$ ansible-inventory --graph --inventory hosts.terraform_state.yml 
@all:
  |--@ungrouped:
  |  |--./foo
  |  |--./bar
@gravesm gravesm added the type/enhancement New feature or request label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants