Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades to work with Terraform v0.12.20 #12

Closed
wants to merge 13 commits into from
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

74 changes: 74 additions & 0 deletions codefresh/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: '1.0'

stages:
- Prepare
- Test

steps:
wait:
title: Wait
stage: Prepare
image: codefresh/cli:latest
commands:
- codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
retry:
maxAttempts: 10
delay: 20
exponentialFactor: 1.1

main_clone:
title: "Clone repository"
type: git-clone
stage: Prepare
description: "Initialize"
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
git: CF-default
revision: ${{CF_REVISION}}

clean_init:
title: Prepare build-harness and test-harness
image: ${{TEST_IMAGE}}
stage: Prepare
commands:
- cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
- make init
- git -C build-harness checkout master
- make -C test/ clean init TEST_HARNESS_BRANCH=master
- make -C test/src clean init
- find . -type d -name '.terraform' | xargs rm -rf
- find . -type f -name 'terraform.tfstate*' -exec rm -f {} \;

test:
type: "parallel"
title: "Run tests"
description: "Run all tests in parallel"
stage: Test
steps:
test_readme_lint:
title: "Test README.md updated"
stage: "Test"
image: ${{TEST_IMAGE}}
description: Test "readme/lint"
commands:
- make readme/lint

test_module:
title: Test module with bats
image: ${{TEST_IMAGE}}
stage: Test
commands:
- make -C test/ module

test_examples_complete:
title: Test "examples/complete" with bats
image: ${{TEST_IMAGE}}
stage: Test
commands:
- make -C test/ examples/complete

test_examples_complete_terratest:
title: Test "examples/complete" with terratest
image: ${{TEST_IMAGE}}
stage: Test
commands:
- make -C test/src
4 changes: 2 additions & 2 deletions example/main.tf → examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module "kms_key" {
}

module "store" {
source = "../"
source = "../../"

tags = {
ManagedBy = "Terraform"
Expand Down Expand Up @@ -43,5 +43,5 @@ module "store" {
},
]

kms_arn = "${module.kms_key.key_arn}"
kms_arn = module.kms_key.key_arn
}
6 changes: 3 additions & 3 deletions example/outputs.tf → examples/complete/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
output "parameter_names" {
description = "List of key names"
value = "${module.store.names}"
value = module.store.names
}

output "parameter_values" {
description = "List of values"
value = "${module.store.values}"
value = module.store.values
}

output "map" {
description = "Map of parameters"
value = "${module.store.map}"
value = module.store.map
}
File renamed without changes.
27 changes: 16 additions & 11 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
data "aws_ssm_parameter" "read" {
count = "${var.enabled == "true" ? length(var.parameter_read) : 0}"
name = "${element(var.parameter_read, count.index)}"
count = var.enabled ? length(var.parameter_read) : 0
name = element(var.parameter_read, count.index)
}

resource "aws_ssm_parameter" "default" {
count = "${var.enabled == "true" ? length(var.parameter_write) : 0}"
name = "${lookup(var.parameter_write[count.index], "name")}"
description = "${lookup(var.parameter_write[count.index], "description", lookup(var.parameter_write[count.index], "name"))}"
type = "${lookup(var.parameter_write[count.index], "type", "SecureString")}"
key_id = "${lookup(var.parameter_write[count.index], "type", "SecureString") == "SecureString" && length(var.kms_arn) > 0 ? var.kms_arn : ""}"
value = "${lookup(var.parameter_write[count.index], "value")}"
overwrite = "${lookup(var.parameter_write[count.index], "overwrite", "false")}"
allowed_pattern = "${lookup(var.parameter_write[count.index], "allowed_pattern", "")}"
tags = "${var.tags}"
count = var.enabled ? length(var.parameter_write) : 0
name = tolist(var.parameter_write)[count.index]["name"]
description = lookup(
tolist(var.parameter_write)[count.index],
"description",
tolist(var.parameter_write)[count.index]["name"],
)
type = lookup(tolist(var.parameter_write)[count.index], "type", "SecureString")
key_id = lookup(tolist(var.parameter_write)[count.index], "type", "SecureString") == "SecureString" && length(var.kms_arn) > 0 ? var.kms_arn : ""
value = tolist(var.parameter_write)[count.index]["value"]
overwrite = lookup(tolist(var.parameter_write)[count.index], "overwrite", "false")
allowed_pattern = lookup(tolist(var.parameter_write)[count.index], "allowed_pattern", "")
tags = var.tags
}

33 changes: 28 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
# Splitting and joining, and then compacting a list to get a normalised list
locals {
name_list = "${compact(concat(split("${var.split_delimiter}",join("${var.split_delimiter}", aws_ssm_parameter.default.*.name)), split("${var.split_delimiter}",join("${var.split_delimiter}", data.aws_ssm_parameter.read.*.name))))}"
value_list = "${compact(concat(split("${var.split_delimiter}",join("${var.split_delimiter}", aws_ssm_parameter.default.*.value)), split("${var.split_delimiter}",join("${var.split_delimiter}", data.aws_ssm_parameter.read.*.value))))}"
name_list = compact(
concat(
split(
var.split_delimiter,
join(var.split_delimiter, aws_ssm_parameter.default.*.name),
),
split(
var.split_delimiter,
join(var.split_delimiter, data.aws_ssm_parameter.read.*.name),
),
),
)
value_list = compact(
concat(
split(
var.split_delimiter,
join(var.split_delimiter, aws_ssm_parameter.default.*.value),
),
split(
var.split_delimiter,
join(var.split_delimiter, data.aws_ssm_parameter.read.*.value),
),
),
)
}

output "names" {
value = "${local.name_list}"
value = local.name_list
description = "A list of all of the parameter names"
}

output "values" {
description = "A list of all of the parameter values"
value = "${local.value_list}"
value = local.value_list
}

output "map" {
description = "A map of the names and values created"
value = "${zipmap(local.name_list, local.value_list)}"
value = zipmap(local.name_list, local.value_list)
}

1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.test-harness
44 changes: 44 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
SHELL := /bin/bash
TEST_HARNESS ?= https://github.com/cloudposse/test-harness.git
TEST_HARNESS_BRANCH ?= master
TEST_HARNESS_PATH = $(realpath .test-harness)
BATS_ARGS ?= --tap
BATS_LOG ?= test.log

# Define a macro to run the tests
define RUN_TESTS
@echo "Running tests in $(1)"
@cd $(1) && bats $(BATS_ARGS) $(addsuffix .bats,$(addprefix $(TEST_HARNESS_PATH)/test/terraform/,$(TESTS)))
endef

default: all

-include Makefile.*

## Provision the test-harnesss
.test-harness:
[ -d $@ ] || git clone --depth=1 -b $(TEST_HARNESS_BRANCH) $(TEST_HARNESS) $@

## Initialize the tests
init: .test-harness

## Install all dependencies (OS specific)
deps::
@exit 0

## Clean up the test harness
clean:
[ "$(TEST_HARNESS_PATH)" == "/" ] || rm -rf $(TEST_HARNESS_PATH)

## Run all tests
all: module examples/complete

## Run basic sanity checks against the module itself
module: export TESTS ?= installed lint get-modules module-pinning get-plugins provider-pinning validate terraform-docs input-descriptions output-descriptions
module: deps
$(call RUN_TESTS, ../)

## Run tests against example
examples/complete: export TESTS ?= installed lint get-modules get-plugins validate
examples/complete: deps
$(call RUN_TESTS, ../$@)
5 changes: 5 additions & 0 deletions test/Makefile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ifneq (,$(wildcard /sbin/apk))
## Install all dependencies for alpine
deps:: init
@apk add --update terraform-docs@cloudposse json2hcl@cloudposse
endif
2 changes: 2 additions & 0 deletions test/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gopath
vendor/
92 changes: 92 additions & 0 deletions test/src/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/src/Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.2"

[prune]
go-tests = true
unused-packages = true
Loading