Skip to content

Commit 120abc7

Browse files
committed
vm: Add AdditionalUnattendContent on Windows machines
This commit adds functionality for automatically running C:\AzureData\CustomData.bin on first boot. This file is provided via the user data secret, and contains init scripts. The Windows Machine Config Operator relies on the user data script being executed automatically on the Windows VM to set up SSH access. On AWS, it is invoked automatically after provisioning. This commit is intended to align Azure with that behavior.
1 parent 7276393 commit 120abc7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pkg/cloud/azure/services/virtualmachines/virtualmachines.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,39 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error {
126126
if compute.OperatingSystemTypes(vmSpec.OSDisk.OSType) == compute.Windows {
127127
osProfile.WindowsConfiguration = &compute.WindowsConfiguration{
128128
EnableAutomaticUpdates: to.BoolPtr(false),
129+
AdditionalUnattendContent: &[]compute.AdditionalUnattendContent{
130+
{
131+
PassName: "OobeSystem",
132+
ComponentName: "Microsoft-Windows-Shell-Setup",
133+
SettingName: "AutoLogon",
134+
Content: to.StringPtr(`
135+
<AutoLogon>
136+
<Username>` + *osProfile.AdminUsername + `</Username>
137+
<Password>
138+
<Value>` + *osProfile.AdminPassword + `</Value>
139+
</Password>
140+
<Enabled>true</Enabled>
141+
<LogonCount>1</LogonCount>
142+
</AutoLogon>
143+
`),
144+
},
145+
{
146+
PassName: "OobeSystem",
147+
ComponentName: "Microsoft-Windows-Shell-Setup",
148+
SettingName: "FirstLogonCommands",
149+
Content: to.StringPtr(`
150+
<FirstLogonCommands>
151+
<SynchronousCommand wcm:action="add">
152+
<Description>Launch custom data scripts</Description>
153+
<CommandLine>
154+
if exist C:\AzureData\CustomData.bin powershell.exe -encodedcommand (Get-Content 'C:\AzureData\CustomData.bin' -Raw)
155+
</CommandLine>
156+
<Order>1</Order>
157+
</SynchronousCommand>
158+
</FirstLogonCommands>
159+
`),
160+
},
161+
},
129162
}
130163
} else if sshKeyData != "" {
131164
osProfile.LinuxConfiguration = &compute.LinuxConfiguration{

0 commit comments

Comments
 (0)