Code Monkey home page Code Monkey logo

terraform-provisioner-chefsolo's Introduction

Terraform Provisioner Chef Solo

Usage

Chef solo provisioner allows you to run chef with local mode but still being able to discover other nodes provisioned by chef.

It is designed to interact closely with the chef solo data-source.

Required attributes for using chefsolo provisioner are :

chef_module_path : The path to the module / cookbook / policy you want to run on your machine.

output_dir : Where all the generated files by the provisioner should be output

nodes : An array of Node JSON files, chef will use them in order to discover nodes during provisioning ( these can be very easily generated by the chefsolo datasource )

target_node: A DNA JSON file, this is the DNA that will be applied to your machine.

instance_id: The node ID you want to target during chef run (must match with the targeted node)

A very minimal configuration would be :

provisioner "chefsolo" {
    "chef_module_path": "path/to/my/cookbook"
    "output_dir": "/tmp/output_tf"
    "nodes": ["${data.template_chefsolo.nodes.*.node}"]
    "target_node": "${data.template_chefsolo.nodes.*.dna}"
    "instance_id": "my_id"
}

Other options will soon be documented too.

Example of usage with terraform provider chef solo :


data "template_chef_solo" "consul_server" {

  count = "${length(var.instances_ips)}"

  automatic_attributes = "${file("${path.module}/attributes/master.tpl")}"
  node_id         = "${element(var.instances_hostnames, count.index)}"
  policy_name     = "consul_server"
  policy_group    = "local"
  environment     = "preprod"

  vars {
    node_ip     = "${element(var.instances_ips, count.index)}"
    node_id     = "${element(var.instances_hostnames, count.index)}"
    hosts       = "${jsonencode(zipmap(
                        var.instances_ips,
                        var.instances_hostnames)
                    )}"
  }
}

resource "null_resource" "provision_consul" {

  triggers {
    always = "${uuid()}"
  }

  count = "${length(var.instances_ips)}"

  connection {
    user        = "centos"
    private_key = "${file(var.ssh_key)}"
    host        = "${element(var.instances_ips, count.index)}"
  }

  provisioner "chef-solo" {

    use_sudo         = true
    nodes            = ["${data.template_chef_solo.consul_server.*.node}"]
    target_node      = "${element(data.template_chef_solo.consul_server.*.dna, count.index)}"
    environment      = "${element(data.template_chef_solo.consul_server.*.environment, count.index)}"
    use_policyfile   = "${element(data.template_chef_solo.consul_server.*.use_policyfile, count.index)}"
    instance_id      = "${element(data.template_chef_solo.consul_server.*.node_id, count.index)}"

    chef_module_path = "${path.module}/../.."
    output_dir       = "${path.module}/bump-chef"
    version          = "12.18.31"

  }
}

terraform-provisioner-chefsolo's People

Contributors

mwea avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.