Skip to content

Commit

Permalink
Merge pull request #49 from padok-team/test/create-terratest
Browse files Browse the repository at this point in the history
chore(test): add terratest
  • Loading branch information
nlevee authored Oct 11, 2024
2 parents 87420dc + 9ca6188 commit 4314810
Show file tree
Hide file tree
Showing 9 changed files with 1,119 additions and 21 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/terratest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on:
pull_request:
branches:
- main
paths:
- "**.tf"
- "test/*.go"
name: terratest
jobs:
terratest:
runs-on: ubuntu-latest

permissions:
contents: "read"
id-token: "write"

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.22.x"
- uses: "google-github-actions/auth@v2"
with:
project_id: "library-344516"
workload_identity_provider: "projects/270410071403/locations/global/workloadIdentityPools/github/providers/padok-gcp-library"
- name: tfswitch
run: |
wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh
chmod 755 install.sh
./install.sh -b ~/.local/bin v1.2.2 # Last arg is the desired tfswitch version
rm install.sh
tfswitch -b ~/.local/bin/terraform
- name: Test with the Go CLI
run: go test -timeout 30s ./test
9 changes: 0 additions & 9 deletions examples/custom-cdn-policy/versions.tf

This file was deleted.

3 changes: 0 additions & 3 deletions examples/lb-with-custom-certificate/versions.tf

This file was deleted.

9 changes: 0 additions & 9 deletions examples/multi-backend-lb/versions.tf

This file was deleted.

57 changes: 57 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module github.com/padok-team/terraform-google-lb

go 1.22.7

require github.com/gruntwork-io/terratest v0.47.1

require (
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.19.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/storage v1.28.1 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/aws/aws-sdk-go v1.44.122 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.6 // indirect
github.com/hashicorp/go-multierror v1.1.0 // 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.9.1 // indirect
github.com/hashicorp/terraform-json v0.13.0 // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tmccombs/hcl2json v0.3.3 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/zclconf/go-cty v1.9.1 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.114.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
973 changes: 973 additions & 0 deletions go.sum

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions test/terraform_custom-cdn-policy_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package test

import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
)

func TestTerraformCustomCdnPolicyExample(t *testing.T) {
// retryable errors in terraform testing.
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: "../examples/custom-cdn-policy",
})

defer terraform.Destroy(t, terraformOptions)

terraform.InitAndPlan(t, terraformOptions)
}
18 changes: 18 additions & 0 deletions test/terraform_lb-with-custom-certificate_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package test

import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
)

func TestTerraformLbWithCustomCertificateExample(t *testing.T) {
// retryable errors in terraform testing.
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: "../examples/lb-with-custom-certificate",
})

defer terraform.Destroy(t, terraformOptions)

terraform.InitAndPlan(t, terraformOptions)
}
18 changes: 18 additions & 0 deletions test/terraform_multi-backend-lb_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package test

import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
)

func TestTerraformMultiBackendLbExample(t *testing.T) {
// retryable errors in terraform testing.
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: "../examples/multi-backend-lb",
})

defer terraform.Destroy(t, terraformOptions)

terraform.InitAndPlan(t, terraformOptions)
}

0 comments on commit 4314810

Please sign in to comment.