Skip to content

cloud.terraform.terraform_state Plugin should accept required_providers source and version as input #151

@oshankkumar

Description

@oshankkumar
SUMMARY

The inventory plugin cloud.terraform.terraform_state should accept required_providers source and version as input. I am using the azurerm backend provider with version 2.99.0. However, this plugin by default uses the latest azurerm version while building the inventory, resulting in an error when running terraform show while building the inventory.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

plugin

ANSIBLE VERSION
ansible [core 2.17.0]
  config file = None
  configured module search path = ['/home/XXXXXX/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/XXXXX/python3.11/site-packages/ansible
  ansible collection location = /home/XXXXX/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/XXXXXXX/bin/ansible
  python version = 3.11.9 (main, Apr  6 2024, 17:59:24) [GCC 9.4.0] (/XXXXX/bin/python3.11)
  jinja version = 3.1.4
  libyaml = True

COLLECTION VERSION
Collection                               Version
---------------------------------------- -------
ansible.posix                            1.5.4
azure.azcollection                       2.4.0
cloud.terraform                          3.0.0
community.docker                         3.10.3
community.library_inventory_filtering_v1 1.0.1


CONFIGURATION

OS / ENVIRONMENT
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
STEPS TO REPRODUCE

Create an inventory plugin inventory.yml

plugin: cloud.terraform.terraform_state
backend_type: azurerm
backend_config:
  resource_group_name: rg
  storage_account_name: sc
  container_name: terraform
  key: terraform.tfstate

Run the following command:

ansible-inventory -i inventory.yml --graph

An error is thrown:

[WARNING]:  * Failed to parse inventory.yml with auto plugin: Could not get Terraform show from path: /tmp/tmp11q0tkqc.  stdout:
stderr: Failed to marshal state to json: unsupported attribute "availability_zone"

This happens because the Terraform state file was built using an older version while the cloud.terraform.terraform_state plugin uses the latest version during terraform init. The plugin should accept input for required_providers source and version and use this information to write the Terraform version config which will be used during terraform init.

Metadata

Metadata

Assignees

Labels

WIPtype/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions