The collection automates the management and provisioning of infrastructure as code (IaC) using the Terraform CLI tool within Ansible playbooks and Execution Environment runtimes.
GNU General Public License v3.0
94
stars
32
forks
source link
`cloud.terraform.terraform_state` Plugin Fails to Include EC2 Instances Created via Terraform Modules in Ansible Inventory #165
The cloud.terraform.terraform_state plugin fails to retrieve AWS EC2 instances that are created via Terraform modules when generating an Ansible inventory. Instances defined directly using the aws_instance resource type are successfully fetched, but those within modules (including both custom and third-party modules) are not recognized by the plugin.
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
STEPS TO REPRODUCE
Define AWS EC2 instances using three different methods in Terraform:
Directly using aws_instance resource.
Using a custom module (module "ec2") that internally defines aws_instance.
Using a third-party module (module "ec2_instance") like terraform-aws-modules/ec2-instance/aws.
Apply the Terraform configuration to create resources.
Use the cloud.terraform.terraform_state plugin to generate an Ansible inventory.
The Ansible inventory should include all EC2 instances created by Terraform, regardless of whether they were defined directly or within modules.
ACTUAL RESULTS
Only the EC2 instances defined directly using the aws_instance resource type are included in the Ansible inventory. Instances created within custom or third-party modules are not recognized or included.
$ ansible-inventory -i ansible_terraform_state.yaml --graph -vvvv
ansible-inventory [core 2.17.3]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.10/site-packages/ansible
executable location = /usr/bin/ansible-inventory
python version = 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] (/usr/bin/python3)
jinja version = 3.1.4
libyaml = True
Using inventory plugin 'cloud.terraform.terraform_state' to process inventory source 'ansible_terraform_state.yaml'
Parsed ansible_terraform_state.yaml inventory source with auto plugin
@all:
|--@ungrouped:
| |--HelloWorld
# Instances from modules are missing
SUMMARY
The
cloud.terraform.terraform_state
plugin fails to retrieve AWS EC2 instances that are created via Terraform modules when generating an Ansible inventory. Instances defined directly using the aws_instance resource type are successfully fetched, but those within modules (including both custom and third-party modules) are not recognized by the plugin.ISSUE TYPE
COMPONENT NAME
cloud.terraform.terraform_state
pluginANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.4 LTS Release: 22.04 Codename: jammy
STEPS TO REPRODUCE
Define AWS EC2 instances using three different methods in Terraform: Directly using
aws_instance
resource. Using a custom module (module "ec2"
) that internally definesaws_instance
. Using a third-party module (module "ec2_instance"
) liketerraform-aws-modules/ec2-instance/aws
. Apply the Terraform configuration to create resources. Use thecloud.terraform.terraform_state
plugin to generate an Ansible inventory.EXPECTED RESULTS
The Ansible inventory should include all EC2 instances created by Terraform, regardless of whether they were defined directly or within modules.
ACTUAL RESULTS
Only the EC2 instances defined directly using the aws_instance resource type are included in the Ansible inventory. Instances created within custom or third-party modules are not recognized or included.