set identity field in the template

This commit is contained in:
Feiyu Shi 2020-05-20 21:16:59 -07:00
parent d9c9bfbae8
commit 7c1a62dfed
2 changed files with 26 additions and 0 deletions

View File

@ -61,6 +61,10 @@ func GetVirtualMachineDeployment(config *Config) (*resources.Deployment, error)
builder.BuildWindows(config.tmpKeyVaultName, config.tmpWinRMCertificateUrl)
}
if len(config.UserAssignedManagedIdentities) != 0 {
builder.SetIdentity(config.UserAssignedManagedIdentities)
}
if config.ImageUrl != "" {
builder.SetImageUrl(config.ImageUrl, osType, config.diskCachingType)
} else if config.CustomManagedImageName != "" {

View File

@ -103,6 +103,28 @@ func (s *TemplateBuilder) BuildWindows(keyVaultName, winRMCertificateUrl string)
return nil
}
func (s *TemplateBuilder) SetIdentity(userAssignedManagedIdentities []string) error {
resource, err := s.getResourceByType(resourceVirtualMachine)
if err != nil {
return err
}
var id *Identity
if len(userAssignedManagedIdentities) != 0 {
id = &Identity{
Type: to.StringPtr("UserAssigned"),
UserAssignedIdentities: make(map[string]*UserAssignedIdentitiesValue),
}
for _, uid := range userAssignedManagedIdentities {
id.UserAssignedIdentities[uid] = &UserAssignedIdentitiesValue{}
}
}
resource.Identity = id
return nil
}
func (s *TemplateBuilder) SetManagedDiskUrl(managedImageId string, storageAccountType compute.StorageAccountTypes, cachingType compute.CachingTypes) error {
resource, err := s.getResourceByType(resourceVirtualMachine)
if err != nil {