73a91d233f
Bumps [github.com/hashicorp/hcl/v2](https://github.com/hashicorp/hcl) from 2.22.0 to 2.23.0. - [Release notes](https://github.com/hashicorp/hcl/releases) - [Changelog](https://github.com/hashicorp/hcl/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/hcl/compare/v2.22.0...v2.23.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/hcl/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> |
||
---|---|---|
.devcontainer | ||
.github | ||
bin/breaking_detect | ||
example | ||
.gitignore | ||
CODE_OF_CONDUCT.md | ||
LICENSE | ||
README.md | ||
SECURITY.md | ||
breakingchange.go | ||
breakingchange_test.go | ||
e2etest.go | ||
e2etest_test.go | ||
go.mod | ||
go.sum | ||
module.go | ||
retryable_errors.go | ||
retryable_errors_sample.hcl.json | ||
retryable_errors_test.go | ||
stream_logger.go | ||
stream_logger_test.go | ||
unittest.go | ||
unittest_test.go | ||
upgradetest.go | ||
upgradetest_test.go | ||
variable_file.go | ||
variable_file_test.go | ||
version_helper.go | ||
version_helper_test.go |
README.md
Azure Verified Terraform Module Test Helper
This repo contains two helper functions that were used to test Azure Verified Terraform Module.
For End-End test:
func TestExamplesStartup(t *testing.T) {
vars := map[string]interface{}{
"client_id": "",
"client_secret": "",
}
managedIdentityId := os.Getenv("MSI_ID")
if managedIdentityId != "" {
vars["managed_identity_principal_id"] = managedIdentityId
}
test_helper.RunE2ETest(t, "../../", "examples/startup", terraform.Options{
Upgrade: true,
Vars: vars,
}, func(t *testing.T, output test_helper.TerraformOutput) {
aksId, ok := output["test_aks_id"].(string)
assert.True(t, ok)
assert.Regexp(t, regexp.MustCompile("/subscriptions/.+/resourceGroups/.+/providers/Microsoft.ContainerService/managedClusters/.+"), aksId)
})
}
The RunE2ETest
function accept module's root path, sub-folder to example code that our test want to apply, a terraform.Options
argument, and an assertion callback.
In E2E test we apply the example code,then we execute terraform output
and pass the json format output to this assertion callback, you can assert whether the output meets your spec there.
For Version-Upgrade Test:
func TestExampleUpgrade_startup(t *testing.T) {
currentRoot, err := test_helper.GetCurrentModuleRootPath()
if err != nil {
t.FailNow()
}
currentMajorVersion, err := test_helper.GetCurrentMajorVersionFromEnv()
if err != nil {
t.FailNow()
}
vars := map[string]interface{}{
"client_id": "",
"client_secret": "",
}
managedIdentityId := os.Getenv("MSI_ID")
if managedIdentityId != "" {
vars["managed_identity_principal_id"] = managedIdentityId
}
test_helper.ModuleUpgradeTest(t, "Azure", "terraform-azurerm-aks", "examples/startup", currentRoot, terraform.Options{
Upgrade: true,
Vars: vars,
}, currentMajorVersion)
}
The ModuleUpgradeTest
function accept your Github repo's owner name (could be username or org name), repo name, sub-folder to example code, and module's current major version (eg: v3.0.0 major version is 3).
The ModuleUpgradeTest
function will clone and checkout the latest released tag version within the major version you've passed, apply the code in a temp directory, then modify the module's source to the current path, then execute terraform plan
to see if there would be any drift in the plan.