Skip to content

Commit c633d78

Browse files
authored
Update to latest module versions. Update tests (#49)
* Updates * Updates * Updates * Updates * Updates * Updates
1 parent f1f7c57 commit c633d78

14 files changed

+1129
-440
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2019 Cloud Posse, LLC
189+
Copyright 2019-2024 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

+27-27
Large diffs are not rendered by default.

docs/terraform.md

+27-27
Large diffs are not rendered by default.

examples/complete/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ provider "aws" {
33
}
44

55
module "vpn_connection" {
6-
source = "../../"
6+
source = "../../"
7+
78
vpc_id = var.vpc_id
89
vpn_gateway_amazon_side_asn = var.vpn_gateway_amazon_side_asn
910
customer_gateway_bgp_asn = var.customer_gateway_bgp_asn

examples/complete/outputs.tf

-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,3 @@ output "vpn_connection_tunnel2_vgw_inside_address" {
4848
description = "The RFC 6890 link-local address of the second VPN tunnel (Virtual Private Gateway side)"
4949
value = module.vpn_connection.vpn_connection_tunnel2_vgw_inside_address
5050
}
51-

examples/complete/variables.tf

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
variable "region" {
22
type = string
33
description = "AWS Region"
4-
default = "us-west-1"
4+
nullable = false
55
}
66

77
variable "vpc_id" {
88
type = string
99
description = "The ID of the VPC to which the Virtual Private Gateway will be attached"
10+
nullable = false
1011
}
1112

1213
variable "vpn_gateway_amazon_side_asn" {
14+
type = number
1315
description = "The Autonomous System Number (ASN) for the Amazon side of the VPN gateway. If you don't specify an ASN, the Virtual Private Gateway is created with the default ASN"
1416
default = 64512
17+
nullable = false
1518
}
1619

1720
variable "customer_gateway_bgp_asn" {
18-
description = "The gateway's Border Gateway Protocol (BGP) Autonomous System Number (ASN)"
21+
type = number
22+
description = "The Customer Gateway's Border Gateway Protocol (BGP) Autonomous System Number (ASN)"
1923
default = 65000
24+
nullable = false
2025
}
2126

2227
variable "customer_gateway_ip_address" {
@@ -27,18 +32,21 @@ variable "customer_gateway_ip_address" {
2732
variable "route_table_ids" {
2833
type = list(string)
2934
description = "The IDs of the route tables for which routes from the Virtual Private Gateway will be propagated"
35+
nullable = false
3036
}
3137

3238
variable "vpn_connection_static_routes_only" {
3339
type = bool
3440
description = "If set to `true`, the VPN connection will use static routes exclusively. Static routes must be used for devices that don't support BGP"
3541
default = true
42+
nullable = false
3643
}
3744

3845
variable "vpn_connection_static_routes_destinations" {
3946
type = list(string)
4047
description = "List of CIDR blocks to be used as destination for static routes. Routes to destinations will be propagated to the route tables defined in `route_table_ids`"
4148
default = ["10.80.1.0/24"]
49+
nullable = false
4250
}
4351

4452
variable "vpn_connection_tunnel1_inside_cidr" {
@@ -55,13 +63,12 @@ variable "vpn_connection_tunnel2_inside_cidr" {
5563

5664
variable "vpn_connection_tunnel1_preshared_key" {
5765
type = string
58-
description = "The preshared key of the first VPN tunnel. The preshared key must be between 8 and 64 characters in length and cannot start with zero. Allowed characters are alphanumeric characters, periods(.) and underscores(_)"
66+
description = "The preshared key of the first VPN tunnel. The pre-shared key must be between 8 and 64 characters in length and cannot start with zero. Allowed characters are alphanumeric characters, periods(.) and underscores(_)"
5967
default = ""
6068
}
6169

6270
variable "vpn_connection_tunnel2_preshared_key" {
6371
type = string
64-
description = "The preshared key of the second VPN tunnel. The preshared key must be between 8 and 64 characters in length and cannot start with zero. Allowed characters are alphanumeric characters, periods(.) and underscores(_)"
72+
description = "The preshared key of the second VPN tunnel. The pre-shared key must be between 8 and 64 characters in length and cannot start with zero. Allowed characters are alphanumeric characters, periods(.) and underscores(_)"
6573
default = ""
6674
}
67-

main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ resource "aws_customer_gateway" "default" {
2828
}
2929

3030
module "logs" {
31-
source = "cloudposse/cloudwatch-logs/aws"
32-
version = "0.6.8"
31+
source = "cloudposse/cloudwatch-logs/aws"
32+
version = "0.6.8"
33+
3334
enabled = local.logs_enabled
3435
iam_role_enabled = false
3536
retention_in_days = var.vpn_connection_log_retention_in_days
3637

3738
context = module.this.context
3839
}
3940

40-
4141
# https://www.terraform.io/docs/providers/aws/r/vpn_connection.html
4242
resource "aws_vpn_connection" "default" {
4343
count = local.enabled && var.customer_gateway_ip_address != null ? 1 : 0

outputs.tf

-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,3 @@ output "transit_gateway_attachment_id" {
5353
description = "The ID of the transit gateway attachment for the VPN connection (if a TGW connection)"
5454
value = local.transit_gateway_attachment_id
5555
}
56-

test/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ clean:
3333
all: module examples/complete
3434

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

4040
## Run tests against example
41-
examples/complete: export TESTS ?= installed lint get-modules get-plugins validate
41+
examples/complete: export TESTS ?= installed lint validate
4242
examples/complete: deps
4343
$(call RUN_TESTS, ../$@)

test/src/Makefile

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
export TF_CLI_ARGS_init ?= -get-plugins=true
2-
export TERRAFORM_VERSION ?= $(shell curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M '.current_version' | cut -d. -f1-2)
1+
export TERRAFORM_VERSION ?= $(shell curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M '.current_version' | cut -d. -f1)
32

43
.DEFAULT_GOAL : all
5-
64
.PHONY: all
5+
76
## Default target
87
all: test
98

@@ -16,7 +15,7 @@ init:
1615
## Run tests
1716
test: init
1817
go mod download
19-
go test -v -timeout 60m -run TestExamplesComplete
18+
go test -v -timeout 60m
2019

2120
## Run tests in docker container
2221
docker/test:

test/src/examples_complete_test.go

+61-3
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,50 @@
11
package test
22

33
import (
4+
"os"
5+
"strings"
46
"testing"
57

8+
"github.com/gruntwork-io/terratest/modules/random"
69
"github.com/gruntwork-io/terratest/modules/terraform"
10+
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
711
"github.com/stretchr/testify/assert"
812
)
913

14+
const (
15+
region = "us-east-2"
16+
)
17+
18+
func cleanup(t *testing.T, terraformOptions *terraform.Options, tempTestFolder string) {
19+
terraform.Destroy(t, terraformOptions)
20+
os.RemoveAll(tempTestFolder)
21+
}
22+
1023
// Test the Terraform module in examples/complete using Terratest.
1124
func TestExamplesComplete(t *testing.T) {
1225
t.Parallel()
26+
randID := strings.ToLower(random.UniqueId())
27+
attributes := []string{randID}
28+
29+
rootFolder := "../../"
30+
terraformFolderRelativeToRoot := "examples/complete"
31+
varFiles := []string{"fixtures." + region + ".tfvars"}
32+
33+
tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
1334

1435
terraformOptions := &terraform.Options{
1536
// The path to where our Terraform code is located
16-
TerraformDir: "../../examples/complete",
37+
TerraformDir: tempTestFolder,
1738
Upgrade: true,
1839
// Variables to pass to our Terraform code using -var-file options
19-
VarFiles: []string{"fixtures.us-east-2.tfvars"},
40+
VarFiles: varFiles,
41+
Vars: map[string]interface{}{
42+
"attributes": attributes,
43+
},
2044
}
2145

22-
defer terraform.Destroy(t, terraformOptions)
46+
// At the end of the test, run `terraform destroy` to clean up any resources that were created
47+
defer cleanup(t, terraformOptions, tempTestFolder)
2348

2449
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
2550
terraform.InitAndApply(t, terraformOptions)
@@ -32,3 +57,36 @@ func TestExamplesComplete(t *testing.T) {
3257
vpnGatewayId := terraform.Output(t, terraformOptions, "vpn_gateway_id")
3358
assert.Contains(t, vpnGatewayId, "vpn-")
3459
}
60+
61+
func TestExamplesCompleteDisabled(t *testing.T) {
62+
t.Parallel()
63+
randID := strings.ToLower(random.UniqueId())
64+
attributes := []string{randID}
65+
66+
rootFolder := "../../"
67+
terraformFolderRelativeToRoot := "examples/complete"
68+
varFiles := []string{"fixtures." + region + ".tfvars"}
69+
70+
tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
71+
72+
terraformOptions := &terraform.Options{
73+
// The path to where our Terraform code is located
74+
TerraformDir: tempTestFolder,
75+
Upgrade: true,
76+
// Variables to pass to our Terraform code using -var-file options
77+
VarFiles: varFiles,
78+
Vars: map[string]interface{}{
79+
"attributes": attributes,
80+
"enabled": "false",
81+
},
82+
}
83+
84+
// At the end of the test, run `terraform destroy` to clean up any resources that were created
85+
defer cleanup(t, terraformOptions, tempTestFolder)
86+
87+
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
88+
results := terraform.InitAndApply(t, terraformOptions)
89+
90+
// Should complete successfully without creating or changing any resources
91+
assert.Contains(t, results, "Resources: 0 added, 0 changed, 0 destroyed.")
92+
}

test/src/go.mod

+93-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,97 @@
1-
module github.com/cloudposse/terraform-aws-vpc-connection
1+
module github.com/cloudposse/terraform-aws-vpn-connection
22

3-
go 1.14
3+
go 1.21
44

55
require (
6-
github.com/gruntwork-io/terratest v0.31.1
7-
github.com/stretchr/testify v1.5.1
6+
github.com/gruntwork-io/terratest v0.47.0
7+
github.com/stretchr/testify v1.9.0
8+
)
9+
10+
require (
11+
cloud.google.com/go v0.110.0 // indirect
12+
cloud.google.com/go/compute v1.19.1 // indirect
13+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
14+
cloud.google.com/go/iam v0.13.0 // indirect
15+
cloud.google.com/go/storage v1.28.1 // indirect
16+
github.com/agext/levenshtein v1.2.3 // indirect
17+
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
18+
github.com/aws/aws-sdk-go v1.44.122 // indirect
19+
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
20+
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
21+
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
22+
github.com/davecgh/go-spew v1.1.1 // indirect
23+
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
24+
github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
25+
github.com/go-logr/logr v1.2.4 // indirect
26+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
27+
github.com/go-openapi/jsonreference v0.20.2 // indirect
28+
github.com/go-openapi/swag v0.22.3 // indirect
29+
github.com/go-sql-driver/mysql v1.4.1 // indirect
30+
github.com/gogo/protobuf v1.3.2 // indirect
31+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
32+
github.com/golang/protobuf v1.5.3 // indirect
33+
github.com/google/gnostic-models v0.6.8 // indirect
34+
github.com/google/go-cmp v0.5.9 // indirect
35+
github.com/google/gofuzz v1.2.0 // indirect
36+
github.com/google/uuid v1.3.0 // indirect
37+
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
38+
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
39+
github.com/gruntwork-io/go-commons v0.8.0 // indirect
40+
github.com/hashicorp/errwrap v1.0.0 // indirect
41+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
42+
github.com/hashicorp/go-getter v1.7.5 // indirect
43+
github.com/hashicorp/go-multierror v1.1.0 // indirect
44+
github.com/hashicorp/go-safetemp v1.0.0 // indirect
45+
github.com/hashicorp/go-version v1.6.0 // indirect
46+
github.com/hashicorp/hcl/v2 v2.9.1 // indirect
47+
github.com/hashicorp/terraform-json v0.13.0 // indirect
48+
github.com/imdario/mergo v0.3.11 // indirect
49+
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
50+
github.com/jmespath/go-jmespath v0.4.0 // indirect
51+
github.com/josharian/intern v1.0.0 // indirect
52+
github.com/json-iterator/go v1.1.12 // indirect
53+
github.com/klauspost/compress v1.15.11 // indirect
54+
github.com/mailru/easyjson v0.7.7 // indirect
55+
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
56+
github.com/mitchellh/go-homedir v1.1.0 // indirect
57+
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
58+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
59+
github.com/moby/spdystream v0.2.0 // indirect
60+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
61+
github.com/modern-go/reflect2 v1.0.2 // indirect
62+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
63+
github.com/pmezard/go-difflib v1.0.0 // indirect
64+
github.com/pquerna/otp v1.2.0 // indirect
65+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
66+
github.com/spf13/pflag v1.0.5 // indirect
67+
github.com/tmccombs/hcl2json v0.3.3 // indirect
68+
github.com/ulikunitz/xz v0.5.10 // indirect
69+
github.com/urfave/cli v1.22.2 // indirect
70+
github.com/zclconf/go-cty v1.9.1 // indirect
71+
go.opencensus.io v0.24.0 // indirect
72+
golang.org/x/crypto v0.21.0 // indirect
73+
golang.org/x/net v0.23.0 // indirect
74+
golang.org/x/oauth2 v0.8.0 // indirect
75+
golang.org/x/sys v0.18.0 // indirect
76+
golang.org/x/term v0.18.0 // indirect
77+
golang.org/x/text v0.14.0 // indirect
78+
golang.org/x/time v0.3.0 // indirect
79+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
80+
google.golang.org/api v0.114.0 // indirect
81+
google.golang.org/appengine v1.6.7 // indirect
82+
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
83+
google.golang.org/grpc v1.56.3 // indirect
84+
google.golang.org/protobuf v1.33.0 // indirect
85+
gopkg.in/inf.v0 v0.9.1 // indirect
86+
gopkg.in/yaml.v2 v2.4.0 // indirect
87+
gopkg.in/yaml.v3 v3.0.1 // indirect
88+
k8s.io/api v0.28.4 // indirect
89+
k8s.io/apimachinery v0.28.4 // indirect
90+
k8s.io/client-go v0.28.4 // indirect
91+
k8s.io/klog/v2 v2.100.1 // indirect
92+
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
93+
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
94+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
95+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
96+
sigs.k8s.io/yaml v1.3.0 // indirect
897
)

0 commit comments

Comments
 (0)