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

Commit

Permalink
Merge pull request #81 from hashicorp/tf13
Browse files Browse the repository at this point in the history
Update repo to work with TF 0.13
robmorgan authored Oct 26, 2020
2 parents e21690f + e863cd5 commit 9b05609
Showing 18 changed files with 651 additions and 836 deletions.
73 changes: 15 additions & 58 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,30 @@
workspace_root: &workspace_root /go/src/github.com/hashicorp/terraform-aws-nomad
defaults: &defaults
working_directory: *workspace_root
docker:
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:latest
environment:
GRUNTWORK_INSTALLER_VERSION: v0.0.21
TERRATEST_LOG_PARSER_VERSION: v0.17.4
MODULE_CI_VERSION: v0.13.15
TERRAFORM_VERSION: 0.12.2
TERRAGRUNT_VERSION: NONE
PACKER_VERSION: 1.4.1
GOLANG_VERSION: 1.11

install_gruntwork_utils: &install_gruntwork_utils
name: install gruntwork utils
command: |
echo 'export PATH=$HOME/terraform:$HOME/packer:$PATH' >> $BASH_ENV
curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}"
sudo -E gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "${MODULE_CI_VERSION}"
sudo -E gruntwork-install --binary-name "docs-generator" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.13.11"
configure-environment-for-gruntwork-module \
--terraform-version ${TERRAFORM_VERSION} \
--terragrunt-version ${TERRAGRUNT_VERSION} \
--packer-version ${PACKER_VERSION} \
--use-go-dep \
--circle-ci-2 \
--go-version ${GOLANG_VERSION} \
--go-src-path test
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:tf13.4

version: 2
jobs:
validate_terraform:
docker:
- image: hashicorp/terraform
steps:
- checkout
- run:
name: Validate Terraform Formatting
command: "[ -z \"$(terraform fmt -write=false)\" ] || { terraform fmt -write=false -diff; exit 1; }"

test:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: *workspace_root

- restore_cache:
keys:
- dep-v2-{{ checksum "test/Gopkg.lock" }}

- run:
<<: *install_gruntwork_utils

- save_cache:
key: dep-v2-{{ checksum "test/Gopkg.lock" }}
paths:
- /go/src/github.com/hashicorp/terraform-aws-nomad/test/vendor

- persist_to_workspace:
root: *workspace_root
paths: test/vendor
# Fail the build if the pre-commit hooks don't pass. Note: if you run $ pre-commit install locally within this repo, these hooks will
# execute automatically every time before you commit, ensuring the build never fails at this step!
name: run pre-commit hooks
command: |
pip install pre-commit==1.21.0 cfgv==2.0.1
pre-commit install
pre-commit run --all-files
- run:
name: create log directory
command: mkdir -p /tmp/logs

- run:
name: run tests
command: run-go-tests --circle-ci-2 --path test --timeout 2h | tee /tmp/logs/all.log
command: run-go-tests --path test --timeout 2h | tee /tmp/logs/all.log
no_output_timeout: 3600s

- store_artifacts:
@@ -81,15 +37,16 @@ jobs:
steps:
- checkout
- run: echo 'export PATH=$HOME/terraform:$HOME/packer:$PATH' >> $BASH_ENV
- run: sudo -E gruntwork-install --module-name "aws-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.12.2"
- run: sudo -E gruntwork-install --module-name "git-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.12.2"
- run: sudo -E gruntwork-install --module-name "build-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.12.2"
- run: sudo -E gruntwork-install --module-name "aws-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.29.0"
- run: sudo -E gruntwork-install --module-name "git-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.29.0"
- run: sudo -E gruntwork-install --module-name "build-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.29.0"

# We generally only want to build AMIs on new releases, but when we are setting up AMIs in a new account for the
# first time, we want to build the AMIs but NOT run automated tests, since those tests will fail without an existing
# AMI already in the AWS Account.
- run: /go/src/github.com/hashicorp/terraform-aws-nomad/_ci/publish-amis.sh "ubuntu16-ami"
- run: /go/src/github.com/hashicorp/terraform-aws-nomad/_ci/publish-amis.sh "amazon-linux-ami"
- run: _ci/publish-amis.sh "ubuntu16-ami"
- run: _ci/publish-amis.sh "ubuntu18-ami"
- run: _ci/publish-amis.sh "amazon-linux-2-ami"

workflows:
version: 2
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.10
hooks:
- id: terraform-fmt
- id: gofmt
21 changes: 3 additions & 18 deletions _ci/publish-amis.sh
Original file line number Diff line number Diff line change
@@ -7,13 +7,10 @@

set -e

readonly PACKER_TEMPLATE_PATH="/home/ubuntu/$CIRCLE_PROJECT_REPONAME/examples/nomad-consul-ami/nomad-consul.json"
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly PACKER_TEMPLATE_PATH="$SCRIPT_DIR/../examples/nomad-consul-ami/nomad-consul.json"
readonly PACKER_TEMPLATE_DEFAULT_REGION="us-east-1"
readonly AMI_PROPERTIES_FILE="/tmp/ami.properties"
readonly AMI_LIST_MARKDOWN_DIR="/home/ubuntu/$CIRCLE_PROJECT_REPONAME/_docs"
readonly GIT_COMMIT_MESSAGE="Add latest AMI IDs."
readonly GIT_USER_NAME="gruntwork-ci"
readonly GIT_USER_EMAIL="ci@gruntwork.io"

# In CircleCI, every build populates the branch name in CIRCLE_BRANCH except builds triggered by a new tag, for which
# the CIRCLE_BRANCH env var is empty. We assume tags are only issued against the master branch.
@@ -50,16 +47,4 @@ source "$AMI_PROPERTIES_FILE"
publish-ami \
--all-regions \
--source-ami-id "$ARTIFACT_ID" \
--source-ami-region "$PACKER_TEMPLATE_DEFAULT_REGION" \
--output-markdown > "$AMI_LIST_MARKDOWN_DIR/$PACKER_BUILD_NAME-list.md" \
--markdown-title-text "$PACKER_BUILD_NAME: Latest Public AMIs" \
--markdown-description-text "**WARNING! Do NOT use these AMIs in a production setting.** The AMIs are meant only to make initial experiments with this module more convenient."

# Git add, commit, and push the newly created AMI IDs as a markdown doc to the repo
git-add-commit-push \
--path "$AMI_LIST_MARKDOWN_DIR/$PACKER_BUILD_NAME-list.md" \
--message "$GIT_COMMIT_MESSAGE" \
--user-name "$GIT_USER_NAME" \
--user-email "$GIT_USER_EMAIL" \
--git-push-behavior "current" \
--branch-name "$BRANCH_NAME"
--source-ami-region "$PACKER_TEMPLATE_DEFAULT_REGION"
21 changes: 0 additions & 21 deletions _docs/amazon-linux-ami-list.md

This file was deleted.

21 changes: 0 additions & 21 deletions _docs/ubuntu16-ami-list.md

This file was deleted.

2 changes: 1 addition & 1 deletion examples/nomad-consul-ami/nomad-consul-docker.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"variables": {
"aws_region": "us-east-1",
"nomad_version": "0.9.1",
"consul_module_version": "v0.7.4",
"consul_module_version": "v0.8.0",
"consul_version": "1.5.1",
"ami_name_prefix": "nomad-consul"
},
12 changes: 8 additions & 4 deletions examples/nomad-consul-ami/nomad-consul.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"variables": {
"aws_region": "us-east-1",
"nomad_version": "0.9.1",
"consul_module_version": "v0.7.4",
"consul_module_version": "v0.8.0",
"consul_version": "1.5.1",
"ami_name_prefix": "nomad-consul"
},
@@ -96,10 +96,14 @@
]
},
{
"type": "file",
"source": "{{template_dir}}/../../../terraform-aws-nomad",
"destination": "/tmp",
"type": "shell",
"inline": ["mkdir -p /tmp/terraform-aws-nomad"],
"pause_before": "30s"
},
{
"type": "file",
"source": "{{template_dir}}/../../",
"destination": "/tmp/terraform-aws-nomad"
},
{
"type": "shell",
12 changes: 7 additions & 5 deletions examples/nomad-consul-separate-cluster/main.tf
Original file line number Diff line number Diff line change
@@ -14,10 +14,12 @@

# ----------------------------------------------------------------------------------------------------------------------
# REQUIRE A SPECIFIC TERRAFORM VERSION OR HIGHER
# This module has been updated with 0.12 syntax, which means it is no longer compatible with any versions below 0.12.
# ----------------------------------------------------------------------------------------------------------------------
terraform {
required_version = ">= 0.12"
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
# forwards compatible with 0.13.x code.
required_version = ">= 0.12.26"
}

# ---------------------------------------------------------------------------------------------------------------------
@@ -95,7 +97,7 @@ module "nomad_servers" {
# ---------------------------------------------------------------------------------------------------------------------

module "consul_iam_policies_servers" {
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-iam-policies?ref=v0.7.7"
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-iam-policies?ref=v0.8.0"

iam_role_id = module.nomad_servers.iam_role_id
}
@@ -120,7 +122,7 @@ data "template_file" "user_data_nomad_server" {
# ---------------------------------------------------------------------------------------------------------------------

module "consul_servers" {
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-cluster?ref=v0.7.7"
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-cluster?ref=v0.8.0"

cluster_name = "${var.consul_cluster_name}-server"
cluster_size = var.num_consul_servers
@@ -206,7 +208,7 @@ module "nomad_clients" {
# ---------------------------------------------------------------------------------------------------------------------

module "consul_iam_policies_clients" {
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-iam-policies?ref=v0.7.7"
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-iam-policies?ref=v0.8.0"

iam_role_id = module.nomad_clients.iam_role_id
}
10 changes: 6 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -10,10 +10,12 @@

# ----------------------------------------------------------------------------------------------------------------------
# REQUIRE A SPECIFIC TERRAFORM VERSION OR HIGHER
# This module has been updated with 0.12 syntax, which means it is no longer compatible with any versions below 0.12.
# ----------------------------------------------------------------------------------------------------------------------
terraform {
required_version = ">= 0.12"
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
# forwards compatible with 0.13.x code.
required_version = ">= 0.12.26"
}

# ---------------------------------------------------------------------------------------------------------------------
@@ -58,7 +60,7 @@ data "aws_ami" "nomad_consul" {
# ---------------------------------------------------------------------------------------------------------------------

module "servers" {
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-cluster?ref=v0.7.7"
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-cluster?ref=v0.8.0"

cluster_name = "${var.cluster_name}-server"
cluster_size = var.num_servers
@@ -177,7 +179,7 @@ module "clients" {
# ---------------------------------------------------------------------------------------------------------------------

module "consul_iam_policies" {
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-iam-policies?ref=v0.7.7"
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-iam-policies?ref=v0.8.0"

iam_role_id = module.clients.iam_role_id
}
10 changes: 6 additions & 4 deletions modules/nomad-cluster/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# ----------------------------------------------------------------------------------------------------------------------
# REQUIRE A SPECIFIC TERRAFORM VERSION OR HIGHER
# This module has been updated with 0.12 syntax, which means it is no longer compatible with any versions below 0.12.
# ----------------------------------------------------------------------------------------------------------------------
terraform {
required_version = ">= 0.12"
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
# forwards compatible with 0.13.x code.
required_version = ">= 0.12.26"
}

# ---------------------------------------------------------------------------------------------------------------------
@@ -33,7 +35,7 @@ resource "aws_autoscaling_group" "autoscaling_group" {
value = var.cluster_name
propagate_at_launch = true
}

tag {
key = var.cluster_tag_key
value = var.cluster_tag_value
@@ -49,7 +51,7 @@ resource "aws_autoscaling_group" "autoscaling_group" {
propagate_at_launch = tag.value["propagate_at_launch"]
}
}

lifecycle {
# As of AWS Provider 3.x, inline load_balancers and target_group_arns
# in an aws_autoscaling_group take precedence over attachment resources.
2 changes: 1 addition & 1 deletion modules/nomad-cluster/variables.tf
Original file line number Diff line number Diff line change
@@ -199,7 +199,7 @@ variable "tags" {
propagate_at_launch = bool
}))
default = []

}

variable "ebs_block_devices" {
2 changes: 1 addition & 1 deletion modules/nomad-security-group-rules/README.md
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ servers that have both Nomad and Consul on each node:

```hcl
module "consul_servers" {
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-cluster?ref=v0.7.7"
source = "github.com/hashicorp/terraform-aws-consul//modules/consul-cluster?ref=v0.8.0"
# This AMI has both Nomad and Consul installed
ami_id = "ami-1234abcd"
6 changes: 4 additions & 2 deletions modules/nomad-security-group-rules/main.tf
Original file line number Diff line number Diff line change
@@ -4,10 +4,12 @@

# ----------------------------------------------------------------------------------------------------------------------
# REQUIRE A SPECIFIC TERRAFORM VERSION OR HIGHER
# This module has been updated with 0.12 syntax, which means it is no longer compatible with any versions below 0.12.
# ----------------------------------------------------------------------------------------------------------------------
terraform {
required_version = ">= 0.12"
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
# forwards compatible with 0.13.x code.
required_version = ">= 0.12.26"
}

resource "aws_security_group_rule" "allow_http_inbound" {
Loading

0 comments on commit 9b05609

Please sign in to comment.