diff --git a/pkg/testskeleton/testskeleton.go b/pkg/testskeleton/testskeleton.go index 05f5b62..ddf1cbb 100644 --- a/pkg/testskeleton/testskeleton.go +++ b/pkg/testskeleton/testskeleton.go @@ -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" @@ -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 {