Skip to content

Commit

Permalink
azure: use user-data or custom-data
Browse files Browse the repository at this point in the history
It's possible to use one or the other using the `UseUserData` Azure
option.

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
  • Loading branch information
tormath1 committed Nov 22, 2022
1 parent 6957a22 commit 7e156f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 19 additions & 5 deletions platform/api/azure/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func (a *API) getVMParameters(name, userdata, sshkey, storageAccountURI string,
},
},
}
if userdata != "" {
ud := base64.StdEncoding.EncodeToString([]byte(userdata))
osProfile.CustomData = &ud
}

// Encode userdata to base64.
ud := base64.StdEncoding.EncodeToString([]byte(userdata))

var imgRef *compute.ImageReference
var plan *compute.Plan
if a.opts.DiskURI != "" {
Expand All @@ -77,7 +77,7 @@ func (a *API) getVMParameters(name, userdata, sshkey, storageAccountURI string,
Name: imgRef.Sku,
}
}
return compute.VirtualMachine{
vm := compute.VirtualMachine{
Name: &name,
Location: &a.opts.Location,
Tags: map[string]*string{
Expand Down Expand Up @@ -118,6 +118,20 @@ func (a *API) getVMParameters(name, userdata, sshkey, storageAccountURI string,
},
},
}

// I don't think it would be an issue to have empty user-data set but better
// to be safe than sorry.
if ud != "" {
if a.Opts.UseUserData {
plog.Infof("using user-data")
vm.VirtualMachineProperties.UserData = &ud
} else {
plog.Infof("using custom data")
vm.VirtualMachineProperties.OsProfile.CustomData = &ud
}
}

return vm
}

func (a *API) CreateInstance(name, userdata, sshkey, resourceGroup, storageAccount string, network Network) (*Machine, error) {
Expand Down
2 changes: 2 additions & 0 deletions platform/api/azure/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ type Options struct {

// Azure Storage API endpoint suffix. If unset, the Azure SDK default will be used.
StorageEndpointSuffix string
// UseUserData can be use to enable custom data only or user-data only.
UseUserData bool
}

0 comments on commit 7e156f8

Please sign in to comment.