Skip to content

Commit

Permalink
Merge pull request #13 from mengesb/chef_breakup
Browse files Browse the repository at this point in the history
Breakup of chef map variable
  • Loading branch information
mengesb authored Aug 10, 2016
2 parents a721f04 + 04e1071 commit cd28353
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 66 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ tf_hachef CHANGELOG

This file is used to list changes made in each version of the tf_hachef Terraform plan.

v0.2.3 (2016-08-10)
-------------------
- Breakup `chef` map into `chef_backend`, `chef_client`, `chef_mlsa`,
`chef_org`, `chef_server`, and `chef_user` variables
- Changes to supporting documentation

v0.2.2 (2016-08-09)
-------------------
- Fix for #7
Expand All @@ -17,7 +23,8 @@ v0.2.0 (2016-08-08)
-------------------
- Overhaul on code (nearly complete re-write)
- Updated syntax for (most) Terraform 0.7.0 constructs
- NOTE: Leaving `template` in place of `data` source due to `count` absence on `data` source
- NOTE: Leaving `template` in place of `data` source due to `count` absence on
`data` source
- Removed a number of files

v0.1.1 (2016-07-15)
Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,22 @@ to delete the resources.
* `certificate`: The uploaded identifier for the SSL certificate to use with AWS ELB
* `hostname`: Basename for the hostname. Default: `chefelb`
* `tags_desc`: Default tag for ELB. Default: `Created using Terraform`
* `chef`: Chef settings
* `accept_mlsa`: Indicate acceptance of the Chef MLSA. Must update to `true`. Default: `false`
* `client_version`: Chef client version to install. Default: `12.12.15`
* `backend_count`: Count of chef-backend instances to deploy. Default: `4`
* `backend_version`: Chef backend version to install. Default: `1.0.9`
* `frontend_count`: Chef server core instance count. Default: `4`
* `frontend_version`: Chef server core version to install. Default: `12.8.0`
* `org`: Chef organization to create. Default: `chef`
* `org_long`: Chef long organization name. Default: `Chef Organization`
* `chef_backend`: Chef backend settings
* `count`: Count of chef-backend instances to deploy. Default: `4`
* `version`: Chef backend version to install. Default: `1.0.9`
* `chef_client`: Chef client version to install. Default: `12.12.15`
* `chef_mlsa`: Indicate acceptance of the Chef MLSA. Must update to `true`. Default: `false`
* `chef_org`: Chef organization settings
* `short`: Chef organization to create. Default: `chef`
* `long`: Chef long organization name. Default: `Chef Organization`
* `chef_server`: Chef server core settings
* `count`: Chef server core instance count. Default: `4`
* `version`: Chef server core version to install. Default: `12.8.0`
* `chef_user`: Chef initial user settings
* `username`: Chef username to create. Default: `chef`
* `user_email`: Chef user e-mail address. Default: `[email protected]`
* `user_firstname`: Chef user first name. Default: `Chef`
* `user_lastname`: Chef user last name. Default: `User`
* `email`: Chef user e-mail address. Default: `[email protected]`
* `first_name`: Chef user first name. Default: `Chef`
* `last_name`: Chef user last name. Default: `User`
* `instance`: Map of various AWS instance settings (backend and frontend)
* `backend_flavor`: Backend default instance type. Default: `r3.xlarge`
* `backend_iops`: Backend root volume IOPs (when using `io1`). Default: `6000`
Expand Down
48 changes: 24 additions & 24 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
resource "null_resource" "chef_mlsa" {
provisioner "local-exec" {
command = "bash ${path.module}/files/chef_mlsa.bash ${var.chef["accept_mlsa"]}"
command = "bash ${path.module}/files/chef_mlsa.bash ${var.chef_mlsa}"
}
}
#
Expand Down Expand Up @@ -216,7 +216,7 @@ resource "null_resource" "chef-prep" {
}
# Chef provisiong attributes_json and dna.json templating
resource "template_file" "be-attributes-json" {
count = "${var.chef["backend_count"]}"
count = "${var.chef_backend["count"]}"
template = "${file("${path.module}/files/attributes-json.tpl")}"
vars {
domain = "${var.domain}"
Expand All @@ -227,7 +227,7 @@ resource "template_file" "be-attributes-json" {
# Provision servers
# Backend: chef-backend
resource "aws_instance" "chef-backends" {
count = "${var.chef["backend_count"]}"
count = "${var.chef_backend["count"]}"
ami = "${lookup(var.ami, "${var.os}-${var.instance["backend_type"]}-${var.provider["region"]}")}"
ebs_optimized = "${var.instance["ebs_optimized"]}"
instance_type = "${var.instance["backend_flavor"]}"
Expand Down Expand Up @@ -269,8 +269,8 @@ resource "aws_instance" "chef-backends" {
# Install requirements and run chef-solo
provisioner "remote-exec" {
inline = [
"curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -v ${var.chef["client_version"]}",
"curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -P chef-backend -d /tmp -v ${var.chef["backend_version"]}",
"curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -v ${var.chef_client}",
"curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -P chef-backend -d /tmp -v ${var.chef_backend["version"]}",
"sudo chef-solo -j /tmp/dna.json -N ${self.tags.Name} -o 'recipe[system::default]'",
"rm -rf /tmp/dna.json",
]
Expand Down Expand Up @@ -316,7 +316,7 @@ resource "null_resource" "establish_leader" {
}
# Establish chef-backend cluster followers
resource "null_resource" "follow_leader" {
count = "${var.chef["backend_count"] - 1}"
count = "${var.chef_backend["count"] - 1}"
depends_on = ["null_resource.establish_leader"]
connection {
host = "${element(aws_instance.chef-backends.*.public_ip, count.index + 1)}"
Expand Down Expand Up @@ -348,15 +348,15 @@ resource "null_resource" "follow_leader" {
}
}
resource "aws_route53_record" "chef-backends-private" {
count = "${var.chef["backend_count"]}"
count = "${var.chef_backend["count"]}"
zone_id = "${var.r53_zones["internal"]}"
name = "${element(aws_instance.chef-backends.*.tags.Name, count.index)}"
type = "A"
ttl = "${var.r53_ttls["internal"]}"
records = ["${element(aws_instance.chef-backends.*.private_ip, count.index)}"]
}
resource "aws_route53_record" "chef-backends-public" {
count = "${var.chef["backend_count"]}"
count = "${var.chef_backend["count"]}"
zone_id = "${var.r53_zones["external"]}"
name = "${element(aws_instance.chef-backends.*.tags.Name, count.index)}"
type = "A"
Expand All @@ -367,15 +367,15 @@ resource "aws_route53_record" "chef-backends-public" {
# Frontend: chef-server-core
# Chef provisiong attributes_json and dna.json templating
resource "template_file" "frontend-attributes-json" {
count = "${var.chef["frontend_count"]}"
count = "${var.chef_server["count"]}"
template = "${file("${path.module}/files/frontend-attributes-json.tpl")}"
vars {
domain = "${var.domain}"
host = "${format("%s-%03d", var.instance_hostname["frontend"], count.index + 1)}"
}
}
resource "aws_instance" "chef-frontends" {
count = "${var.chef["frontend_count"]}"
count = "${var.chef_server["count"]}"
ami = "${lookup(var.ami, "${var.os}-${var.instance["frontend_type"]}-${var.provider["region"]}")}"
ebs_optimized = "${var.instance["ebs_optimized"]}"
instance_type = "${var.instance["frontend_flavor"]}"
Expand Down Expand Up @@ -428,23 +428,23 @@ resource "aws_instance" "chef-frontends" {
inline = [
"sudo mkdir -p /etc/opscode /var/opt/opscode/nginx/ca/ /var/opt/chef-manage",
"sudo touch /var/opt/chef-manage/.license.accepted",
"curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -v ${var.chef["client_version"]}",
"curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -P chef-server -d /tmp -v ${var.chef["frontend_version"]}",
"curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -v ${var.chef_client}",
"curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -P chef-server -d /tmp -v ${var.chef_server["version"]}",
"sudo chef-solo -j /tmp/dna.json -N ${self.tags.Name} -o 'recipe[system::default]'",
"[ $? -eq 0 ] && rm -f /tmp/dna.json",
]
}
}
resource "aws_route53_record" "chef-frontend-private" {
count = "${var.chef["frontend_count"]}"
count = "${var.chef_server["count"]}"
zone_id = "${var.r53_zones["internal"]}"
name = "${element(aws_instance.chef-frontends.*.tags.Name, count.index)}"
type = "A"
ttl = "${var.r53_ttls["internal"]}"
records = ["${element(aws_instance.chef-frontends.*.private_ip, count.index)}"]
}
resource "aws_route53_record" "chef-frontend-public" {
count = "${var.chef["frontend_count"]}"
count = "${var.chef_server["count"]}"
zone_id = "${var.r53_zones["external"]}"
name = "${element(aws_instance.chef-frontends.*.tags.Name, count.index)}"
type = "A"
Expand All @@ -453,7 +453,7 @@ resource "aws_route53_record" "chef-frontend-public" {
}
resource "null_resource" "generate_frontend_cfg" {
depends_on = ["null_resource.follow_leader"]
count = "${var.chef["frontend_count"]}"
count = "${var.chef_server["count"]}"
connection {
host = "${aws_instance.chef-backends.0.public_ip}"
user = "${var.ami_user[var.os]}"
Expand Down Expand Up @@ -522,7 +522,7 @@ resource "null_resource" "first_frontend" {
}
}
resource "null_resource" "other_frontends" {
count = "${var.chef["frontend_count"] - 1}"
count = "${var.chef_server["count"] - 1}"
depends_on = ["null_resource.first_frontend"]
connection {
host = "${element(aws_instance.chef-frontends.*.public_ip, count.index + 1)}"
Expand Down Expand Up @@ -565,9 +565,9 @@ data "template_file" "knife-rb" {
depends_on = ["null_resource.chef-prep"]
template = "${file("${path.module}/files/knife-rb.tpl")}"
vars {
user = "${var.chef["username"]}"
user = "${var.chef_user["username"]}"
fqdn = "${var.elb["hostname"]}.${var.domain}"
org = "${var.chef["org"]}"
org = "${var.chef_org["short"]}"
}
}
# Setting up Chef Server
Expand All @@ -581,17 +581,17 @@ resource "null_resource" "chef-setup" {
# TODO: Maybe create parametertized script to run these commands (wrapping chef-server-ctl)
provisioner "remote-exec" {
inline = [
"sudo chef-server-ctl user-create ${var.chef["username"]} ${var.chef["user_firstname"]} ${var.chef["user_lastname"]} ${var.chef["user_email"]} ${base64sha256(aws_instance.chef-frontends.0.id)} -f /tmp/${var.chef["username"]}.pem",
"sudo chef-server-ctl org-create ${var.chef["org"]} '${var.chef["org_long"]}' --association_user ${var.chef["username"]} --filename /tmp/${var.chef["org"]}-validator.pem",
"sudo chown ${var.ami_user[var.os]} /tmp/${var.chef["username"]}.pem /tmp/${var.chef["org"]}-validator.pem",
"sudo chef-server-ctl user-create ${var.chef_user["username"]} ${var.chef_user["first_name"]} ${var.chef_user["last_name"]} ${var.chef_user["email"]} ${base64sha256(aws_instance.chef-frontends.0.id)} -f /tmp/${var.chef_user["username"]}.pem",
"sudo chef-server-ctl org-create ${var.chef_org["short"]} '${var.chef_org["long"]}' --association_user ${var.chef_user["username"]} --filename /tmp/${var.chef_org["short"]}-validator.pem",
"sudo chown ${var.ami_user[var.os]} /tmp/${var.chef_user["username"]}.pem /tmp/${var.chef_org["short"]}-validator.pem",
]
}
# Copy back files
provisioner "local-exec" {
command = <<-EOC
rm -f .chef/${var.chef["org"]}-validator.pem .chef/${var.chef["username"]}.pem
scp -r -o stricthostkeychecking=no -i ${var.instance_keys["key_file"]} ${var.ami_user[var.os]}@${aws_instance.chef-frontends.0.public_ip}:/tmp/${var.chef["org"]}-validator.pem .chef/${var.chef["org"]}-validator.pem
scp -r -o stricthostkeychecking=no -i ${var.instance_keys["key_file"]} ${var.ami_user[var.os]}@${aws_instance.chef-frontends.0.public_ip}:/tmp/${var.chef["username"]}.pem .chef/${var.chef["username"]}.pem
rm -f .chef/${var.chef_org["short"]}-validator.pem .chef/${var.chef_user["username"]}.pem
scp -r -o stricthostkeychecking=no -i ${var.instance_keys["key_file"]} ${var.ami_user[var.os]}@${aws_instance.chef-frontends.0.public_ip}:/tmp/${var.chef_org["short"]}-validator.pem .chef/${var.chef_org["short"]}-validator.pem
scp -r -o stricthostkeychecking=no -i ${var.instance_keys["key_file"]} ${var.ami_user[var.os]}@${aws_instance.chef-frontends.0.public_ip}:/tmp/${var.chef_user["username"]}.pem .chef/${var.chef_user["username"]}.pem
EOC
}
}
Expand Down
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Outputs
output "chef_manage_url" {
value = "https://${var.elb["hostname"]}.${var.domain}/organizations/${var.chef["org"]}"
value = "https://${var.elb["hostname"]}.${var.domain}/organizations/${var.chef_org["short"]}"
}
output "chef_username" {
value = "${var.chef["username"]}"
value = "${var.chef_user["username"]}"
}
output "chef_user_password" {
sensitive = true
Expand Down
34 changes: 20 additions & 14 deletions terraform.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,26 @@ ssl_certificate = {
#
# Chef settings
#
chef = {
accept_mlsa = false # UPDATE THIS!
client_version = "12.12.15"
backend_count = 4
backend_version = "1.0.9"
frontend_count = 4
frontend_version = "12.8.0"
org = "chef"
org_long = "Chef Organization"
username = "chef"
user_firstname = "Chef"
user_lastnname = "User"
user_email = "[email protected]"
}
#chef_backend = {
# count = 4
# version = "1.1.12"
#}
#chef_client = "12.12.15"
chef_mlsa = "false" # Must update this to true!
#chef_org = {
# short = "chef"
# long = "Chef Organization"
#}
#chef_server = {
# count = 4
# version = "12.8.0"
#}
#chef_user = {
# username = "chef"
# first_name = "Chef"
# last_nname = "User"
# email = "[email protected]"
#}
#
# AWS Route53 settings
#
Expand Down
52 changes: 39 additions & 13 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,50 @@ variable "elb" {
#
# Chef settings
#
variable "chef" {
variable "chef_backend" {
type = "map"
description = "Various Chef related settings"
description = "Chef backend settings"
default = {
accept_mlsa = false
client_version = "12.12.15"
backend_count = 4
backend_version = "1.0.9"
frontend_count = 4
frontend_version = "12.8.0"
org = "chef"
org_long = "Chef Organization"
count = 4
version = "1.1.12"
}
}
variable "chef_server" {
type = "map"
description = "Chef server core settings"
default = {
count = 4
version = "12.8.0"
}
}
variable "chef_user" {
type = "map"
description = "Chef user creation settings"
default = {
email = "[email protected]"
first_name = "Chef"
last_name = "User"
username = "chef"
user_email = "[email protected]"
user_firstname = "Chef"
user_lastname = "User"
}
}
variable "chef_org" {
type = "map"
description = "Chef organization settings"
default = {
short = "chef"
long = "Chef Organization"
}
}
variable "chef_client" {
type = "string"
description = "Chef client version"
default = "12.12.15"
}
variable "chef_mlsa" {
# type = "string"
description = "Chef MLSA license agreement"
default = false
}
#
# AWS EC2 instance settings
#
Expand Down

0 comments on commit cd28353

Please sign in to comment.