Closed kedar9696 closed 2 months ago
@kedar9696 you need to set the parameter search_child_modules: true
in order for the plugin to include modules resources
Thank you, @abikouo, for your help! Everything is working as expected now. I realized I missed that parameter; it was my mistake.
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.