Skip to content

Commit

Permalink
~ consul-cluster: fix /etc/consul permissions (777->600)
Browse files Browse the repository at this point in the history
ref #75
  • Loading branch information
clstokes committed Oct 25, 2015
1 parent c1bf581 commit 8a72aa5
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 60 deletions.
76 changes: 40 additions & 36 deletions consul-cluster/aws-beginner-consul-cluster/terraform/instances.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ resource "aws_instance" "consul_client" {
Name = "consul_client"
}

provisioner "remote-exec" {
provisioner "file" {
connection {
user = "ubuntu"
key_file = "${module.shared.private_key_path}"
agent = "false"
}

scripts = [
"${module.shared.path}/consul/installers/consul_install.sh"
]
source = "${module.shared.path}/consul/consul.d/consul_client.json"
destination = "/tmp/consul.json.tmp"
}

provisioner "file" {
Expand All @@ -44,19 +43,21 @@ resource "aws_instance" "consul_client" {
agent = "false"
}

source = "${module.shared.path}/consul/consul.d/consul_client.json"
destination = "/etc/consul.d/consul.json.tmp"
source = "${module.shared.path}/consul/init/consul.conf"
destination = "/tmp/consul.conf"
}

provisioner "file" {
provisioner "remote-exec" {
connection {
user = "ubuntu"
key_file = "${module.shared.private_key_path}"
agent = "false"
}

source = "${module.shared.path}/consul/init/consul.conf"
destination = "/etc/init/consul.conf"
scripts = [
"${module.shared.path}/consul/installers/consul_install.sh",
"${module.shared.path}/consul/installers/consul_conf_install.sh",
]
}

provisioner "remote-exec" {
Expand Down Expand Up @@ -86,16 +87,15 @@ resource "aws_instance" "consul_0" {
Name = "consul_0"
}

provisioner "remote-exec" {
provisioner "file" {
connection {
user = "ubuntu"
key_file = "${module.shared.private_key_path}"
agent = "false"
}

scripts = [
"${module.shared.path}/consul/installers/consul_install.sh"
]
source = "${module.shared.path}/consul/consul.d/consul_server.json"
destination = "/tmp/consul.json.tmp"
}

provisioner "file" {
Expand All @@ -105,19 +105,21 @@ resource "aws_instance" "consul_0" {
agent = "false"
}

source = "${module.shared.path}/consul/consul.d/consul_server.json"
destination = "/etc/consul.d/consul.json.tmp"
source = "${module.shared.path}/consul/init/consul.conf"
destination = "/tmp/consul.conf"
}

provisioner "file" {
provisioner "remote-exec" {
connection {
user = "ubuntu"
key_file = "${module.shared.private_key_path}"
agent = "false"
}

source = "${module.shared.path}/consul/init/consul.conf"
destination = "/etc/init/consul.conf"
scripts = [
"${module.shared.path}/consul/installers/consul_install.sh",
"${module.shared.path}/consul/installers/consul_conf_install.sh",
]
}

provisioner "remote-exec" {
Expand All @@ -144,16 +146,15 @@ resource "aws_instance" "consul_1" {
Name = "consul_1"
}

provisioner "remote-exec" {
provisioner "file" {
connection {
user = "ubuntu"
key_file = "${module.shared.private_key_path}"
agent = "false"
}

scripts = [
"${module.shared.path}/consul/installers/consul_install.sh"
]
source = "${module.shared.path}/consul/consul.d/consul_server.json"
destination = "/tmp/consul.json.tmp"
}

provisioner "file" {
Expand All @@ -163,19 +164,21 @@ resource "aws_instance" "consul_1" {
agent = "false"
}

source = "${module.shared.path}/consul/consul.d/consul_server.json"
destination = "/etc/consul.d/consul.json.tmp"
source = "${module.shared.path}/consul/init/consul.conf"
destination = "/tmp/consul.conf"
}

provisioner "file" {
provisioner "remote-exec" {
connection {
user = "ubuntu"
key_file = "${module.shared.private_key_path}"
agent = "false"
}

source = "${module.shared.path}/consul/init/consul.conf"
destination = "/etc/init/consul.conf"
scripts = [
"${module.shared.path}/consul/installers/consul_install.sh",
"${module.shared.path}/consul/installers/consul_conf_install.sh",
]
}

provisioner "remote-exec" {
Expand All @@ -202,16 +205,15 @@ resource "aws_instance" "consul_2" {
Name = "consul_2"
}

provisioner "remote-exec" {
provisioner "file" {
connection {
user = "ubuntu"
key_file = "${module.shared.private_key_path}"
agent = "false"
}

scripts = [
"${module.shared.path}/consul/installers/consul_install.sh"
]
source = "${module.shared.path}/consul/consul.d/consul_server.json"
destination = "/tmp/consul.json.tmp"
}

provisioner "file" {
Expand All @@ -221,19 +223,21 @@ resource "aws_instance" "consul_2" {
agent = "false"
}

source = "${module.shared.path}/consul/consul.d/consul_server.json"
destination = "/etc/consul.d/consul.json.tmp"
source = "${module.shared.path}/consul/init/consul.conf"
destination = "/tmp/consul.conf"
}

provisioner "file" {
provisioner "remote-exec" {
connection {
user = "ubuntu"
key_file = "${module.shared.private_key_path}"
agent = "false"
}

source = "${module.shared.path}/consul/init/consul.conf"
destination = "/etc/init/consul.conf"
scripts = [
"${module.shared.path}/consul/installers/consul_install.sh",
"${module.shared.path}/consul/installers/consul_conf_install.sh",
]
}

provisioner "remote-exec" {
Expand Down
3 changes: 0 additions & 3 deletions consul-cluster/shared/consul/consul.d/consul_client.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"node_name": "{{ instance_id }}",
"service": {
"name": "consul-client"
},

"atlas_join": true,
"atlas_infrastructure": "{{ atlas_username }}/{{ atlas_environment }}",
Expand Down
3 changes: 0 additions & 3 deletions consul-cluster/shared/consul/consul.d/consul_server.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"node_name": "{{ instance_id }}",
"service": {
"name": "consul"
},

"atlas_join": true,
"atlas_infrastructure": "{{ atlas_username }}/{{ atlas_environment }}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"node_name": "{{ instance_id }}",
"service": {
"name": "consul"
},

"atlas_join": true,
"atlas_infrastructure": "{{ atlas_username }}/{{ atlas_environment }}",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -ex

sudo mv /tmp/consul.conf /etc/init/
sudo mv /tmp/consul.json.tmp /etc/consul.d/
4 changes: 1 addition & 3 deletions consul-cluster/shared/consul/installers/consul_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ echo "Installing consul..."
unzip consul.zip
sudo chmod +x consul
sudo mv consul /usr/bin/consul
sudo mkdir -m 777 /etc/consul.d
sudo chmod a+w /var/log
sudo chmod a+w /etc/init/
sudo mkdir -m 0600 /etc/consul.d

# setup consul directories
sudo mkdir -p /opt/consul/data
Expand Down
12 changes: 6 additions & 6 deletions consul-cluster/shared/consul/userdata/consul_update.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ set -e
FILE_FINAL=/etc/consul.d/consul.json
FILE_TMP=$FILE_FINAL.tmp

sed -i -- "s/{{ region }}/${region}/g" $FILE_TMP
sed -i -- "s/{{ atlas_token }}/${atlas_token}/g" $FILE_TMP
sed -i -- "s/{{ atlas_username }}/${atlas_username}/g" $FILE_TMP
sed -i -- "s/{{ atlas_environment }}/${atlas_environment}/g" $FILE_TMP
sudo sed -i -- "s/{{ region }}/${region}/g" $FILE_TMP
sudo sed -i -- "s/{{ atlas_token }}/${atlas_token}/g" $FILE_TMP
sudo sed -i -- "s/{{ atlas_username }}/${atlas_username}/g" $FILE_TMP
sudo sed -i -- "s/{{ atlas_environment }}/${atlas_environment}/g" $FILE_TMP
# Note: consul_bootstrap_expect isn't required for consul clients, only servers.
sed -i -- "s/{{ consul_bootstrap_expect }}/${consul_bootstrap_expect}/g" $FILE_TMP
sudo sed -i -- "s/{{ consul_bootstrap_expect }}/${consul_bootstrap_expect}/g" $FILE_TMP

# Note: placeholders below replaced by bash, not the Terraform go template.
METADATA_INSTANCE_ID=`curl http://169.254.169.254/2014-02-25/meta-data/instance-id`
sed -i -- "s/{{ instance_id }}/$METADATA_INSTANCE_ID/g" $FILE_TMP
sudo sed -i -- "s/{{ instance_id }}/$METADATA_INSTANCE_ID/g" $FILE_TMP

sudo mv $FILE_TMP $FILE_FINAL
sudo service consul start
Expand Down
9 changes: 7 additions & 2 deletions consul-cluster/shared/packer/consul_client.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@
{
"type": "file",
"source": "shared/consul/consul.d/consul_client.json",
"destination": "/etc/consul.d/consul.json.tmp"
"destination": "/tmp/consul.json.tmp"
},
{
"type": "file",
"source": "shared/consul/init/consul.conf",
"destination": "/etc/init/consul.conf"
"destination": "/tmp/consul.conf"
},
{
"type": "shell",
"script": "shared/consul/installers/consul_conf_install.sh"
}
],
"push": {
"name": "{{user `atlas_username`}}/{{user `atlas_name`}}",
"vcs": false,
"base_dir": "../../",
"include": [
"shared/consul/installers/consul_conf_install.sh",
"shared/consul/installers/consul_install.sh",
"shared/consul/consul.d/consul_client.json",
"shared/consul/init/consul.conf"
Expand Down
9 changes: 7 additions & 2 deletions consul-cluster/shared/packer/consul_server.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@
{
"type": "file",
"source": "shared/consul/consul.d/consul_server.json",
"destination": "/etc/consul.d/consul.json.tmp"
"destination": "/tmp/consul.json.tmp"
},
{
"type": "file",
"source": "shared/consul/init/consul.conf",
"destination": "/etc/init/consul.conf"
"destination": "/tmp/consul.conf"
},
{
"type": "shell",
"script": "shared/consul/installers/consul_conf_install.sh"
}
],
"push": {
"name": "{{user `atlas_username`}}/{{user `atlas_name`}}",
"vcs": false,
"base_dir": "../../",
"include": [
"shared/consul/installers/consul_conf_install.sh",
"shared/consul/installers/consul_install.sh",
"shared/consul/consul.d/consul_server.json",
"shared/consul/init/consul.conf"
Expand Down
9 changes: 7 additions & 2 deletions consul-cluster/shared/packer/consul_server_multiregion.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@
{
"type": "file",
"source": "shared/consul/consul.d/consul_server_multiregion.json",
"destination": "/etc/consul.d/consul.json.tmp"
"destination": "/tmp/consul.json.tmp"
},
{
"type": "file",
"source": "shared/consul/init/consul.conf",
"destination": "/etc/init/consul.conf"
"destination": "/tmp/consul.conf"
},
{
"type": "shell",
"script": "shared/consul/installers/consul_conf_install.sh"
}
],
"push": {
"name": "{{user `atlas_username`}}/{{user `atlas_name`}}",
"vcs": false,
"base_dir": "../../",
"include": [
"shared/consul/installers/consul_conf_install.sh",
"shared/consul/installers/consul_install.sh",
"shared/consul/consul.d/consul_server_multiregion.json",
"shared/consul/init/consul.conf"
Expand Down

0 comments on commit 8a72aa5

Please sign in to comment.