From b590bd80f6a61fb3113a4683613b58a3a6fc2ede Mon Sep 17 00:00:00 2001 From: Soren Martius Date: Sun, 25 Jul 2021 17:16:01 +0100 Subject: [PATCH 1/2] feat: add support for Terraform v1.x --- CHANGELOG.md | 4 ++ Makefile | 75 ++++++++++++++++++++--------- README.md | 4 +- examples/README.md | 2 +- examples/secure-s3-bucket/README.md | 2 +- test/README.md | 2 +- versions.tf | 2 +- 7 files changed, 61 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5a60d4..2b18b76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add support for Terraform `v1.x` + ## [0.5.0] ### Added diff --git a/Makefile b/Makefile index 34f15c9..844923b 100644 --- a/Makefile +++ b/Makefile @@ -1,49 +1,67 @@ # Set default shell to bash SHELL := /bin/bash -o pipefail -BUILD_TOOLS_VERSION ?= v0.11.0 +BUILD_TOOLS_VERSION ?= v0.12.0 BUILD_TOOLS_DOCKER_REPO ?= mineiros/build-tools BUILD_TOOLS_DOCKER_IMAGE ?= ${BUILD_TOOLS_DOCKER_REPO}:${BUILD_TOOLS_VERSION} -# If running in CI (e.g. GitHub Actions) -# https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables +# Some CI providers such as GitHub Actions, CircleCI, and TravisCI are setting +# the CI environment variable to a non-empty value by default to indicate that +# the current workflow is running in a Continuous Integration environment. # -# To disable TF_IN_AUTOMATION in CI set it to empty +# If TF_IN_AUTOMATION is set to any non-empty value, Terraform adjusts its +# output to avoid suggesting specific commands to run next. # https://www.terraform.io/docs/commands/environment-variables.html#tf_in_automation # # We are using GNU style quiet commands to disable set V to non-empty e.g. V=1 # https://www.gnu.org/software/automake/manual/html_node/Debugging-Make-Rules.html # ifdef CI - TF_IN_AUTOMATION ?= yes - export TF_IN_AUTOMATION + TF_IN_AUTOMATION ?= yes + export TF_IN_AUTOMATION - V ?= 1 + V ?= 1 endif ifndef NOCOLOR - GREEN := $(shell tput -Txterm setaf 2) - YELLOW := $(shell tput -Txterm setaf 3) - WHITE := $(shell tput -Txterm setaf 7) - RESET := $(shell tput -Txterm sgr0) + GREEN := $(shell tput -Txterm setaf 2) + YELLOW := $(shell tput -Txterm setaf 3) + WHITE := $(shell tput -Txterm setaf 7) + RESET := $(shell tput -Txterm sgr0) endif -# We are creating docker volumes for /go and /terraform that are unique per -# repository to reuse dependencies between different docker run commands. -VOLUME_PREFIX ?= mineiros_build_tools -VOLUME_SUFFIX ?= $(notdir $(shell git rev-parse --show-toplevel || "build")) -DOCKER_RUN_FLAGS += -v ${VOLUME_PREFIX}-terraform-${VOLUME_SUFFIX}:/terraform -DOCKER_RUN_FLAGS += -v ${VOLUME_PREFIX}-go-${VOLUME_SUFFIX}:/go -DOCKER_RUN_FLAGS += -v ${PWD}:/build +GIT_TOPLEVEl = $(shell git rev-parse --show-toplevel) + +# Generic docker run flags +DOCKER_RUN_FLAGS += -v ${GIT_TOPLEVEl}:/build DOCKER_RUN_FLAGS += --rm DOCKER_RUN_FLAGS += -e TF_IN_AUTOMATION -DOCKER_AWS_FLAGS += -e AWS_ACCESS_KEY_ID -DOCKER_AWS_FLAGS += -e AWS_SECRET_ACCESS_KEY -DOCKER_AWS_FLAGS += -e AWS_SESSION_TOKEN +# If SSH_AUTH_SOCK is set, we forward the SSH agent of the host system into +# the docker container. This is useful when working with private repositories +# and dependencies that might need to be cloned inside the container (e.g. +# private Terraform modules). +ifdef SSH_AUTH_SOCK + DOCKER_SSH_FLAGS += -e SSH_AUTH_SOCK=/ssh-agent + DOCKER_SSH_FLAGS += -v ${SSH_AUTH_SOCK}:/ssh-agent +endif -DOCKER_FLAGS += ${DOCKER_RUN_FLAGS} -DOCKER_RUN_CMD = docker run ${DOCKER_FLAGS} ${BUILD_TOOLS_DOCKER_IMAGE} +# If AWS_ACCESS_KEY_ID is defined, we are likely running inside an AWS provider +# module. To enable AWS authentication inside the docker container, we inject +# the relevant environment variables. +ifdef AWS_ACCESS_KEY_ID + DOCKER_AWS_FLAGS += -e AWS_ACCESS_KEY_ID + DOCKER_AWS_FLAGS += -e AWS_SECRET_ACCESS_KEY + DOCKER_AWS_FLAGS += -e AWS_SESSION_TOKEN +endif + +# If GITHUB_OWNER is defined, we are likely running inside a GitHub provider +# module. To enable GitHub authentication inside the docker container, +# we inject the relevant environment variables. +ifdef GITHUB_OWNER + DOCKER_GITHUB_FLAGS += -e GITHUB_TOKEN + DOCKER_GITHUB_FLAGS += -e GITHUB_OWNER +endif .PHONY: default default: help @@ -56,12 +74,16 @@ template/adjust: ## Run pre-commit hooks inside a build-tools docker container. .PHONY: test/pre-commit +test/pre-commit: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS} test/pre-commit: $(call docker-run,pre-commit run -a) ## Run all Go tests inside a build-tools docker container. This is complementary to running 'go test ./test/...'. .PHONY: test/unit-tests +test/unit-tests: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS} +test/unit-tests: DOCKER_FLAGS += ${DOCKER_GITHUB_FLAGS} test/unit-tests: DOCKER_FLAGS += ${DOCKER_AWS_FLAGS} +test/unit-tests: DOCKER_FLAGS += -e TF_DATA_DIR=.terratest test/unit-tests: TEST ?= "TestUnit" test/unit-tests: @echo "${YELLOW}[TEST] ${GREEN}Start Running Go Tests in Docker Container.${RESET}" @@ -71,9 +93,11 @@ test/unit-tests: .PHONY: clean clean: $(call rm-command,.terraform) + $(call rm-command,.terraform.lock.hcl) $(call rm-command,*.tfplan) $(call rm-command,*/*/.terraform) $(call rm-command,*/*/*.tfplan) + $(call rm-command,*/*/.terraform.lock.hcl) ## Display help for all targets .PHONY: help @@ -88,7 +112,10 @@ help: } \ { lastLine = $$0 }' $(MAKEFILE_LIST) -# define helper functions +# Define helper functions +DOCKER_FLAGS += ${DOCKER_RUN_FLAGS} +DOCKER_RUN_CMD = docker run ${DOCKER_FLAGS} ${BUILD_TOOLS_DOCKER_IMAGE} + quiet-command = $(if ${V},${1},$(if ${2},@echo ${2} && ${1}, @${1})) docker-run = $(call quiet-command,${DOCKER_RUN_CMD} ${1} | cat,"${YELLOW}[DOCKER RUN] ${GREEN}${1}${RESET}") go-test = $(call quiet-command,${DOCKER_RUN_CMD} go test -v -count 1 -timeout 45m -parallel 128 ${1} | cat,"${YELLOW}[TEST] ${GREEN}${1}${RESET}") diff --git a/README.md b/README.md index 515ecce..0c4cf88 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A [Terraform] base module for creating a secure [AWS S3-Bucket]. -***This module supports Terraform v0.15, v0.14, v0.13 as well as v0.12.20 and above +***This module supports Terraform v1.x, v0.15, v0.14, v0.13 as well as v0.12.20 and above and is compatible with the terraform AWS provider v3 as well as v2.0 and above.*** - [Module Features](#module-features) @@ -607,7 +607,7 @@ Copyright © 2020 [Mineiros GmbH][homepage] [badge-build]: https://github.com/mineiros-io/terraform-aws-s3-bucket/workflows/CI/CD%20Pipeline/badge.svg [badge-semver]: https://img.shields.io/github/v/tag/mineiros-io/terraform-aws-s3-bucket.svg?label=latest&sort=semver [badge-license]: https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg -[badge-terraform]: https://img.shields.io/badge/terraform-0.15%20|0.14%20|%200.13%20|%200.12.20+-623CE4.svg?logo=terraform +[badge-terraform]: https://img.shields.io/badge/terraform-1.x%20|%200.15%20|%200.14%20|%200.13%20|%200.12.20+-623CE4.svg?logo=terraform [badge-slack]: https://img.shields.io/badge/slack-@mineiros--community-f32752.svg?logo=slack [badge-tf-aws]: https://img.shields.io/badge/AWS-3%20and%202.0+-F8991D.svg?logo=terraform diff --git a/examples/README.md b/examples/README.md index b82be42..cdc802e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -16,7 +16,7 @@ [homepage]: https://mineiros.io/?ref=terraform-aws-s3-bucket [badge-license]: https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg -[badge-terraform]: https://img.shields.io/badge/terraform-0.13%20and%200.12.20+-623CE4.svg?logo=terraform +[badge-terraform]: https://img.shields.io/badge/terraform-1.x%20|%200.15%20|%200.14%20|%200.13%20|%200.12.20+-623CE4.svg?logo=terraform [badge-slack]: https://img.shields.io/badge/slack-@mineiros--community-f32752.svg?logo=slack [badge-semver]: https://img.shields.io/github/v/tag/mineiros-io/terraform-aws-s3-bucket.svg?label=latest&sort=semver diff --git a/examples/secure-s3-bucket/README.md b/examples/secure-s3-bucket/README.md index ebeacfd..23ce8c0 100644 --- a/examples/secure-s3-bucket/README.md +++ b/examples/secure-s3-bucket/README.md @@ -102,7 +102,7 @@ Run `terraform destroy -refresh=false -auto-approve` to destroy all resources ag [homepage]: https://mineiros.io/?ref=terraform-aws-s3-bucket [badge-license]: https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg -[badge-terraform]: https://img.shields.io/badge/terraform-0.13%20and%200.12.20+-623CE4.svg?logo=terraform +[badge-terraform]: https://img.shields.io/badge/terraform-1.x%20|%200.15%20|%200.14%20|%200.13%20|%200.12.20+-623CE4.svg?logo=terraform [badge-slack]: https://img.shields.io/badge/slack-@mineiros--community-f32752.svg?logo=slack [badge-semver]: https://img.shields.io/github/v/tag/mineiros-io/terraform-aws-s3-bucket.svg?label=latest&sort=semver diff --git a/test/README.md b/test/README.md index b36fb35..1605e50 100644 --- a/test/README.md +++ b/test/README.md @@ -73,7 +73,7 @@ Alternatively, you can also run the tests without Docker. [Go]: https://golang.org/ [Terraform]: https://www.terraform.io/downloads.html [badge-license]: https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg -[badge-terraform]: https://img.shields.io/badge/terraform-0.13%20and%200.12.20+-623CE4.svg?logo=terraform +[badge-terraform]: https://img.shields.io/badge/terraform-1.x%20|%200.15%20|%200.14%20|%200.13%20|%200.12.20+-623CE4.svg?logo=terraform [badge-slack]: https://img.shields.io/badge/slack-@mineiros--community-f32752.svg?logo=slack [releases-terraform]: https://github.com/hashicorp/terraform/releases diff --git a/versions.tf b/versions.tf index d6e3d2f..b160fc6 100644 --- a/versions.tf +++ b/versions.tf @@ -3,7 +3,7 @@ # --------------------------------------------------------------------------------------------------------------------- terraform { - required_version = ">= 0.12.20, < 0.16" + required_version = ">= 0.12.20, < 2.0" required_providers { aws = ">= 2.51, < 4.0" From 8730532006cc7a266c59fde15a216fd83cc8ba53 Mon Sep 17 00:00:00 2001 From: Soren Martius Date: Sun, 25 Jul 2021 17:20:49 +0100 Subject: [PATCH 2/2] chore: prepare v0.6.0 release --- CHANGELOG.md | 7 +++++-- README.md | 2 +- examples/secure-s3-bucket/README.md | 4 ++-- examples/secure-s3-bucket/main.tf | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b18b76..f8e4754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.6.0] + ### Added - Add support for Terraform `v1.x` @@ -139,11 +141,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 -[unreleased]: https://github.com/mineiros-io/terraform-aws-s3-bucket/compare/v0.5.0...HEAD -[0.5.0]: https://github.com/mineiros-io/terraform-aws-s3-bucket/compare/v0.4.2...v0.5.0 +[unreleased]: https://github.com/mineiros-io/terraform-aws-s3-bucket/compare/v0.6.0...HEAD +[0.6.0]: https://github.com/mineiros-io/terraform-aws-s3-bucket/compare/v0.5.0...v0.6.0 +[0.5.0]: https://github.com/mineiros-io/terraform-aws-s3-bucket/compare/v0.4.2...v0.5.0 [0.4.2]: https://github.com/mineiros-io/terraform-aws-s3-bucket/compare/v0.4.1...v0.4.2 [0.4.1]: https://github.com/mineiros-io/terraform-aws-s3-bucket/compare/v0.4.0...v0.4.1 [0.4.0]: https://github.com/mineiros-io/terraform-aws-s3-bucket/compare/v0.3.0...v0.4.0 diff --git a/README.md b/README.md index 0c4cf88..494ce90 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Most basic usage creating a random named secure AWS bucket. ```hcl module "bucket" { source = "mineiros-io/s3-bucket/aws" - version = "~> 0.5.0" + version = "~> 0.6.0" } ``` diff --git a/examples/secure-s3-bucket/README.md b/examples/secure-s3-bucket/README.md index 23ce8c0..7d35db8 100644 --- a/examples/secure-s3-bucket/README.md +++ b/examples/secure-s3-bucket/README.md @@ -20,7 +20,7 @@ The code in [main.tf] defines... ```hcl module "example-app-bucket" { source = "mineiros-io/s3-bucket/aws" - version = "~> 0.5.0" + version = "~> 0.6.0" bucket_prefix = "app" @@ -40,7 +40,7 @@ module "example-app-bucket" { module "example-log-bucket" { source = "mineiros-io/s3-bucket/aws" - version = "~> 0.5.0" + version = "~> 0.6.0" bucket_prefix = "log" diff --git a/examples/secure-s3-bucket/main.tf b/examples/secure-s3-bucket/main.tf index aa92926..c1bf0ce 100644 --- a/examples/secure-s3-bucket/main.tf +++ b/examples/secure-s3-bucket/main.tf @@ -13,7 +13,7 @@ provider "aws" { module "example-app-bucket" { source = "mineiros-io/s3-bucket/aws" - version = "~> 0.5.0" + version = "~> 0.6.0" bucket_prefix = "app" @@ -37,7 +37,7 @@ module "example-app-bucket" { module "example-log-bucket" { source = "mineiros-io/s3-bucket/aws" - version = "~> 0.5.0" + version = "~> 0.6.0" bucket_prefix = "log"