Update builder/azure/arm/tempname.go

refactor the code.. thanks for the suggestion @sylviamoss

Co-Authored-By: Sylvia Moss <sylviamoss.m@gmail.com>
This commit is contained in:
vijayrajah 2020-04-17 00:04:39 +05:30 committed by GitHub
parent 9209826bfe
commit fff06353b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 26 deletions

View File

@ -26,33 +26,21 @@ type TempName struct {
func NewTempName(p string) *TempName {
tempName := &TempName{}
suffix := random.AlphaNumLower(5)
if p == "" {
suffix := random.AlphaNumLower(10)
tempName.ComputeName = fmt.Sprintf("pkrvm%s", suffix)
tempName.DeploymentName = fmt.Sprintf("pkrdp%s", suffix)
tempName.KeyVaultName = fmt.Sprintf("pkrkv%s", suffix)
tempName.OSDiskName = fmt.Sprintf("pkros%s", suffix)
tempName.NicName = fmt.Sprintf("pkrni%s", suffix)
tempName.PublicIPAddressName = fmt.Sprintf("pkrip%s", suffix)
tempName.SubnetName = fmt.Sprintf("pkrsn%s", suffix)
tempName.VirtualNetworkName = fmt.Sprintf("pkrvn%s", suffix)
tempName.NsgName = fmt.Sprintf("pkrsg%s", suffix)
tempName.ResourceGroupName = fmt.Sprintf("packer-Resource-Group-%s", suffix)
} else {
suffix := random.AlphaNumLower(5)
tempName.ComputeName = fmt.Sprintf("%svm%s", p, suffix)
tempName.DeploymentName = fmt.Sprintf("%sdp%s", p, suffix)
tempName.KeyVaultName = fmt.Sprintf("%skv%s", p, suffix)
tempName.OSDiskName = fmt.Sprintf("%sos%s", p, suffix)
tempName.NicName = fmt.Sprintf("%sni%s", p, suffix)
tempName.PublicIPAddressName = fmt.Sprintf("%sip%s", p, suffix)
tempName.SubnetName = fmt.Sprintf("%ssn%s", p, suffix)
tempName.VirtualNetworkName = fmt.Sprintf("%svn%s", p, suffix)
tempName.NsgName = fmt.Sprintf("%ssg%s", p, suffix)
tempName.ResourceGroupName = fmt.Sprintf("%s-Resource-Group-%s", p, suffix)
}
p = "pkr"
suffix = random.AlphaNumLower(10)
}
tempName.ComputeName = fmt.Sprintf("%svm%s", p, suffix)
tempName.DeploymentName = fmt.Sprintf("%sdp%s", p, suffix)
tempName.KeyVaultName = fmt.Sprintf("%skv%s", p, suffix)
tempName.OSDiskName = fmt.Sprintf("%sos%s", p, suffix)
tempName.NicName = fmt.Sprintf("%sni%s", p, suffix)
tempName.PublicIPAddressName = fmt.Sprintf("%sip%s", p, suffix)
tempName.SubnetName = fmt.Sprintf("%ssn%s", p, suffix)
tempName.VirtualNetworkName = fmt.Sprintf("%svn%s", p, suffix)
tempName.NsgName = fmt.Sprintf("%ssg%s", p, suffix)
tempName.ResourceGroupName = fmt.Sprintf("%s-Resource-Group-%s", p, suffix)
tempName.AdminPassword = generatePassword()
tempName.CertificatePassword = random.AlphaNum(32)