ansible / awx

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.
Other
13.98k stars 3.42k forks source link

awx.awx collection: support for 'Terraform State' inventory source #15252

Closed vvarga007 closed 4 months ago

vvarga007 commented 4 months ago

Please confirm the following

Feature type

Enhancement to Existing Feature

Feature Summary

AWX 24.0.0 introduced a terraform state inventory source. It would be great to create this inventory source with the 'awx.awx' ansible collection, which is currently not supported. It is the same with the 'Terraform backend configuration' credential type.

Select the relevant components

Steps to reproduce

N/A

Current results

N/A

Sugested feature result

N/A

Additional information

No response

thedoubl3j commented 4 months ago

Reasonable request, my guess is it would take some work in https://github.com/ansible/awx/blob/devel/awx_collection/plugins/modules/inventory_source.py. If someone has time, feel free to take a crack, might be a bit before we can get to it though @vvarga007 but very doable/in scope I think.

vvarga007 commented 4 months ago

@thedoubl3j I took a quick look at this. To create a terraform state inventory source, the only thing that we have to do is to add 'terraform' as a valid choice.( https://github.com/ansible/awx/blob/devel/awx_collection/plugins/modules/inventory_source.py) I changed it to this:

source=dict(choices=["scm", "ec2", "gce", "azure_rm", "vmware", "satellite6", "openstack", "rhv", "controller", "insights", "terraform"]),

After this change, I was able to create an inventory source with the following task:

- name: Add an inventory source 'TF_source'
  awx.awx.inventory_source:
    inventory: Inventory_TEST_TF_SOURCE
    name: TF_source
    source: terraform
    source_vars:
      backend_type: s3
    credential: TF_TEST
    organization: Default
    state: present
vvarga007 commented 4 months ago

I checked the TF backend credential, too. It seems that works out of the box. This combo works like a charm after that minor change in my previous comment.

- name: Add TF backend configuration
  awx.awx.credential:
    name: TF_TEST
    credential_type: Terraform backend configuration
    organization: Default
    inputs:
      configuration: |
        bucket = "example-tfstates"
        key = "aws-test-instance/tf_state.tfstate"
        region = "us-east-1"
        access_key = "CHANGEME"
        secret_key = "CHANGEME"

- name: Add an inventory source 'TF_source'
  awx.awx.inventory_source:
    inventory: Inventory_TEST_TF_SOURCE
    name: TF_soruce
    source: terraform
    source_vars:
      backend_type: s3
    credential: TF_TEST
    organization: Default
    overwrite: true
    overwrite_vars: true
    update_on_launch: true
    verbosity: 1
    state: present
vvarga007 commented 4 months ago

@thedoubl3j I created a PR for this. Please take a look.