Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cloud/azure/actuators/machine/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ func (s *Reconciler) createVirtualMachine(ctx context.Context, nicName string) e

var detailedError autorest.DetailedError
if errors.As(err, &detailedError) && detailedError.Message == "Failure sending request" {
return machinecontroller.InvalidMachineConfiguration("failure sending request for machine %s", s.scope.Machine.Name)
return machinecontroller.InvalidMachineConfiguration("failure sending request for machine %s: %v", s.scope.Machine.Name, err)
}
return fmt.Errorf("failed to create or get machine: %w", err)
}
Expand Down
42 changes: 42 additions & 0 deletions pkg/cloud/azure/services/virtualmachines/virtualmachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ import (
"sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/services/networkinterfaces"
)

const (
// winAutoLogonFormatString is the format string used to create the AutoLogon
// AdditionalUnattendContent configuration for Windows machines.
winAutoLogonFormatString = `<AutoLogon>
<Username>%s</Username>
<Password>
<Value>%s</Value>
</Password>
<Enabled>true</Enabled>
<LogonCount>1</LogonCount>
</AutoLogon>`

// winFirstLogonCommandsString is the string used to create the FirstLogonCommands
// AdditionalUnattendContent configuration for Windows machines.
winFirstLogonCommandsString = `<FirstLogonCommands>
<SynchronousCommand>
<Description>Copy user data secret contents to init script</Description>
<CommandLine>cmd /c "copy C:\AzureData\CustomData.bin C:\init.ps1"</CommandLine>
<Order>11</Order>
</SynchronousCommand>
<SynchronousCommand>
<Description>Launch init script</Description>
<CommandLine>powershell.exe -NonInteractive -ExecutionPolicy Bypass -File C:\init.ps1</CommandLine>
<Order>12</Order>
</SynchronousCommand>
</FirstLogonCommands>`
)

// Spec input specification for Get/CreateOrUpdate/Delete calls
type Spec struct {
Name string
Expand Down Expand Up @@ -126,6 +154,20 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error {
if compute.OperatingSystemTypes(vmSpec.OSDisk.OSType) == compute.Windows {
osProfile.WindowsConfiguration = &compute.WindowsConfiguration{
EnableAutomaticUpdates: to.BoolPtr(false),
AdditionalUnattendContent: &[]compute.AdditionalUnattendContent{
{
PassName: "OobeSystem",
ComponentName: "Microsoft-Windows-Shell-Setup",
SettingName: "AutoLogon",
Content: to.StringPtr(fmt.Sprintf(winAutoLogonFormatString, *osProfile.AdminUsername, *osProfile.AdminPassword)),
},
{
PassName: "OobeSystem",
ComponentName: "Microsoft-Windows-Shell-Setup",
SettingName: "FirstLogonCommands",
Content: to.StringPtr(winFirstLogonCommandsString),
},
},
}
} else if sshKeyData != "" {
osProfile.LinuxConfiguration = &compute.LinuxConfiguration{
Expand Down