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

Added the inventory option to produce an output similar to Ansible host file #31

Merged
merged 1 commit into from
Apr 3, 2016

Conversation

andrefbsantos
Copy link
Contributor

I introduced the --inventory option which changes the output from the classic json format from --list to an output similar to Ansible host file.
The following configuration:

resource "digitalocean_droplet" "gamma" {
  image = "centos-7-0-x64"
  name = "terraform-inventory-1"
  region = "nyc1"
  size = "512mb"
  ssh_keys = [862272]
}

resource "digitalocean_droplet" "zeta" {
  image = "centos-7-0-x64"
  name = "terraform-inventory-1"
  region = "nyc1"
  size = "512mb"
  ssh_keys = [862272]
}

Would generate the following host file:

[gamma]
192.81.216.231

[gamma.0]
192.81.216.231

[type_digitalocean_droplet]
192.81.216.231
198.211.97.15

[zeta]
198.211.97.15

[zeta.0]
198.211.97.15

This output can be fed to Ansible to provision remotes servers.

@adammck
Copy link
Owner

adammck commented Feb 24, 2016

Thanks for the patch! Can you clarify your use-case for me? I'm not aware of any situations in which the JSON dynamic inventory format is insufficient.

@andrefbsantos
Copy link
Contributor Author

I'm currently using the --inventory option to parse the terraform.tfstate and produce an host file like the example shown above.

Then I feed that host file to applications which can process the host and interact with the remotes machines, such as Ansible.

@adammck
Copy link
Owner

adammck commented Feb 24, 2016

I'm probably being dense here, but I don't understand why one would need the host file when the JSON inventory is available. Are there tools other than Ansible which support the format?

@andrefbsantos
Copy link
Contributor Author

At the moment I'm only using Ansible, which is not accepting the JSON format.

Sorry for not being clear.

@lordnynex
Copy link

@adammck A bit late to the party on this PR, but my use case for this feature switch is generating up to date ansible inventory files that are shared with peripheral teams to do tasks such as deployment at a lower privilege level. This would allow me to eliminate the current ansible dynamic inventory script using the EC2 api and keep all of the TF (and requisite tfstate files) purely in the 'devops team domain'.

One thing I consistently grapple with is siloing user roles. In my case TF operates with elevated credentials. At present my only options are using TF remote state plugins, which I prefer to not use.

Additionally, generating ansible inventory files as 'artifacts' allows me to keep my provided toolset (deploy scripts leveraging ansible for the developer team), without adding terraform-inventory binary as a dependency. At present, if I want to integrate this I must ensure all engineers in the organization know about it and install it.

Anyways, just my $.2.

@adammck adammck merged commit 3d29481 into adammck:master Apr 3, 2016
@adammck
Copy link
Owner

adammck commented Apr 3, 2016

Thanks, @lordnynex, this PR makes a lot more sense from that angle. Merged!

lazartravica added a commit to lazartravica/terraform-inventory that referenced this pull request Apr 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants