Skip to content

Commit

Permalink
Merge pull request #49 from mineiros-io/soerenmartius/terraform-1.x-s…
Browse files Browse the repository at this point in the history
…upport

Add support for Terraform v1.x
  • Loading branch information
soerenmartius authored Jul 25, 2021
2 parents 685a1f6 + 8730532 commit 9fac520
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 37 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ 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`

## [0.5.0]

### Added
Expand Down Expand Up @@ -135,11 +141,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- markdown-link-check-disable -->

[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

<!-- markdown-link-check-enable -->

[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
Expand Down
75 changes: 51 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}"
Expand All @@ -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
Expand All @@ -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}")
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
```

Expand Down Expand Up @@ -607,7 +607,7 @@ Copyright &copy; 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
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions examples/secure-s3-bucket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/secure-s3-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9fac520

Please sign in to comment.