Skip to content

Commit c4f3df3

Browse files
authored
Update test-framework to current (cloudposse#142)
1 parent 2fed1b2 commit c4f3df3

File tree

11 files changed

+195
-614
lines changed

11 files changed

+195
-614
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ Available targets:
355355

356356
| Name | Version |
357357
|------|---------|
358-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
358+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
359359
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.63.0 |
360360
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
361361

docs/terraform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
| Name | Version |
55
|------|---------|
6-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
6+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
77
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.63.0 |
88
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
99

examples/complete/fixtures.us-east-2.tfvars

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
enabled = true
2-
31
region = "us-east-2"
42

53
availability_zones = ["us-east-2a", "us-east-2b"]

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ resource "aws_rds_cluster" "primary" {
148148

149149
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster#replication_source_identifier
150150
resource "aws_rds_cluster" "secondary" {
151-
count = local.enabled && ! local.is_regional_cluster ? 1 : 0
151+
count = local.enabled && !local.is_regional_cluster ? 1 : 0
152152
cluster_identifier = var.cluster_identifier == "" ? module.this.id : var.cluster_identifier
153153
database_name = var.db_name
154154
master_username = local.ignore_admin_credentials ? null : var.admin_user
@@ -342,7 +342,7 @@ module "dns_replicas" {
342342
source = "cloudposse/route53-cluster-hostname/aws"
343343
version = "0.12.2"
344344

345-
enabled = local.enabled && length(var.zone_id) > 0 && ! local.is_serverless && local.cluster_instance_count > 0
345+
enabled = local.enabled && length(var.zone_id) > 0 && !local.is_serverless && local.cluster_instance_count > 0
346346
dns_name = local.reader_dns_name
347347
zone_id = var.zone_id
348348
records = coalescelist(aws_rds_cluster.primary.*.reader_endpoint, aws_rds_cluster.secondary.*.reader_endpoint, [""])

test/Makefile

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
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)
22

33
.DEFAULT_GOAL : all
4-
54
.PHONY: all
5+
66
## Default target
77
all: test
88

@@ -15,8 +15,7 @@ init:
1515
## Run tests
1616
test: init
1717
go mod download
18-
go test -v -timeout 60m -run TestExamplesComplete
19-
go test -v -timeout 60m -run TestExamplesServerlessv2Postgres
18+
go test -v -timeout 60m
2019

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

test/src/examples_complete_test.go

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
package test
22

33
import (
4-
"math/rand"
5-
"strconv"
4+
"os"
5+
"strings"
66
"testing"
7-
"time"
87

8+
"github.com/gruntwork-io/terratest/modules/random"
99
"github.com/gruntwork-io/terratest/modules/terraform"
10+
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
1011
"github.com/stretchr/testify/assert"
1112
)
1213

14+
func cleanup(t *testing.T, terraformOptions *terraform.Options, tempTestFolder string) {
15+
terraform.Destroy(t, terraformOptions)
16+
os.RemoveAll(tempTestFolder)
17+
}
18+
1319
// Test the Terraform module in examples/complete using Terratest.
1420
func TestExamplesComplete(t *testing.T) {
1521
t.Parallel()
22+
randID := strings.ToLower(random.UniqueId())
23+
attributes := []string{randID}
1624

17-
rand.Seed(time.Now().UnixNano())
25+
rootFolder := "../../"
26+
terraformFolderRelativeToRoot := "examples/complete"
27+
varFiles := []string{"fixtures.us-east-2.tfvars"}
1828

19-
randId := strconv.Itoa(rand.Intn(100000))
20-
attributes := []string{randId}
29+
tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
2130

2231
terraformOptions := &terraform.Options{
2332
// The path to where our Terraform code is located
24-
TerraformDir: "../../examples/complete",
33+
TerraformDir: tempTestFolder,
2534
Upgrade: true,
2635
// Variables to pass to our Terraform code using -var-file options
27-
VarFiles: []string{"fixtures.us-east-2.tfvars"},
36+
VarFiles: varFiles,
2837
Vars: map[string]interface{}{
2938
"attributes": attributes,
3039
},
3140
}
3241

3342
// At the end of the test, run `terraform destroy` to clean up any resources that were created
34-
defer terraform.Destroy(t, terraformOptions)
43+
defer cleanup(t, terraformOptions, tempTestFolder)
3544

3645
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
3746
terraform.InitAndApply(t, terraformOptions)
@@ -53,7 +62,7 @@ func TestExamplesComplete(t *testing.T) {
5362

5463
// Run `terraform output` to get the value of an output variable
5564
clusterIdentifier := terraform.Output(t, terraformOptions, "cluster_identifier")
56-
expectedClusterIdentifier := "eg-test-rds-cluster-" + randId
65+
expectedClusterIdentifier := "eg-test-rds-cluster-" + randID
5766
// Verify we're getting back the outputs we expect
5867
assert.Equal(t, expectedClusterIdentifier, clusterIdentifier)
5968

@@ -62,3 +71,36 @@ func TestExamplesComplete(t *testing.T) {
6271
// Verify we're getting back the outputs we expect
6372
assert.Contains(t, arn, ":cluster:eg-test-rds-cluster")
6473
}
74+
75+
func TestExamplesCompleteDisabled(t *testing.T) {
76+
t.Parallel()
77+
randID := strings.ToLower(random.UniqueId())
78+
attributes := []string{randID}
79+
80+
rootFolder := "../../"
81+
terraformFolderRelativeToRoot := "examples/complete"
82+
varFiles := []string{"fixtures.us-east-2.tfvars"}
83+
84+
tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
85+
86+
terraformOptions := &terraform.Options{
87+
// The path to where our Terraform code is located
88+
TerraformDir: tempTestFolder,
89+
Upgrade: true,
90+
// Variables to pass to our Terraform code using -var-file options
91+
VarFiles: varFiles,
92+
Vars: map[string]interface{}{
93+
"attributes": attributes,
94+
"enabled": "false",
95+
},
96+
}
97+
98+
// At the end of the test, run `terraform destroy` to clean up any resources that were created
99+
defer cleanup(t, terraformOptions, tempTestFolder)
100+
101+
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
102+
results := terraform.InitAndApply(t, terraformOptions)
103+
104+
// Should complete successfully without creating or changing any resources
105+
assert.Contains(t, results, "Resources: 0 added, 0 changed, 0 destroyed.")
106+
}

test/src/examples_serverlessv2_postgres_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
11
package test
22

33
import (
4-
"math/rand"
5-
"strconv"
4+
"strings"
65
"testing"
7-
"time"
86

7+
"github.com/gruntwork-io/terratest/modules/random"
98
"github.com/gruntwork-io/terratest/modules/terraform"
9+
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
1010
"github.com/stretchr/testify/assert"
1111
)
1212

13-
// Test the Terraform module in examples/complete using Terratest.
13+
// Test the Terraform module in examples/serverlessv2_postgres using Terratest.
1414
func TestExamplesServerlessv2Postgres(t *testing.T) {
1515
t.Parallel()
16+
randID := strings.ToLower(random.UniqueId())
17+
attributes := []string{randID}
1618

17-
rand.Seed(time.Now().UnixNano())
19+
rootFolder := "../../"
20+
terraformFolderRelativeToRoot := "examples/serverlessv2_postgres"
21+
varFiles := []string{"fixtures.us-east-2.tfvars"}
1822

19-
randId := strconv.Itoa(rand.Intn(100000))
20-
attributes := []string{randId}
23+
tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
2124

2225
terraformOptions := &terraform.Options{
2326
// The path to where our Terraform code is located
24-
TerraformDir: "../../examples/serverlessv2_postgres",
27+
TerraformDir: tempTestFolder,
2528
Upgrade: true,
2629
// Variables to pass to our Terraform code using -var-file options
27-
VarFiles: []string{"fixtures.us-east-2.tfvars"},
30+
VarFiles: varFiles,
2831
Vars: map[string]interface{}{
2932
"attributes": attributes,
3033
},
3134
}
3235

3336
// At the end of the test, run `terraform destroy` to clean up any resources that were created
34-
defer terraform.Destroy(t, terraformOptions)
37+
defer cleanup(t, terraformOptions, tempTestFolder)
3538

3639
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
3740
terraform.InitAndApply(t, terraformOptions)
@@ -53,7 +56,7 @@ func TestExamplesServerlessv2Postgres(t *testing.T) {
5356

5457
// Run `terraform output` to get the value of an output variable
5558
clusterIdentifier := terraform.Output(t, terraformOptions, "cluster_identifier")
56-
expectedClusterIdentifier := "eg-test-rds-cluster-" + randId
59+
expectedClusterIdentifier := "eg-test-rds-cluster-" + randID
5760
// Verify we're getting back the outputs we expect
5861
assert.Equal(t, expectedClusterIdentifier, clusterIdentifier)
5962

test/src/go.mod

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,89 @@
11
module github.com/cloudposse/terraform-aws-rds-cluster
22

3-
go 1.14
3+
go 1.17
44

55
require (
6-
github.com/gruntwork-io/terratest v0.40.12
6+
// Known security flaws in terratest dependencies prior to v0.40.15
7+
github.com/gruntwork-io/terratest v0.40.16
78
github.com/stretchr/testify v1.7.0
89
)
10+
11+
require (
12+
cloud.google.com/go v0.83.0 // indirect
13+
cloud.google.com/go/storage v1.10.0 // indirect
14+
github.com/agext/levenshtein v1.2.3 // indirect
15+
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
16+
github.com/aws/aws-sdk-go v1.40.56 // indirect
17+
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
18+
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
19+
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
20+
github.com/davecgh/go-spew v1.1.1 // indirect
21+
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
22+
github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
23+
github.com/go-logr/logr v0.2.0 // indirect
24+
github.com/go-sql-driver/mysql v1.4.1 // indirect
25+
github.com/gogo/protobuf v1.3.2 // indirect
26+
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
27+
github.com/golang/protobuf v1.5.2 // indirect
28+
github.com/golang/snappy v0.0.3 // indirect
29+
github.com/google/gofuzz v1.1.0 // indirect
30+
github.com/google/uuid v1.2.0 // indirect
31+
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
32+
github.com/googleapis/gnostic v0.4.1 // indirect
33+
github.com/gruntwork-io/go-commons v0.8.0 // indirect
34+
github.com/hashicorp/errwrap v1.0.0 // indirect
35+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
36+
github.com/hashicorp/go-getter v1.6.1 // indirect
37+
github.com/hashicorp/go-multierror v1.1.0 // indirect
38+
github.com/hashicorp/go-safetemp v1.0.0 // indirect
39+
github.com/hashicorp/go-version v1.3.0 // indirect
40+
github.com/hashicorp/hcl/v2 v2.9.1 // indirect
41+
github.com/hashicorp/terraform-json v0.13.0 // indirect
42+
github.com/imdario/mergo v0.3.11 // indirect
43+
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
44+
github.com/jmespath/go-jmespath v0.4.0 // indirect
45+
github.com/json-iterator/go v1.1.11 // indirect
46+
github.com/jstemmer/go-junit-report v0.9.1 // indirect
47+
github.com/klauspost/compress v1.13.0 // indirect
48+
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
49+
github.com/mitchellh/go-homedir v1.1.0 // indirect
50+
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
51+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
52+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
53+
github.com/modern-go/reflect2 v1.0.1 // indirect
54+
github.com/pmezard/go-difflib v1.0.0 // indirect
55+
github.com/pquerna/otp v1.2.0 // indirect
56+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
57+
github.com/spf13/pflag v1.0.5 // indirect
58+
github.com/tmccombs/hcl2json v0.3.3 // indirect
59+
github.com/ulikunitz/xz v0.5.8 // indirect
60+
github.com/urfave/cli v1.22.2 // indirect
61+
github.com/zclconf/go-cty v1.9.1 // indirect
62+
go.opencensus.io v0.23.0 // indirect
63+
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
64+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
65+
golang.org/x/mod v0.4.2 // indirect
66+
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
67+
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
68+
golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e // indirect
69+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
70+
golang.org/x/text v0.3.6 // indirect
71+
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
72+
golang.org/x/tools v0.1.2 // indirect
73+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
74+
google.golang.org/api v0.47.0 // indirect
75+
google.golang.org/appengine v1.6.7 // indirect
76+
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
77+
google.golang.org/grpc v1.38.0 // indirect
78+
google.golang.org/protobuf v1.26.0 // indirect
79+
gopkg.in/inf.v0 v0.9.1 // indirect
80+
gopkg.in/yaml.v2 v2.4.0 // indirect
81+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
82+
k8s.io/api v0.20.6 // indirect
83+
k8s.io/apimachinery v0.20.6 // indirect
84+
k8s.io/client-go v0.20.6 // indirect
85+
k8s.io/klog/v2 v2.4.0 // indirect
86+
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
87+
sigs.k8s.io/structured-merge-diff/v4 v4.0.3 // indirect
88+
sigs.k8s.io/yaml v1.2.0 // indirect
89+
)

0 commit comments

Comments
 (0)