terraform-inventory icon indicating copy to clipboard operation
terraform-inventory copied to clipboard

Terraform inventory groups contain invalid characters.

Open queglay opened this issue 4 years ago • 5 comments

Terraform Inventory seems to create groups with '.' characters in the groups. This delimiter in turn generates warnings from Ansible because they are invalid characters and produces a warning.

[WARNING]: Invalid characters were found in group names but not replaced

This is an example shell output when I provision with Ansible in Terraform.

module.workstation.null_resource.workstation_pcoip (local-exec): + ansible-playbook -i ansible/inventory ansible/node-centos-init-users.yaml -v --extra-vars variable_host=role_workstation_centos hostname=cloud_workstation1.example.com pcoip=true
module.workstation.null_resource.workstation_pcoip (local-exec): Using /vagrant/ansible.cfg as config file
module.workstation.null_resource.workstation_pcoip (local-exec): [DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to
module.workstation.null_resource.workstation_pcoip (local-exec): allow bad characters in group names by default, this will change, but still be
module.workstation.null_resource.workstation_pcoip (local-exec): user configurable on deprecation. This feature will be removed in version 2.10.
module.workstation.null_resource.workstation_pcoip (local-exec):  Deprecation warnings can be disabled by setting deprecation_warnings=False in
module.workstation.null_resource.workstation_pcoip (local-exec): ansible.cfg.
module.workstation.null_resource.workstation_pcoip (local-exec):  [WARNING]: Invalid characters were found in group names but not replaced, use
module.workstation.null_resource.workstation_pcoip (local-exec): -vvvv to see details

queglay avatar Aug 14 '19 07:08 queglay

A workaround:

terraform-inventory "$@" | jq 'with_entries(.key |= sub("\\."; "_"))'

KostyaEsmukov avatar Sep 22 '19 18:09 KostyaEsmukov

Problematic code is here: https://github.com/adammck/terraform-inventory/blob/94a66e3c5e56afe02f93ef1c765f6de6d25c0103/cli.go#L167-L168

But I'm not sure if changing the . to a _ is a sufficient fix.

obilodeau avatar Oct 01 '19 17:10 obilodeau

Tentative PR available here: #128

obilodeau avatar Oct 01 '19 18:10 obilodeau

I have published a new "dev" release from my fork: https://github.com/jpmat296/terraform-inventory/releases

It includes PR #128. This issue is fixed at least for me.

jpmat296 avatar Jan 08 '21 09:01 jpmat296

Hi, The merged PR only fix presence of dots in the the inventory groups, but my infrastructure on AWS generates system tags with hyphens, also illegal , so I have to filter out that group (as I don't need them):

terraform-inventory $@ ./ | jq 'with_entries(select([.key] | inside(["system_t3_micro-centos8"])|not))'

which I've generalised as

terraform-inventory $@ ./ | jq 'with_entries(select([.key] | contains(["system_"])|not))'

rija avatar Oct 03 '23 07:10 rija