Skip to content

Commit

Permalink
Fix extension tests (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatagarwal-ibm authored Feb 8, 2024
1 parent 5842df6 commit a9635c4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
11 changes: 10 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>terraform-ibm-modules/common-dev-assets:commonRenovateConfig"]
"extends": ["github>terraform-ibm-modules/common-dev-assets:commonRenovateConfig"],
"packageRules": [
{
"description": "Do not allow SLZ version to be updated as we need to lock into version v5.1.1-rc",
"enabled": false,
"matchFileNames": [
"tests/resources/**"
]
}
]
}
31 changes: 25 additions & 6 deletions tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
package test

import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/require"
"os"
"strings"
"testing"

"github.com/gruntwork-io/terratest/modules/files"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper"
)

Expand Down Expand Up @@ -55,7 +61,7 @@ func TestRunSLZExample(t *testing.T) {
// Deploy SLZ ROKS Cluster first since it is needed for the WAS extension input
// ------------------------------------------------------------------------------------

prefix := fmt.Sprintf("was-slz-%s", strings.ToLower(random.UniqueId()))
prefix := fmt.Sprintf("was-%s", strings.ToLower(random.UniqueId()))
realTerraformDir := "./resources"
tempTerraformDir, _ := files.CopyTerraformFolderToTemp(realTerraformDir, fmt.Sprintf(prefix+"-%s", strings.ToLower(random.UniqueId())))
tags := common.GetTagsFromTravis()
Expand All @@ -79,14 +85,29 @@ func TestRunSLZExample(t *testing.T) {
},
// Set Upgrade to true to ensure latest version of providers and modules are used by terratest.
// This is the same as setting the -upgrade=true flag with terraform.
Upgrade: false,
Upgrade: true,
})

terraform.WorkspaceSelectOrNew(t, existingTerraformOptions, prefix)
_, existErr := terraform.InitAndApplyE(t, existingTerraformOptions)
if existErr != nil {
assert.True(t, existErr == nil, "Init and Apply of temp existing resource failed")
} else {
outputClusterJson := terraform.OutputJson(t, existingTerraformOptions, "cluster_data")

var clusterID string
var clusters []struct {
ClusterID string `json:"cluster_id"`
}
// Unmarshal the JSON data into the struct
if err := json.Unmarshal([]byte(outputClusterJson), &clusters); err != nil {
fmt.Println(err)
return
}
// Loop through the clusters and find the cluster_id
for _, cluster := range clusters {
clusterID = cluster.ClusterID
}

// ------------------------------------------------------------------------------------
// Deploy WAS extension
Expand All @@ -98,10 +119,8 @@ func TestRunSLZExample(t *testing.T) {
// Do not hard fail the test if the implicit destroy steps fail to allow a full destroy of resource to occur
ImplicitRequired: false,
TerraformVars: map[string]interface{}{
"prefix": prefix,
"region": region,
"resource_group": fmt.Sprintf("%s-was-rg", prefix),
"landing_zone_prefix": terraform.Output(t, existingTerraformOptions, "prefix"),
"cluster_id": clusterID,
"region": region,
},
})

Expand Down
3 changes: 1 addition & 2 deletions tests/resources/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
##############################################################################

module "landing_zone" {
source = "terraform-ibm-modules/landing-zone/ibm//patterns//roks//module"
version = "v5.1.1-rc"
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone//patterns//roks//module?ref=v5.1.1-rc"
region = var.region
prefix = var.prefix
tags = var.resource_tags
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ variable "region" {
variable "prefix" {
type = string
description = "Prefix to append to all resources created by this example"
default = "GoldenEye"
default = "was-slz"
}

variable "resource_tags" {
Expand Down

0 comments on commit a9635c4

Please sign in to comment.