2016-03-04 05:14:55 -05:00
|
|
|
package arm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-07-11 18:32:45 -04:00
|
|
|
"strings"
|
2016-03-04 05:14:55 -05:00
|
|
|
|
2018-09-03 08:26:07 -04:00
|
|
|
"github.com/hashicorp/packer/common/random"
|
2016-03-04 05:14:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type TempName struct {
|
2016-04-21 19:50:03 -04:00
|
|
|
AdminPassword string
|
|
|
|
CertificatePassword string
|
|
|
|
ComputeName string
|
|
|
|
DeploymentName string
|
|
|
|
KeyVaultName string
|
|
|
|
ResourceGroupName string
|
|
|
|
OSDiskName string
|
2018-03-10 14:17:43 -05:00
|
|
|
NicName string
|
|
|
|
SubnetName string
|
|
|
|
PublicIPAddressName string
|
|
|
|
VirtualNetworkName string
|
2016-03-04 05:14:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewTempName() *TempName {
|
|
|
|
tempName := &TempName{}
|
|
|
|
|
2018-09-05 04:26:52 -04:00
|
|
|
suffix := random.AlphaNumLower(10)
|
2016-03-04 05:14:55 -05:00
|
|
|
tempName.ComputeName = fmt.Sprintf("pkrvm%s", suffix)
|
|
|
|
tempName.DeploymentName = fmt.Sprintf("pkrdp%s", suffix)
|
2016-04-21 19:50:03 -04:00
|
|
|
tempName.KeyVaultName = fmt.Sprintf("pkrkv%s", suffix)
|
2016-03-04 05:14:55 -05:00
|
|
|
tempName.OSDiskName = fmt.Sprintf("pkros%s", suffix)
|
2018-03-10 14:17:43 -05:00
|
|
|
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)
|
2016-03-04 05:14:55 -05:00
|
|
|
tempName.ResourceGroupName = fmt.Sprintf("packer-Resource-Group-%s", suffix)
|
|
|
|
|
2018-07-11 18:32:45 -04:00
|
|
|
tempName.AdminPassword = generatePassword()
|
2018-09-03 08:26:07 -04:00
|
|
|
tempName.CertificatePassword = random.AlphaNum(32)
|
2016-03-04 05:14:55 -05:00
|
|
|
|
|
|
|
return tempName
|
|
|
|
}
|
2018-07-11 18:32:45 -04:00
|
|
|
|
|
|
|
// generate a password that is acceptable to Azure
|
|
|
|
// Three of the four items must be met.
|
|
|
|
// 1. Contains an uppercase character
|
|
|
|
// 2. Contains a lowercase character
|
|
|
|
// 3. Contains a numeric digit
|
|
|
|
// 4. Contains a special character
|
|
|
|
func generatePassword() string {
|
|
|
|
var s string
|
|
|
|
for i := 0; i < 100; i++ {
|
2018-09-03 08:26:07 -04:00
|
|
|
s := random.AlphaNum(32)
|
2018-09-05 04:26:52 -04:00
|
|
|
if !strings.ContainsAny(s, random.PossibleNumbers) {
|
2018-07-11 18:32:45 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-09-05 04:26:52 -04:00
|
|
|
if !strings.ContainsAny(s, random.PossibleLowerCase) {
|
2018-07-11 18:32:45 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-09-05 04:26:52 -04:00
|
|
|
if !strings.ContainsAny(s, random.PossibleUpperCase) {
|
2018-07-11 18:32:45 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// if an acceptable password cannot be generated in 100 tries, give up
|
|
|
|
return s
|
|
|
|
}
|