Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Namegenerator functions refactor #12

Merged
merged 7 commits into from
Sep 25, 2023
51 changes: 15 additions & 36 deletions pkg/testskeleton/testskeleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,47 +58,25 @@ type AdditionalChangesAfterDeployment struct {
ChangedResources []ChangedResource
}

// Structure used for AWS deployments - contains randomly generated resource names.
type AwsRandomNames struct {
NamePrefix string
// Structure used for terraform tfvars input information,
// not all options are used in all public cloud environments
type TerraformVarsInfo struct {
NamePrefix string
AzureResourceGroupName string
AzureStorageAccountName string
GoogleProjectId string
}

// Function that generates and returns a set of random AWS resource names.
// Randomization is based on UUID.
func GenerateAwRandomNames() AwsRandomNames {
// Function that generates and returns information used by Terraform TFVARS.
func GenerateTerraformVarsInfo() TerraformVarsInfo {
prid := os.Getenv("PRID")
if prid != "" {
prid = fmt.Sprintf("p%s", prid)
} else {
prid = "tt"
}

id := uuid.New().String()
idSliced := strings.Split(id, "-")

prefixId := idSliced[2]

names := AwsRandomNames{
NamePrefix: fmt.Sprintf("%s-%s-", prid, prefixId),
}

return names
}

// 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 {
prid := os.Getenv("PRID")
if prid != "" {
prid = fmt.Sprintf("-pr%s-", prid)
}
projectId := os.Getenv("PROJECT_ID")

id := uuid.New().String()
idSliced := strings.Split(id, "-")
Expand All @@ -107,10 +85,11 @@ func GenerateAzureRandomNames() AzureRandomNames {
gid := idSliced[0:2]
storageId := idSliced[3:5]

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

return names
Expand Down