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

Adding better support for groups via the metadata.groups attribute #21

Closed
wants to merge 2 commits into from

Conversation

jackspirou
Copy link

This pull request adds better support for groups, via the metadata.groups attribute and fixes #16

@vasiliyb
Copy link

vasiliyb commented Dec 9, 2015

@jackspirou I've tried compiling from your fork, with no avail:

go get github.com/jackspirou/terraform-inventory
cd src/gitub.com/jackspirou/terraform-inventory
go build

./terraform-inventory --list still shows the hosts separate

@jackspirou
Copy link
Author

@vasiliyb can you send me an example file your using? Do you have a metadata.groups attribute listed?

@vasiliyb
Copy link

vasiliyb commented Dec 9, 2015

@jackspirou email sent, thank you! I dont see metadata.groups in --list output

@adammck
Copy link
Owner

adammck commented Dec 10, 2015

Hello! Thanks very much for your patch. However, I also can't seem to get it to work. None of the resources in my state files seem to include a meta.groups attribute. Can you provide an example?

@jackspirou
Copy link
Author

Hi @vasiliyb and @adammck, sorry for the delay in responding. So the reason I submitted this was because our team needed something that Ansible groups could easily pickup. This PR takes the approach of adding a metadata.groups attribute (which I hear is quite popular with other tools) to the .tfstate file. This can be done by including the following code for a resource in main.tf

resource "openstack_compute_instance_v2" "hive" {
  count = "${lookup(var.instances, var.env)}"
  security_groups = ["default", "HTTP"]
  name = "${var.env}-hive-${count.index}"
  region = "${var.region}"
  image_name = "${module.settings.images}"
  flavor_name = "${lookup(var.flavor, var.env)}"
  key_pair = "${module.settings.key_pair}"
  floating_ip = "${lookup(var.static_address, var.env)}"
  network {
    name = "${module.settings.private_net}"
  }
  metadata {
    groups = "web,api,hive"
  }
}

After using terraform apply with the example above, running terraform-inventory --list <filepath> would result in:

{"api":["10.65.82.170"],"hive":["10.65.82.170"],"web":["10.65.82.170"]}

So values like "metadata.groups": "mongosc,mongos,mongoc", might produce groups along side the current --list outputt:

{
  "mongoc":["10.10.10.101","10.10.10.102","10.10.10.103"],
  "mongos":["10.10.10.101","10.10.10.102","10.10.10.103"],
  "mongosc":["10.10.10.101","10.10.10.102","10.10.10.103"],
  "server.0":["10.10.10.101"],
  "server.1":["10.10.10.102"],
  "server.2":["10.10.10.103"]
}

Let me know your thoughts and if this still makes sense given PR #22 or if we can consider #16 fixed.

@jackspirou
Copy link
Author

After taking a look at PR #22 I think it accomplishes much of this, but from what I understand it doesn't allow for multiple resources to one group, or multiple resources to multiple groups. So for example, you might have a shared Ansible bootstrap play to set default configuration on all servers belonging to the HTTP Ansible group.

Again all feedback welcome.

@adammck
Copy link
Owner

adammck commented Dec 15, 2015

Thanks for getting back to me, @jackspirou. You're right that #22 doesn't provide arbitrary group names, which is something I'd very much like to add. I wasn't familiar with the metadata attribute, because (as far as I can tell), it's only supported by the OpenStack provider. But most other providers have their own mechanism (e.g. AWS's instance tags) for this sort of thing.

I refactored master a bit already (to make this sort of thing simpler in future), and will try to get this merged shortly. Thanks very much for the patch!

@jackspirou
Copy link
Author

This PR has conflicts. Closing.

@jackspirou jackspirou closed this Jan 25, 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.

Ansible HostGroup Support
3 participants