Skip to content

Commit

Permalink
feat(testskeleton.go): introduce UUID generation required by Azure Te…
Browse files Browse the repository at this point in the history
…rratest implementation (#3)
  • Loading branch information
FoSix authored Aug 21, 2023
1 parent b32df3d commit 3993a9b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/testskeleton/testskeleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"testing"

"github.com/google/uuid"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/terraform"
tfjson "github.com/hashicorp/terraform-json"
Expand Down Expand Up @@ -57,6 +58,48 @@ type AdditionalChangesAfterDeployment struct {
ChangedResources []ChangedResource
}

// Structure used for Azure deployments - contains randomly generated resource names.
type AzureRandomNames struct {
NamePrefix string
ResourceGroupName string
StorageAccountName string
}

// Function that generates and returns a set of random Azure resource names.
// Randomization is based on UUID.
func GenerateAzureRandomNames() AzureRandomNames {
id := uuid.New().String()
idSliced := strings.Split(id, "-")

prefixId := idSliced[2]
gid := idSliced[0:2]
storageId := idSliced[3:5]

names := AzureRandomNames{
NamePrefix: fmt.Sprintf("ghci%s-", prefixId),
ResourceGroupName: strings.Join(gid, ""),
StorageAccountName: fmt.Sprintf("ghci%s", strings.Join(storageId, "")),
}

return names
}

// Function running only only code validation.
func ValidateCode(t *testing.T, terraformOptions *terraform.Options) *terraform.Options {
if terraformOptions == nil {
terraformOptions = terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: ".",
Logger: logger.Default,
Lock: true,
Upgrade: true,
})
}

terraform.InitAndValidate(t, terraformOptions)

return terraformOptions
}

// Function is responsible for deployment of the infrastructure,
// verify assert expressions and destroy infrastructure
func DeployInfraCheckOutputs(t *testing.T, terraformOptions *terraform.Options, assertList []AssertExpression) *terraform.Options {
Expand Down

0 comments on commit 3993a9b

Please sign in to comment.