Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature for fullpath terraform inventory.yaml references #108

Open
gavindidrichsen opened this issue Apr 19, 2023 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@gavindidrichsen
Copy link

Use Case

As a module developer, I want to be able

  • to test plans and tasks against an inventory that I've created via pecdm
  • to run my plans and tasks using the --inventoryfile option. In other words, if have a test plan in /a/test/module and my pecdm inventory file lives beneath /my/peadm/gcp/inventory.yaml, then I want to be able to test my new hello plan with bolt by running cd /a/test/module && bolt plan run module::hello --inventoryfile=/my/peadm/gcp/inventory.yaml --targets=all. Curently this will not work because /my/peadm/gcp/inventory.yaml uses relative paths to the various terraform directories, e.g.,
---
config:
  transport: ssh
  ssh:
    host-key-check: false
    run-as: root
    user: user
    private-key: ~/.ssh/id_rsa-acceptance
  winrm:
    user: user
    password: Puppetlabs123@
    ssl: false
groups:
  - name: peadm_nodes
    groups:
      - name: pe_server
        targets:
          - _plugin: terraform
            dir: .terraform/google_pe_arch
            resource_type: google_compute_instance.server
            target_mapping:
              name: metadata.internalDNS
              uri: network_interface.0.network_ip
...
...

I believe that the above is generated via the inventory_yaml.epp

Describe the Solution You Would Like

Can we have some option to produce fullpaths as well?

Describe Alternatives You've Considered

I've created a ruby script to amend all my terraform inventory.yaml files so that I can achieve the above. For example, I added the following script to my PATH and then I run this from any GCP terraform inventory.yaml directories

#!/opt/puppetlabs/puppet/bin/ruby
require 'yaml'
require 'fileutils'

# ABORT IF:
# (1) current directory does not contain the inventory.yaml file
# (2) inventory.yaml is not using terraform, i.e. no "_plugin: terraform" entries
abort("ERROR: current directory does not contain the inventory.yaml file") unless File.exist?('inventory.yaml')
abort("INFO: inventory.yaml is not using the terraform plugin so no need to proceed") unless File.read('inventory.yaml').include?('_plugin: terraform')

# ensure all "dir" entries contain fullpath to the directory containing the inventory.yaml file
directory = File.expand_path(File.dirname('inventory.yaml'))
File.open('inventory.yaml', "r+") do |file|
  contents = file.read
  contents.gsub!("dir: .terraform", "dir: #{directory}/.terraform")
  contents.gsub!("dir: terraform", "dir: #{directory}/terraform")
  file.rewind
  file.write(contents)
end
@gavindidrichsen gavindidrichsen added the enhancement New feature or request label Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant