Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from hashicorp/tf12-upgrade
Browse files Browse the repository at this point in the history
Tf12 upgrade
  • Loading branch information
Etiene authored Jul 2, 2019
2 parents c1f5b5f + b78bf24 commit ea3cc2c
Show file tree
Hide file tree
Showing 21 changed files with 1,487 additions and 282 deletions.
56 changes: 56 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
workspace_root: &workspace_root
/go/src/github.com/hashicorp/terraform-google-nomad

defaults: &defaults
working_directory: *workspace_root
docker:
- image: gruntwork/circle-ci-test-image-base:go1.11

version: 2
jobs:
build:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: *workspace_root
- restore_cache:
keys:
- dep-{{ checksum "test/Gopkg.lock" }}
- run: configure-environment-for-gruntwork-module --go-src-path test --use-go-dep --circle-ci-2
- save_cache:
key: dep-{{ checksum "test/Gopkg.lock" }}
paths:
- /go/src/github.com/hashicorp/terraform-google-nomad/test/vendor
- persist_to_workspace:
root: *workspace_root
paths: test/vendor
test:
<<: *defaults
steps:
- checkout
- run: echo 'export PATH=$HOME/terraform:$HOME/packer:$PATH' >> $BASH_ENV
- attach_workspace:
at: *workspace_root
# Write service account creds to disk where the API expects them
- run: mkdir -p /tmp/logs
- run: |
export GOOGLE_APPLICATION_CREDENTIALS="/tmp/gcloud.json" && \
echo $GCLOUD_SERVICE_KEY > /tmp/gcloud.json && \
run-go-tests --circle-ci-2 --path test | tee /tmp/logs/all.log
- run:
command: terratest_log_parser --testlog /tmp/logs/all.log --outputdir /tmp/logs
when: always
- store_artifacts:
path: /tmp/logs
- store_test_results:
path: /tmp/logs

workflows:
version: 2
build-and-test:
jobs:
- build
- test:
requires:
- build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
terraform.tfstate
terraform.tfvars
*.tfstate*
*.test-data

# OS X files
.history
Expand Down
24 changes: 17 additions & 7 deletions examples/nomad-consul-image/nomad-consul.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"min_packer_version": "1.0.4",
"variables": {
"project_id": null,
"zone": null,
"nomad_version": "0.6.3",
"consul_module_version": "v0.0.1",
"consul_version": "0.9.3"
"project_id": "",
"zone": "",
"nomad_version": "0.9.3",
"consul_module_version": "v0.4.0",
"consul_version": "1.5.1"
},
"builders": [{
"type": "googlecompute",
Expand All @@ -17,9 +17,12 @@
"ssh_username": "ubuntu"
}],
"provisioners": [{
"type": "shell",
"inline": ["mkdir -p /tmp/terraform-google-nomad/modules"]
},{
"type": "file",
"source": "{{template_dir}}/../../../terraform-google-nomad",
"destination": "/tmp",
"source": "{{template_dir}}/../../modules/",
"destination": "/tmp/terraform-google-nomad/modules",
"pause_before": "30s"
},{
"type": "shell",
Expand All @@ -31,6 +34,13 @@
"inline": [
"sudo apt-get install -y git"
]
},{
"type": "shell",
"inline": [
"sudo mkdir -p /opt/gruntwork",
"git clone --branch v0.0.3 https://github.com/gruntwork-io/bash-commons.git /tmp/bash-commons",
"sudo cp -r /tmp/bash-commons/modules/bash-commons/src /opt/gruntwork/bash-commons"
]
},{
"type": "shell",
"inline": [
Expand Down
93 changes: 47 additions & 46 deletions examples/nomad-consul-separate-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# ---------------------------------------------------------------------------------------------------------------------

provider "google" {
project = "${var.gcp_project}"
region = "${var.gcp_region}"
project = var.gcp_project
region = var.gcp_region
}

# Use Terraform 0.10.x so that we can take advantage of Terraform GCP functionality as a separate provider via
# https://github.com/terraform-providers/terraform-provider-google
terraform {
required_version = ">= 0.10.3"
# The modules used in this example have been updated with 0.12 syntax, which means the example is no longer
# compatible with any versions below 0.12.
required_version = ">= 0.12"
}

# ---------------------------------------------------------------------------------------------------------------------
Expand All @@ -33,15 +33,15 @@ module "nomad_servers" {
# source = "git::[email protected]:hashicorp/terraform-google-nomad.git//modules/nomad-cluster?ref=v0.0.1"
source = "../../modules/nomad-cluster"

gcp_zone = "${var.gcp_zone}"
gcp_region = var.gcp_region

cluster_name = "${var.nomad_server_cluster_name}"
cluster_size = "${var.nomad_server_cluster_size}"
cluster_tag_name = "${var.nomad_server_cluster_name}"
machine_type = "${var.nomad_server_cluster_machine_type}"
cluster_name = var.nomad_server_cluster_name
cluster_size = var.nomad_server_cluster_size
cluster_tag_name = var.nomad_server_cluster_name
machine_type = var.nomad_server_cluster_machine_type

source_image = "${var.nomad_server_source_image}"
startup_script = "${data.template_file.startup_script_nomad_server.rendered}"
source_image = var.nomad_server_source_image
startup_script = data.template_file.startup_script_nomad_server.rendered

# WARNING!
# In a production setting, we strongly recommend only launching a Nomad Server cluster as private nodes.
Expand All @@ -52,18 +52,18 @@ module "nomad_servers" {
allowed_inbound_cidr_blocks_http = ["0.0.0.0/0"]

# Enable the Consul Cluster to reach the Nomad Cluster
allowed_inbound_tags_http = ["${var.consul_server_cluster_name}", "${var.nomad_client_cluster_name}"]
allowed_inbound_tags_rpc = ["${var.consul_server_cluster_name}", "${var.nomad_client_cluster_name}"]
allowed_inbound_tags_serf = ["${var.consul_server_cluster_name}", "${var.nomad_client_cluster_name}"]
allowed_inbound_tags_http = [var.consul_server_cluster_name, var.nomad_client_cluster_name]
allowed_inbound_tags_rpc = [var.consul_server_cluster_name, var.nomad_client_cluster_name]
allowed_inbound_tags_serf = [var.consul_server_cluster_name, var.nomad_client_cluster_name]
}

# Render the Startup Script that will run on each Nomad Instance on boot. This script will configure and start Nomad.
data "template_file" "startup_script_nomad_server" {
template = "${file("${path.module}/startup-script-nomad-server.sh")}"
template = file("${path.module}/startup-script-nomad-server.sh")

vars {
num_servers = "${var.nomad_server_cluster_size}"
consul_server_cluster_tag_name = "${var.consul_server_cluster_name}"
vars = {
num_servers = var.nomad_server_cluster_size
consul_server_cluster_tag_name = var.consul_server_cluster_name
}
}

Expand All @@ -72,33 +72,35 @@ data "template_file" "startup_script_nomad_server" {
# ---------------------------------------------------------------------------------------------------------------------

module "consul_cluster" {
source = "git::[email protected]:gruntwork-io/terraform-google-consul.git//modules/consul-cluster?ref=v0.0.2"
source = "git::[email protected]:hashicorp/terraform-google-consul.git//modules/consul-cluster?ref=v0.4.0"

gcp_zone = "${var.gcp_zone}"
cluster_name = "${var.consul_server_cluster_name}"
cluster_tag_name = "${var.consul_server_cluster_name}"
cluster_size = "${var.consul_server_cluster_size}"
gcp_project_id = var.gcp_project
gcp_region = var.gcp_region

source_image = "${var.consul_server_source_image}"
machine_type = "${var.consul_server_machine_type}"
cluster_name = var.consul_server_cluster_name
cluster_tag_name = var.consul_server_cluster_name
cluster_size = var.consul_server_cluster_size

startup_script = "${data.template_file.startup_script_consul.rendered}"
source_image = var.consul_server_source_image
machine_type = var.consul_server_machine_type

startup_script = data.template_file.startup_script_consul.rendered

# WARNING!
# In a production setting, we strongly recommend only launching a Consul Server cluster as private nodes.
# Note that the only way to reach private nodes via SSH is to first SSH into another node that is not private.
assign_public_ip_addresses = true

allowed_inbound_tags_dns = ["${var.nomad_server_cluster_name}", "${var.nomad_client_cluster_name}"]
allowed_inbound_tags_http_api = ["${var.nomad_server_cluster_name}", "${var.nomad_client_cluster_name}"]
allowed_inbound_tags_dns = [var.nomad_server_cluster_name, var.nomad_client_cluster_name]
allowed_inbound_tags_http_api = [var.nomad_server_cluster_name, var.nomad_client_cluster_name]
}

# This Startup Script will run at boot configure and start Consul on the Consul Server cluster nodes
data "template_file" "startup_script_consul" {
template = "${file("${path.module}/startup-script-consul-server.sh")}"
template = file("${path.module}/startup-script-consul-server.sh")

vars {
consul_server_cluster_tag_name = "${var.consul_server_cluster_name}"
vars = {
consul_server_cluster_tag_name = var.consul_server_cluster_name
}
}

Expand All @@ -112,15 +114,15 @@ module "nomad_clients" {
# source = "git::[email protected]:hashicorp/terraform-google-nomad.git//modules/nomad-cluster?ref=v0.0.1"
source = "../../modules/nomad-cluster"

gcp_zone = "${var.gcp_zone}"
gcp_region = var.gcp_region

cluster_name = "${var.nomad_client_cluster_name}"
cluster_size = "${var.nomad_client_cluster_size}"
cluster_tag_name = "${var.nomad_client_cluster_name}"
machine_type = "${var.nomad_client_machine_type}"
cluster_name = var.nomad_client_cluster_name
cluster_size = var.nomad_client_cluster_size
cluster_tag_name = var.nomad_client_cluster_name
machine_type = var.nomad_client_machine_type

source_image = "${var.nomad_client_source_image}"
startup_script = "${data.template_file.startup_script_nomad_client.rendered}"
source_image = var.nomad_client_source_image
startup_script = data.template_file.startup_script_nomad_client.rendered

# We strongly recommend setting this to "false" in a production setting. Your Nomad cluster has no reason to be
# publicly accessible! However, for testing and demo purposes, it is more convenient to launch a publicly accessible
Expand All @@ -129,17 +131,16 @@ module "nomad_clients" {

# These inbound clients need only receive requests from Nomad Server and Consul
allowed_inbound_cidr_blocks_http = []
allowed_inbound_tags_http = ["${var.nomad_server_cluster_name}", "${var.consul_server_cluster_name}"]
allowed_inbound_tags_rpc = ["${var.nomad_server_cluster_name}"]
allowed_inbound_tags_serf = ["${var.nomad_server_cluster_name}"]
allowed_inbound_tags_http = [var.nomad_server_cluster_name, var.consul_server_cluster_name]
allowed_inbound_tags_rpc = [var.nomad_server_cluster_name]
allowed_inbound_tags_serf = [var.nomad_server_cluster_name]
}

# Render the Startup Script that will configure and run both Consul and Nomad in client mode.
data "template_file" "startup_script_nomad_client" {
template = "${file("${path.module}/startup-script-nomad-client.sh")}"
template = file("${path.module}/startup-script-nomad-client.sh")

vars {
consul_server_cluster_tag_name = "${var.consul_server_cluster_name}"
vars = {
consul_server_cluster_tag_name = var.consul_server_cluster_name
}
}

40 changes: 24 additions & 16 deletions examples/nomad-consul-separate-cluster/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,51 +1,59 @@
output "gcp_project" {
value = "${var.gcp_project}"
value = var.gcp_project
}

output "gcp_zone" {
value = "${var.gcp_zone}"
output "gcp_region" {
value = var.gcp_region
}

output "nomad_server_cluster_size" {
value = "${var.nomad_server_cluster_size}"
value = var.nomad_server_cluster_size
}

output "nomad_client_cluster_size" {
value = "${var.nomad_client_cluster_size}"
value = var.nomad_client_cluster_size
}

output "nomad_server_cluster_tag_name" {
value = "${var.nomad_server_cluster_name}"
value = var.nomad_server_cluster_name
}

output "nomad_client_cluster_tag_name" {
value = "${var.nomad_client_cluster_name}"
value = var.nomad_client_cluster_name
}

output "consul_server_cluster_tag_name" {
value = "${var.consul_server_cluster_name}"
value = var.consul_server_cluster_name
}

output "nomad_server_instance_group_id" {
value = "${module.nomad_servers.instance_group_id}"
value = module.nomad_servers.instance_group_id
}

output "nomad_server_instance_group_name" {
value = module.nomad_servers.instance_group_name
}

output "nomad_server_instance_group_url" {
value = "${module.nomad_servers.instance_group_url}"
value = module.nomad_servers.instance_group_url
}

output "nomad_client_instance_group_id" {
value = "${module.nomad_clients.instance_group_id}"
value = module.nomad_clients.instance_group_id
}

output "nomad_client_instance_group_name" {
value = module.nomad_clients.instance_group_name
}

output "nomad_client_instance_group_url" {
value = "${module.nomad_clients.instance_group_url}"
value = module.nomad_clients.instance_group_url
}

output "consul_server_instance_group_id" {
value = "${module.consul_cluster.instance_group_name}"
output "consul_server_instance_group_name" {
value = module.consul_cluster.instance_group_name
}

output "consul_server_instance_group_url" {
value = "${module.consul_cluster.instance_group_url}"
}
value = module.consul_cluster.instance_group_url
}
Loading

0 comments on commit ea3cc2c

Please sign in to comment.