diff --git a/terraform/aws/Vagrantfile b/terraform/Vagrantfile similarity index 65% rename from terraform/aws/Vagrantfile rename to terraform/Vagrantfile index 9b44d2203..6dd5cd28c 100644 --- a/terraform/aws/Vagrantfile +++ b/terraform/Vagrantfile @@ -8,14 +8,20 @@ Vagrant.configure(2) do |config| cd /tmp - PACKERVERSION=1.0.0 + PACKERVERSION=1.1.1 PACKERDOWNLOAD=https://releases.hashicorp.com/packer/${PACKERVERSION}/packer_${PACKERVERSION}_linux_amd64.zip - TERRAFORMVERSION=0.9.8 + TERRAFORMVERSION=0.10.8 TERRAFORMDOWNLOAD=https://releases.hashicorp.com/terraform/${TERRAFORMVERSION}/terraform_${TERRAFORMVERSION}_linux_amd64.zip echo "Dependencies..." sudo apt-get install -y unzip tree + # Azure CLI + echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | sudo tee /etc/apt/sources.list.d/azure-cli.list + sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 417A0893 + sudo apt-get install apt-transport-https + sudo apt-get update && sudo apt-get install azure-cli + # Disable the firewall sudo ufw disable @@ -43,9 +49,10 @@ Vagrant.configure(2) do |config| SHELL - config.vm.synced_folder "../aws/", "/home/vagrant/aws", owner: "vagrant", group: "vagrant" - config.vm.synced_folder "../shared/", "/home/vagrant/shared", owner: "vagrant", group: "vagrant" - config.vm.synced_folder "../examples/", "/home/vagrant/examples", owner: "vagrant", group: "vagrant" + config.vm.synced_folder "aws/", "/home/vagrant/aws", owner: "vagrant", group: "vagrant" + config.vm.synced_folder "azure/", "/home/vagrant/azure", owner: "vagrant", group: "vagrant" + config.vm.synced_folder "shared/", "/home/vagrant/shared", owner: "vagrant", group: "vagrant" + config.vm.synced_folder "examples/", "/home/vagrant/examples", owner: "vagrant", group: "vagrant" config.vm.provider "virtualbox" do |vb| vb.memory = "2048" diff --git a/terraform/aws/packer/packer.json b/terraform/aws/packer.json similarity index 75% rename from terraform/aws/packer/packer.json rename to terraform/aws/packer.json index 5f20bc3c2..fce82be8d 100644 --- a/terraform/aws/packer/packer.json +++ b/terraform/aws/packer.json @@ -5,7 +5,7 @@ "source_ami": "ami-80861296", "instance_type": "t2.medium", "ssh_username": "ubuntu", - "ami_name": "nomad-packer {{timestamp}}", + "ami_name": "hashistack {{timestamp}}", "ami_groups": ["all"] }], "provisioners": [ @@ -18,16 +18,16 @@ }, { "type": "file", - "source": "../../shared", + "source": "../shared", "destination": "/ops" }, { "type": "file", - "source": "../../examples", + "source": "../examples", "destination": "/ops" }, { "type": "shell", - "script": "../../shared/scripts/setup.sh" + "script": "../shared/scripts/setup.sh" }] } diff --git a/terraform/aws/packer/README.md b/terraform/aws/packer/README.md deleted file mode 100644 index d42a40567..000000000 --- a/terraform/aws/packer/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Build an Amazon machine image with Packer - -[Packer](https://www.packer.io/intro/index.html) is HashiCorp's open source tool -for creating identical machine images for multiple platforms from a single -source configuration. The Terraform templates included in this repo reference a -publicly avaialble Amazon machine image (AMI) by default. The Packer build -configuration used to create the public AMI is included [here](./packer.json). -If you wish to customize it and build your own private AMI, follow the -instructions below. - -## Pre-requisites - -See the pre-requisites listed [here](../../README.md). If you did not use the -included `Vagrantfile` to bootstrap a staging environment, you will need to -[install Packer](https://www.packer.io/intro/getting-started/install.html). - -Set environment variables for your AWS credentials if you haven't already: - -```bash -$ export AWS_ACCESS_KEY_ID=[ACCESS_KEY_ID] -$ export AWS_SECRET_ACCESS_KEY=[SECRET_ACCESS_KEY] -``` - -After you make your modifications to `packer.json`, execute the following -command to build the AMI: - -```bash -$ packer build packer.json -``` - -Don't forget to copy the AMI ID to your [terraform.tfvars file](../env/us-east/terraform.tfvars). diff --git a/terraform/azure/packer/packer.json b/terraform/azure/packer.json similarity index 88% rename from terraform/azure/packer/packer.json rename to terraform/azure/packer.json index 75fa592ab..3ad6d4e88 100644 --- a/terraform/azure/packer/packer.json +++ b/terraform/azure/packer.json @@ -18,9 +18,9 @@ "image_sku": "16.04-LTS", "os_type": "Linux", "ssh_username": "packer", - "managed_image_name": "nomad", + "managed_image_name": "hashistack", "azure_tags": { - "Product": "Consul" + "Product": "Hashistack" } }], "provisioners": [ @@ -33,17 +33,17 @@ }, { "type": "file", - "source": "../../shared", + "source": "../shared", "destination": "/ops" }, { "type": "file", - "source": "../../examples", + "source": "../examples", "destination": "/ops" }, { "type": "shell", - "script": "../../shared/scripts/setup.sh" + "script": "../shared/scripts/setup.sh" }, { "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", diff --git a/terraform/shared/config/consul_aws.service b/terraform/shared/config/consul_aws.service new file mode 100644 index 000000000..02931a65a --- /dev/null +++ b/terraform/shared/config/consul_aws.service @@ -0,0 +1,16 @@ +[Unit] +Description=Consul Agent +Requires=network-online.target +After=network-online.target + +[Service] +Restart=on-failure +Environment=CONSUL_ALLOW_PRIVILEGED_PORTS=true +ExecStart=/usr/local/bin/consul agent -config-dir="/etc/consul.d" -dns-port="53" -recursor="172.31.0.2" +ExecReload=/bin/kill -HUP $MAINPID +KillSignal=SIGTERM +User=root +Group=root + +[Install] +WantedBy=multi-user.target diff --git a/terraform/shared/config/consul_azure.service b/terraform/shared/config/consul_azure.service new file mode 100644 index 000000000..3f9b24103 --- /dev/null +++ b/terraform/shared/config/consul_azure.service @@ -0,0 +1,16 @@ +[Unit] +Description=Consul Agent +Requires=network-online.target +After=network-online.target + +[Service] +Restart=on-failure +Environment=CONSUL_ALLOW_PRIVILEGED_PORTS=true +ExecStart=/usr/local/bin/consul agent -config-dir="/etc/consul.d" -dns-port="53" -recursor="168.63.129.16" +ExecReload=/bin/kill -HUP $MAINPID +KillSignal=SIGTERM +User=root +Group=root + +[Install] +WantedBy=multi-user.target diff --git a/terraform/shared/config/consul_upstart_aws.conf b/terraform/shared/config/consul_upstart_aws.conf deleted file mode 100644 index 46cff07a1..000000000 --- a/terraform/shared/config/consul_upstart_aws.conf +++ /dev/null @@ -1,24 +0,0 @@ -description "Consul" - -start on runlevel [2345] -stop on runlevel [!2345] - -respawn - -console log - -script - if [ -f "/etc/service/consul" ]; then - . /etc/service/consul - fi - - # Allow Consul to use privileged ports - export CONSUL_ALLOW_PRIVILEGED_PORTS=true - - exec /usr/local/bin/consul agent \ - -config-dir="/etc/consul.d" \ - -dns-port="53" \ - -recursor="172.31.0.2" \ - \$${CONSUL_FLAGS} \ - >>/var/log/consul.log 2>&1 -end script diff --git a/terraform/shared/config/consul_upstart_azure.conf b/terraform/shared/config/consul_upstart_azure.conf deleted file mode 100644 index 63dadbf01..000000000 --- a/terraform/shared/config/consul_upstart_azure.conf +++ /dev/null @@ -1,24 +0,0 @@ -description "Consul" - -start on runlevel [2345] -stop on runlevel [!2345] - -respawn - -console log - -script - if [ -f "/etc/service/consul" ]; then - . /etc/service/consul - fi - - # Allow Consul to use privileged ports - export CONSUL_ALLOW_PRIVILEGED_PORTS=true - - exec /usr/local/bin/consul agent \ - -config-dir="/etc/consul.d" \ - -dns-port="53" \ - -recursor="168.63.129.16" \ - \$${CONSUL_FLAGS} \ - >>/var/log/consul.log 2>&1 -end script diff --git a/terraform/shared/config/nomad.hcl b/terraform/shared/config/nomad.hcl index 4e4be0033..99692881e 100644 --- a/terraform/shared/config/nomad.hcl +++ b/terraform/shared/config/nomad.hcl @@ -7,8 +7,6 @@ server { bootstrap_expect = SERVER_COUNT } -name = "nomad@IP_ADDRESS" - consul { address = "127.0.0.1:8500" } diff --git a/terraform/shared/config/nomad.service b/terraform/shared/config/nomad.service new file mode 100644 index 000000000..a7f977494 --- /dev/null +++ b/terraform/shared/config/nomad.service @@ -0,0 +1,15 @@ +[Unit] +Description=Nomad Agent +Requires=network-online.target +After=network-online.target + +[Service] +Restart=on-failure +ExecStart=/usr/local/bin/nomad agent -config="/etc/nomad.d/nomad.hcl" +ExecReload=/bin/kill -HUP $MAINPID +KillSignal=SIGTERM +User=root +Group=root + +[Install] +WantedBy=multi-user.target diff --git a/terraform/shared/config/nomad_client.hcl b/terraform/shared/config/nomad_client.hcl index 97ec4a5e0..c9cbb14d0 100644 --- a/terraform/shared/config/nomad_client.hcl +++ b/terraform/shared/config/nomad_client.hcl @@ -1,6 +1,5 @@ data_dir = "/opt/nomad/data" bind_addr = "0.0.0.0" -name = "nomad@IP_ADDRESS" # Enable the client client { diff --git a/terraform/shared/config/nomad_upstart.conf b/terraform/shared/config/nomad_upstart.conf deleted file mode 100644 index a90339577..000000000 --- a/terraform/shared/config/nomad_upstart.conf +++ /dev/null @@ -1,19 +0,0 @@ -description "Nomad" - -start on runlevel [2345] -stop on runlevel [!2345] - -respawn - -console log - -script - if [ -f "/etc/service/nomad" ]; then - . /etc/service/nomad - fi - - exec /usr/local/bin/nomad agent \ - -config="/etc/nomad.d/nomad.hcl" \ - \$${NOMAD_FLAGS} \ - >>/var/log/nomad.log 2>&1 -end script diff --git a/terraform/shared/config/vault.service b/terraform/shared/config/vault.service new file mode 100644 index 000000000..3f8b4f3be --- /dev/null +++ b/terraform/shared/config/vault.service @@ -0,0 +1,16 @@ +[Unit] +Description=Vault Agent +Requires=network-online.target +After=network-online.target + +[Service] +Restart=on-failure +Environment=GOMAXPROCS=nproc +ExecStart=/usr/local/bin/vault server -config="/etc/vault.d/vault.hcl" +ExecReload=/bin/kill -HUP $MAINPID +KillSignal=SIGTERM +User=root +Group=root + +[Install] +WantedBy=multi-user.target diff --git a/terraform/shared/config/vault_upstart.conf b/terraform/shared/config/vault_upstart.conf deleted file mode 100644 index 28b81a99b..000000000 --- a/terraform/shared/config/vault_upstart.conf +++ /dev/null @@ -1,22 +0,0 @@ -description "Vault" - -start on runlevel [2345] -stop on runlevel [!2345] - -respawn - -console log - -script - if [ -f "/etc/service/vault" ]; then - . /etc/service/vault - fi - - # Make sure to use all our CPUs, because Vault can block a scheduler thread - export GOMAXPROCS=`nproc` - - exec /usr/local/bin/vault server \ - -config="/etc/vault.d/vault.hcl" \ - \$${VAULT_FLAGS} \ - >>/var/log/vault.log 2>&1 -end script