From 8d0bec097d5b31b62f01a4fb698295d686f72dc6 Mon Sep 17 00:00:00 2001 From: confusdcodr Date: Wed, 11 Sep 2019 08:59:53 -0400 Subject: [PATCH 1/2] Upgrade to terraform 0.12.x --- .bumpversion.cfg | 1 + .dependabot/config.yml | 20 ++++++++ .editorconfig | 9 ++++ CHANGELOG.md | 11 +++++ LICENSE | 2 +- Makefile | 24 ++++++---- README.md | 8 ++-- main.tf | 33 +++++++------- tests/config_endpoint/main.tf | 35 ++++++++++++++ tests/config_endpoint/versions.tf | 3 ++ tests/example_testcase/main.tf | 7 --- tests/go.mod | 11 +++++ tests/go.sum | 25 ++++++++++ tests/module_test.go | 68 ++++++++++++++-------------- tests/multiple_endpoints/main.tf | 40 ++++++++++++++++ tests/multiple_endpoints/versions.tf | 3 ++ tests/no_create/main.tf | 12 +++++ tests/no_create/versions.tf | 3 ++ tests/no_endpoints/main.tf | 32 +++++++++++++ tests/no_endpoints/versions.tf | 3 ++ variables.tf | 11 +++-- versions.tf | 3 ++ 22 files changed, 287 insertions(+), 77 deletions(-) create mode 100644 tests/config_endpoint/main.tf create mode 100644 tests/config_endpoint/versions.tf delete mode 100644 tests/example_testcase/main.tf create mode 100644 tests/go.mod create mode 100644 tests/go.sum create mode 100644 tests/multiple_endpoints/main.tf create mode 100644 tests/multiple_endpoints/versions.tf create mode 100644 tests/no_create/main.tf create mode 100644 tests/no_create/versions.tf create mode 100644 tests/no_endpoints/main.tf create mode 100644 tests/no_endpoints/versions.tf create mode 100644 versions.tf diff --git a/.bumpversion.cfg b/.bumpversion.cfg index ee11dd6..7b43d04 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -4,3 +4,4 @@ commit = True message = Bumps version to {new_version} tag = False tag_name = {new_version} + diff --git a/.dependabot/config.yml b/.dependabot/config.yml index ab6dbbc..2cfba7f 100644 --- a/.dependabot/config.yml +++ b/.dependabot/config.yml @@ -5,3 +5,23 @@ update_configs: - package_manager: "terraform" directory: "/" update_schedule: "daily" + + - package_manager: "terraform" + directory: "/tests/no_endpoints" + update_schedule: "daily" + + - package_manager: "terraform" + directory: "/tests/config_endpoint" + update_schedule: "daily" + + - package_manager: "terraform" + directory: "/tests/multiple_endpoints" + update_schedule: "daily" + + - package_manager: "terraform" + directory: "/tests/no_create" + update_schedule: "daily" + + - package_manager: "go:modules" + directory: "/tests" + update_schedule: "daily" diff --git a/.editorconfig b/.editorconfig index 9c61d05..7109c82 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,7 @@ insert_final_newline = true indent_style = space indent_size = 2 charset = utf-8 +tab_width = 4 [*.md] trim_trailing_whitespace = false @@ -15,6 +16,14 @@ trim_trailing_whitespace = false [*.py] indent_size = 4 +[go.mod] +indent_style = tab +indent_size = 1 + +[*.go] +indent_style = tab +indent_size = 1 + [Makefile] indent_style = tab indent_size = 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index a9c9bad..24ef36d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +### 1.0.0 + +**Released**: 2019.09.11 + +**Commit Delta**: [Change from 0.0.0 release](https://github.com/plus3it/terraform-aws-tardigrade-vpc-endpoints/compare/0.0.0...1.0.0) + +**Summary**: + +* Upgrade to terraform 0.12.x +* Add test cases + ### 0.0.0 **Commit Delta**: N/A diff --git a/LICENSE b/LICENSE index 261eeb9..780b00e 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2019 Maintainers of plus3it/terraform-aws-tardigrade-vpc-endpoints Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile index 1d88840..447157a 100644 --- a/Makefile +++ b/Makefile @@ -100,24 +100,30 @@ json/format: | guard/program/jq $(FIND_JSON) | $(XARGS) bash -c 'echo "$$(jq --indent 4 -S . "{}")" > "{}"' @ echo "[$@]: Successfully formatted JSON files!" -docs/%: README_PARTS := _docs/MAIN.md <(echo) <(terraform-docs markdown table .) +tfdocs-awk/install: $(BIN_DIR) +tfdocs-awk/install: ARCHIVE := https://github.com/plus3it/tfdocs-awk/archive/master.tar.gz +tfdocs-awk/install: + $(CURL) $(ARCHIVE) | tar -C $(BIN_DIR) --strip-components=1 --wildcards '*.sh' --wildcards '*.awk' -xzvf - + +docs/%: README_PARTS := _docs/MAIN.md <(echo) <($(BIN_DIR)/terraform-docs.sh markdown table .) docs/%: README_FILE ?= README.md -docs/lint: | guard/program/terraform-docs +docs/lint: | guard/program/terraform-docs tfdocs-awk/install @ echo "[$@]: Linting documentation files.." diff $(README_FILE) <(cat $(README_PARTS)) @ echo "[$@]: Documentation files PASSED lint test!" -docs/generate: | guard/program/terraform-docs +docs/generate: | guard/program/terraform-docs tfdocs-awk/install @ echo "[$@]: Creating documentation files.." cat $(README_PARTS) > $(README_FILE) @ echo "[$@]: Documentation files creation complete!" -dep/install: guard/program/curl - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - -terratest/install: | guard/program/go guard/program/dep - cd tests && dep ensure +terratest/install: | guard/program/go + cd tests && go mod init terraform-aws-tardigrade-vpc-endpoints/tests + cd tests && go build ./... + cd tests && go mod tidy -terratest/test: | guard/program/go guard/program/dep +terratest/test: | guard/program/go cd tests && go test -timeout 20m + +test: terratest/test diff --git a/README.md b/README.md index ae7cc46..98afb7b 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ Terraform module to create VPC Endpoints | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| -| create\_vpc\_endpoints | toggle to create vpc endpoints | string | `"false"` | no | -| subnet\_ids | target subnet ids | list | `` | no | -| tags | A map of tags to add to the VPC endpoint SG | map | `` | no | -| vpc\_endpoint\_interfaces | List of aws api endpoints that are used to create VPC Interface endpoints. See https://docs.aws.amazon.com/general/latest/gr/rande.html for full list. | list | `` | no | +| create\_vpc\_endpoints | toggle to create vpc endpoints | string | `"true"` | no | +| subnet\_ids | target subnet ids | list(string) | `` | no | +| tags | A map of tags to add to the VPC endpoint SG | map(string) | `` | no | +| vpc\_endpoint\_interfaces | List of aws api endpoints that are used to create VPC Interface endpoints. See https://docs.aws.amazon.com/general/latest/gr/rande.html for full list. | list(string) | `` | no | diff --git a/main.tf b/main.tf index 0cbfc5f..3ac86f7 100644 --- a/main.tf +++ b/main.tf @@ -1,31 +1,31 @@ data "aws_subnet" "selected" { - count = "${var.create_vpc_endpoints ? 1 : 0}" + count = var.create_vpc_endpoints ? 1 : 0 - id = "${var.subnet_ids[0]}" + id = var.subnet_ids[0] } data "aws_vpc" "selected" { - count = "${var.create_vpc_endpoints ? 1 : 0}" + count = var.create_vpc_endpoints ? 1 : 0 - id = "${local.vpc_id}" + id = local.vpc_id } locals { - vpc_id = "${join("", data.aws_subnet.selected.*.vpc_id)}" - vpc_cidr = "${join("", data.aws_vpc.selected.*.cidr_block)}" + vpc_id = join("", data.aws_subnet.selected.*.vpc_id) + vpc_cidr = join("", data.aws_vpc.selected.*.cidr_block) } resource "aws_security_group" "this" { - count = "${var.create_vpc_endpoints ? 1 : 0}" + count = var.create_vpc_endpoints ? 1 : 0 description = "VPC Interface Endpoints - Allow inbound from ${local.vpc_id} and allow all outbound" - vpc_id = "${local.vpc_id}" + vpc_id = local.vpc_id ingress { from_port = 0 to_port = 0 protocol = "-1" - cidr_blocks = ["${local.vpc_cidr}"] + cidr_blocks = [local.vpc_cidr] } egress { @@ -35,24 +35,23 @@ resource "aws_security_group" "this" { cidr_blocks = ["0.0.0.0/0"] } - tags = "${var.tags}" + tags = var.tags } resource "aws_vpc_endpoint" "interface_services" { - count = "${var.create_vpc_endpoints ? length(var.vpc_endpoint_interfaces) : 0}" + count = var.create_vpc_endpoints ? length(var.vpc_endpoint_interfaces) : 0 - vpc_id = "${local.vpc_id}" - service_name = "${var.vpc_endpoint_interfaces[count.index]}" + vpc_id = local.vpc_id + service_name = var.vpc_endpoint_interfaces[count.index] vpc_endpoint_type = "Interface" auto_accept = true - subnet_ids = [ - "${var.subnet_ids}", - ] + subnet_ids = var.subnet_ids security_group_ids = [ - "${aws_security_group.this.id}", + aws_security_group.this[0].id, ] private_dns_enabled = true # https://docs.aws.amazon.com/vpc/latest/userguide/vpce-interface.html#vpce-private-dns } + diff --git a/tests/config_endpoint/main.tf b/tests/config_endpoint/main.tf new file mode 100644 index 0000000..fc1c6af --- /dev/null +++ b/tests/config_endpoint/main.tf @@ -0,0 +1,35 @@ +provider aws { + region = "us-east-1" +} + +resource "random_string" "this" { + length = 6 + upper = false + special = false + number = false +} + +module "vpc" { + source = "github.com/terraform-aws-modules/terraform-aws-vpc?ref=v2.15.0" + providers = { + aws = aws + } + + name = "tardigrade-vpc-endpoints-${random_string.this.result}" + cidr = "10.0.0.0/16" + azs = ["us-east-1a", "us-east-1b"] + private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] + enable_dns_hostnames = true + enable_dns_support = true +} + +module "config_endpoint" { + source = "../../" + providers = { + aws = aws + } + + create_vpc_endpoints = true + vpc_endpoint_interfaces = ["com.amazonaws.us-east-1.config"] + subnet_ids = module.vpc.private_subnets +} diff --git a/tests/config_endpoint/versions.tf b/tests/config_endpoint/versions.tf new file mode 100644 index 0000000..d9b6f79 --- /dev/null +++ b/tests/config_endpoint/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.12" +} diff --git a/tests/example_testcase/main.tf b/tests/example_testcase/main.tf deleted file mode 100644 index dbe7f9d..0000000 --- a/tests/example_testcase/main.tf +++ /dev/null @@ -1,7 +0,0 @@ -terraform { - required_version = "~> 0.11.0" -} - -module "example" { - source = "../../" -} diff --git a/tests/go.mod b/tests/go.mod new file mode 100644 index 0000000..6fc05c5 --- /dev/null +++ b/tests/go.mod @@ -0,0 +1,11 @@ +module terraform-aws-tardigrade-vpc-endpoints/tests + +go 1.12 + +require ( + github.com/gruntwork-io/terratest v0.18.6 + github.com/magiconair/properties v1.8.1 // indirect + github.com/stretchr/testify v1.4.0 // indirect + golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 // indirect + golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect +) diff --git a/tests/go.sum b/tests/go.sum new file mode 100644 index 0000000..9ce561c --- /dev/null +++ b/tests/go.sum @@ -0,0 +1,25 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gruntwork-io/terratest v0.18.6 h1:6LQeJC7O3NErZLv7MNRUuUuFtlekg3z8rYSwOqtJ6ws= +github.com/gruntwork-io/terratest v0.18.6/go.mod h1:NjUn6YXA5Skxt8Rs20t3isYx5Rl+EgvGB8/+RRXddqk= +github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM= +golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/tests/module_test.go b/tests/module_test.go index d3905e0..61254e3 100644 --- a/tests/module_test.go +++ b/tests/module_test.go @@ -1,49 +1,49 @@ package testing import ( - "io/ioutil" - "log" - "os" - "testing" + "io/ioutil" + "log" + "os" + "testing" - "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/gruntwork-io/terratest/modules/terraform" ) func TestModule(t *testing.T) { - files, err := ioutil.ReadDir("./") - - if err != nil { - log.Fatal(err) - } - - for _, f := range files { - // look for directories with test cases in it - if f.IsDir() && f.Name() != "vendor" { - investigateDirectory(t, f) - } - } + files, err := ioutil.ReadDir("./") + + if err != nil { + log.Fatal(err) + } + + for _, f := range files { + // look for directories with test cases in it + if f.IsDir() && f.Name() != "vendor" { + investigateDirectory(t, f) + } + } } func investigateDirectory(t *testing.T, directory os.FileInfo) { - // check if a prereq directory exists - prereqDir := directory.Name() + "/prereq/" - if _, err := os.Stat(prereqDir); err == nil { - prereqOptions := createTerraformOptions(prereqDir) - defer terraform.Destroy(t, prereqOptions) - terraform.InitAndApply(t, prereqOptions) - } - - // run terraform code for test case - terraformOptions := createTerraformOptions(directory.Name()) - defer terraform.Destroy(t, terraformOptions) - terraform.InitAndApply(t, terraformOptions) + // check if a prereq directory exists + prereqDir := directory.Name() + "/prereq/" + if _, err := os.Stat(prereqDir); err == nil { + prereqOptions := createTerraformOptions(prereqDir) + defer terraform.Destroy(t, prereqOptions) + terraform.InitAndApply(t, prereqOptions) + } + + // run terraform code for test case + terraformOptions := createTerraformOptions(directory.Name()) + defer terraform.Destroy(t, terraformOptions) + terraform.InitAndApply(t, terraformOptions) } func createTerraformOptions(directory string) *terraform.Options { - terraformOptions := &terraform.Options{ - TerraformDir: directory, - NoColor: true, - } + terraformOptions := &terraform.Options{ + TerraformDir: directory, + NoColor: true, + } - return terraformOptions + return terraformOptions } diff --git a/tests/multiple_endpoints/main.tf b/tests/multiple_endpoints/main.tf new file mode 100644 index 0000000..58952d0 --- /dev/null +++ b/tests/multiple_endpoints/main.tf @@ -0,0 +1,40 @@ +provider aws { + region = "us-east-1" +} + +resource "random_string" "this" { + length = 6 + upper = false + special = false + number = false +} + +module "vpc" { + source = "github.com/terraform-aws-modules/terraform-aws-vpc?ref=v2.15.0" + providers = { + aws = aws + } + + name = "tardigrade-vpc-endpoints-${random_string.this.result}" + cidr = "10.0.0.0/16" + azs = ["us-east-1a", "us-east-1b"] + private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] + enable_dns_hostnames = true + enable_dns_support = true +} + +module "config_endpoint" { + source = "../../" + providers = { + aws = aws + } + + create_vpc_endpoints = true + vpc_endpoint_interfaces = [ + "com.amazonaws.us-east-1.config", + "com.amazonaws.us-east-1.codepipeline", + "com.amazonaws.us-east-1.monitoring", + "com.amazonaws.us-east-1.ec2", + ] + subnet_ids = module.vpc.private_subnets +} diff --git a/tests/multiple_endpoints/versions.tf b/tests/multiple_endpoints/versions.tf new file mode 100644 index 0000000..d9b6f79 --- /dev/null +++ b/tests/multiple_endpoints/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.12" +} diff --git a/tests/no_create/main.tf b/tests/no_create/main.tf new file mode 100644 index 0000000..04e68f7 --- /dev/null +++ b/tests/no_create/main.tf @@ -0,0 +1,12 @@ +provider aws { + region = "us-east-1" +} + +module "no_create" { + source = "../../" + providers = { + aws = aws + } + + create_vpc_endpoints = false +} diff --git a/tests/no_create/versions.tf b/tests/no_create/versions.tf new file mode 100644 index 0000000..d9b6f79 --- /dev/null +++ b/tests/no_create/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.12" +} diff --git a/tests/no_endpoints/main.tf b/tests/no_endpoints/main.tf new file mode 100644 index 0000000..1409285 --- /dev/null +++ b/tests/no_endpoints/main.tf @@ -0,0 +1,32 @@ +provider aws { + region = "us-east-1" +} + +resource "random_string" "this" { + length = 6 + upper = false + special = false + number = false +} + +module "vpc" { + source = "github.com/terraform-aws-modules/terraform-aws-vpc?ref=v2.15.0" + providers = { + aws = aws + } + + name = "tardigrade-vpc-endpoints-${random_string.this.result}" + cidr = "10.0.0.0/16" + azs = ["us-east-1a", "us-east-1b"] + private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] +} + +module "config_endpoint" { + source = "../../" + providers = { + aws = aws + } + + create_vpc_endpoints = true + subnet_ids = module.vpc.private_subnets +} diff --git a/tests/no_endpoints/versions.tf b/tests/no_endpoints/versions.tf new file mode 100644 index 0000000..d9b6f79 --- /dev/null +++ b/tests/no_endpoints/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.12" +} diff --git a/variables.tf b/variables.tf index 78ddecd..2434b5b 100644 --- a/variables.tf +++ b/variables.tf @@ -1,23 +1,24 @@ variable "create_vpc_endpoints" { - type = "string" + type = string description = "toggle to create vpc endpoints" - default = false + default = true } variable "subnet_ids" { - type = "list" + type = list(string) description = "target subnet ids" default = [] } variable "vpc_endpoint_interfaces" { - type = "list" + type = list(string) description = "List of aws api endpoints that are used to create VPC Interface endpoints. See https://docs.aws.amazon.com/general/latest/gr/rande.html for full list." default = [] } variable "tags" { description = "A map of tags to add to the VPC endpoint SG" - type = "map" + type = map(string) default = {} } + diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..d9b6f79 --- /dev/null +++ b/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.12" +} From 8503a24add4e170e6fa364fdc501c807dd7f54f9 Mon Sep 17 00:00:00 2001 From: confusdcodr Date: Wed, 11 Sep 2019 09:54:44 -0400 Subject: [PATCH 2/2] Bumps version to 1.0.0 --- .bumpversion.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 7b43d04..1b11052 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.0.0 +current_version = 1.0.0 commit = True message = Bumps version to {new_version} tag = False