From dee0ab72cd04b0e8a5216a7bde220a57c531cf7f Mon Sep 17 00:00:00 2001 From: Daniel Butler Date: Tue, 23 Apr 2024 10:53:54 +0100 Subject: [PATCH] feat: added CI pipeline and tests (#3) --- .github/workflows/ci.yml | 12 +++++- .github/workflows/release.yml | 12 ++++++ stack_definition.json | 29 +++++++++++-- tests/README.md | 5 +++ tests/go.mod | 76 +++++++++++++++++++++++++++++++++++ tests/pr_test.go | 39 ++++++++++++++++++ 6 files changed, 168 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 tests/README.md create mode 100644 tests/go.mod create mode 100644 tests/pr_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6de81fa..eb7320e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1 +1,11 @@ -# TODO: Add CI workflow +name: CI-Pipeline + +# Controls when the workflow will run, when comment is created +on: + issue_comment: + types: + - created +jobs: + call-terraform-ci-pipeline: + uses: terraform-ibm-modules/common-pipeline-assets/.github/workflows/common-terraform-module-ci-v2.yml@v1.17.9 + secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..870eae3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,12 @@ +name: Release-Pipeline + +# Trigger on push(merge) to main branch +on: + push: + branches: + - main + +jobs: + call-terraform-release-pipeline: + uses: terraform-ibm-modules/common-pipeline-assets/.github/workflows/common-release.yml@v1.17.9 + secrets: inherit diff --git a/stack_definition.json b/stack_definition.json index c240e13..0a967c2 100644 --- a/stack_definition.json +++ b/stack_definition.json @@ -1,11 +1,24 @@ { - "inputs": [], + "inputs": [ + { + "name": "ibmcloud_api_key", + "required": true, + "type": "password", + "hidden": false + }, + { + "name": "resource_group_name", + "required": false, + "type": "string", + "hidden": false + } + ], "members": [ { "inputs": [ { "name": "resource_group", - "value": "__NULL__" + "value": "ref:../../inputs/resource_group_name" }, { "name": "resource_tags", @@ -17,7 +30,11 @@ }, { "name": "prefix", - "value": "mock" + "value": "primary" + }, + { + "name": "ibmcloud_api_key", + "value": "ref:../../inputs/ibmcloud_api_key" } ], "name": "primary-da", @@ -27,7 +44,7 @@ "inputs": [ { "name": "resource_group", - "value": "ref:/configs/primary-da/outputs/resource_group" + "value": "ref:../../inputs/resource_group_name" }, { "name": "resource_tags", @@ -40,6 +57,10 @@ { "name": "prefix", "value": "secondary" + }, + { + "name": "ibmcloud_api_key", + "value": "ref:../../inputs/ibmcloud_api_key" } ], "name": "secondary-da", diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..dfd6842 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,5 @@ +# Tests + +For information about how to create and run tests, see [Validation tests](https://terraform-ibm-modules.github.io/documentation/#/tests) in the project documentation. + + diff --git a/tests/go.mod b/tests/go.mod new file mode 100644 index 0000000..9d579b6 --- /dev/null +++ b/tests/go.mod @@ -0,0 +1,76 @@ +module github.com/terraform-ibm-modules/stack-ibm-template + +go 1.21 + +toolchain go1.21.3 + +require ( + github.com/stretchr/testify v1.9.0 + github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.31.1 +) + +require ( + github.com/IBM-Cloud/bluemix-go v0.0.0-20240402122236-5c5b994a3f1a // indirect + github.com/IBM-Cloud/power-go-client v1.6.0 // indirect + github.com/IBM/cloud-databases-go-sdk v0.6.0 // indirect + github.com/IBM/go-sdk-core/v5 v5.17.0 // indirect + github.com/IBM/platform-services-go-sdk v0.62.6 // indirect + github.com/IBM/project-go-sdk v0.2.9 // indirect + github.com/IBM/vpc-go-sdk v0.50.0 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/ghodss/yaml v1.0.0 // indirect + github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect + github.com/go-git/go-billy/v5 v5.5.0 // indirect + github.com/go-git/go-git/v5 v5.12.0 // indirect + github.com/go-logr/logr v1.3.0 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-openapi/analysis v0.21.5 // indirect + github.com/go-openapi/errors v0.22.0 // indirect + github.com/go-openapi/jsonpointer v0.20.1 // indirect + github.com/go-openapi/jsonreference v0.20.3 // indirect + github.com/go-openapi/loads v0.21.3 // indirect + github.com/go-openapi/runtime v0.26.0 // indirect + github.com/go-openapi/spec v0.20.12 // indirect + github.com/go-openapi/strfmt v0.23.0 // indirect + github.com/go-openapi/swag v0.22.5 // indirect + github.com/go-openapi/validate v0.22.4 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.19.0 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/google/go-cmp v0.6.0 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/gruntwork-io/terratest v0.46.13 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-retryablehttp v0.7.5 // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/jinzhu/copier v0.4.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/oklog/ulid v1.3.1 // indirect + github.com/opentracing/opentracing-go v1.2.0 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/skeema/knownhosts v1.2.2 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect + go.mongodb.org/mongo-driver v1.14.0 // indirect + go.opentelemetry.io/otel v1.16.0 // indirect + go.opentelemetry.io/otel/metric v1.16.0 // indirect + go.opentelemetry.io/otel/trace v1.16.0 // indirect + golang.org/x/crypto v0.22.0 // indirect + golang.org/x/mod v0.14.0 // indirect + golang.org/x/net v0.23.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.16.1 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/tests/pr_test.go b/tests/pr_test.go new file mode 100644 index 0000000..edcd18e --- /dev/null +++ b/tests/pr_test.go @@ -0,0 +1,39 @@ +package tests + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testprojects" + "os" + "testing" +) + +func TestProjectsFullTest(t *testing.T) { + + options := testprojects.TestProjectOptionsDefault(&testprojects.TestProjectsOptions{ + Testing: t, + StackConfigurationOrder: []string{ + "primary-da", + "secondary-da", + }, + }) + options.StackMemberInputs = map[string]map[string]interface{}{ + "primary-da": { + "prefix": fmt.Sprintf("p%s", options.Prefix), + }, + "secondary-da": { + "prefix": fmt.Sprintf("s%s", options.Prefix), + }, + } + options.StackInputs = map[string]interface{}{ + "resource_group_name": options.ResourceGroup, + "ibmcloud_api_key": os.Getenv("TF_VAR_ibmcloud_api_key"), + } + + err := options.RunProjectsTest() + if assert.NoError(t, err) { + t.Log("TestProjectsFullTest Passed") + } else { + t.Error("TestProjectsFullTest Failed") + } +}