Skip to content

Commit

Permalink
add atmos support (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalhoun authored Apr 15, 2024
1 parent 9e53ea7 commit fcfc4a4
Show file tree
Hide file tree
Showing 29 changed files with 2,333 additions and 225 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ on:
types: [opened, synchronize, reopened]
paths-ignore:
- "README.md"

release:
types: [created]
paths-ignore:
- "README.md"

workflow_dispatch:

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
id-token: write # This is required for requesting the JWT for OIDC
contents: read # This is required for actions/checkout

jobs:
test:
Expand All @@ -30,6 +26,16 @@ jobs:
go-version-file: "./go.mod"
id: go

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false

- name: Setup atmos
uses: cloudposse/github-action-setup-atmos@v2
with:
install-wrapper: false

- name: Get dependencies
run: go mod download

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

**/.terraform.lock.hcl

bin/
bin/
unit-tests.xml
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ deps:
go mod download

# Run acceptance tests
testacc: get
go test $(TEST) -v $(TESTARGS) -timeout 2m
test: deps
go run gotest.tools/gotestsum@latest --junitfile unit-tests.xml --format pkgname-and-test-fails -- -timeout 30m -parallel=1 -count=1 -v $(TEST)

.PHONY: lint get build deps version testacc
.PHONY: lint get build deps version testacc
244 changes: 91 additions & 153 deletions README.md

Large diffs are not rendered by default.

68 changes: 61 additions & 7 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ categories:
- terratest

description: |-
`terratest-helpers` - A library for helping to run tests in [terratest](https://terratest.gruntwork.io).
`terratest-helpers` is a library that adds some missing functionality to [terratest](https://terratest.gruntwork.io).
introduction: |-
`terratest-helpers` is a library for helping to run tests in [terratest](https://terratest.gruntwork.io).
`terratest-helpers` is a library that adds some missing functionality to [terratest](https://terratest.gruntwork.io).
`terratest-helpers` includes functionality for:
- Destroying all resources in an AWS account after a test run
- Destroying all resources in an AWS account after a test run using [aws-nuke](https://github.com/rebuy-de/aws-nuke)
- Running tests with [atmos](https://github.com/cloudposse/atmos) stack configs
## Install
### Go
## Install
Install the latest version
Install the latest version in your go tests
```console
go install github.com/cloudposse/terratest-helpers
Expand All @@ -49,9 +49,63 @@ introduction: |-
You can use `terratest-helpers` as a library in your own terratest code.
### atmos
This library is designed to be used with [atmos](https://github.com/cloudposse/atmos) to allow you to run tests with
different stack configurations. For example, imagine you have a component that you want to test to make sure it applies
properly and that the coput contains "Hello, World". Below hows how you could run a test from an atmos stack.
```go
func TestApplyNoError(t *testing.T) {
t.Parallel()
testFolder, err := files.CopyTerraformFolderToTemp("test/my-test", t.Name())
require.NoError(t, err)
fmt.Printf("running in %s\n", testFolder)
options := WithDefaultRetryableErrors(t, &Options{
AtmosBasePath: testFolder,
Component: "terraform-no-error",
Stack: testStack,
NoColor: true,
})
out := Apply(t, options)
require.Contains(t, out, "Hello, World")
}
```
### aws-nuke
```go
func TestAwsNuke(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/awsnuke-example"
tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
defer os.RemoveAll(tempTestFolder)
terraformOptions := &terraform.Options{
TerraformDir: tempTestFolder,
Upgrade: true,
VarFiles: []string{fmt.Sprintf("fixtures.%s.tfvars", testRegion)},
Vars: map[string]interface{}{
"attributes": []string{randID},
"default_tags": map[string]string{
terratestTagName: randID,
},
},
}
```
## Examples
The [example](examples/) folder contains examples that demonstrate the use of `terratest-helpers`:
The [example](examples/) folder contains a full set examples that demonstrate the use of `terratest-helpers`:
- [example](examples/awsnuke-example) folder contains a terraform module that can be used to test the `awsnuke` functionality.
The test for this module is in [pkg/awsnuke/awsnuke_test.go](pkg/awsnuke/awsnuke_test.go).
Expand Down
116 changes: 61 additions & 55 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,58 +1,63 @@
module github.com/cloudposse/terratest-helpers

go 1.19
go 1.21

require (
github.com/gruntwork-io/terratest v0.46.9
github.com/hashicorp/terraform-json v0.14.0
github.com/jinzhu/copier v0.3.5
github.com/rebuy-de/aws-nuke/v2 v2.20.0
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.4
)

require (
cloud.google.com/go v0.104.0 // indirect
cloud.google.com/go/compute v1.10.0 // indirect
cloud.google.com/go/iam v0.5.0 // indirect
cloud.google.com/go/storage v1.27.0 // indirect
cloud.google.com/go v0.110.10 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/storage v1.35.1 // indirect
github.com/PuerkitoBio/purell v1.2.0 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/boombuler/barcode v1.0.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/cloudposse/atmos v1.54.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/docker/spdystream v0.1.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gruntwork-io/go-commons v0.13.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.6.2 // indirect
github.com/hashicorp/go-getter v1.7.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl/v2 v2.14.1 // indirect
github.com/hashicorp/terraform-json v0.14.0 // indirect
github.com/hashicorp/hcl/v2 v2.19.1 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jstemmer/go-junit-report v1.0.0 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-zglob v0.0.3 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand All @@ -62,59 +67,60 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/pquerna/otp v1.3.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/tmccombs/hcl2json v0.3.4 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/urfave/cli v1.22.10 // indirect
github.com/urfave/cli/v2 v2.20.2 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/zclconf/go-cty v1.11.1 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/term v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/tools v0.2.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.100.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221018160656-63c7b68cfc55 // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/api v0.153.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.25.3 // indirect
k8s.io/apimachinery v0.25.3 // indirect
k8s.io/client-go v0.25.3 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221012122500-cfd413dd9e85 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/api v0.28.4 // indirect
k8s.io/apimachinery v0.28.4 // indirect
k8s.io/client-go v0.28.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

require (
github.com/aws/aws-sdk-go v1.44.120
github.com/fatih/color v1.13.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gruntwork-io/terratest v0.40.24
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/aws/aws-sdk-go v1.44.122
github.com/fatih/color v1.16.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.0 // indirect
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading

0 comments on commit fcfc4a4

Please sign in to comment.