hashicorp / terraform-provider-chef

Terraform Chef provider
https://www.terraform.io/docs/providers/chef/
Mozilla Public License 2.0
12 stars 34 forks source link

Implement data source for pulling data from chef server #22

Open msvticket opened 6 years ago

msvticket commented 6 years ago

To easily use data stored on a chef server in terraform would be very useful.

I envision something you would call like this:

data "chef_search" "rabbitmq" {
  index = "node"
  query = "chef_environment:test AND role:rabbitmq"
  filter {
    name   = "rabbitmq"
    values = ["rabbitmq"]
  }

  filter {
    name   = "host"
    values = ["ipaddress"]
  }
  unique = true
}

data.chef_search.rabbitmq.rabbitmq.default_password and data.chef_search.rabbitmq.host would then be examples of attributes to use.

This is similar to how you would use search in a chef recipe: https://docs.chef.io/chef_search.html#filter-search-results

One gotcha is that chef search normally return a list of results, while a terraform data source (as far as I understand) isn't allowed to do that. So that is why I introduced "unique" above, which would mean that a unique result is expected (and an error would be raised otherwise). Without "unique = true" the result would instead contain the list attribute "rows" with all the results.