private void EnableWinRMCustomDataAndUnattendContent(string rgName, string keyVaultName, string winRMCertificateUrl, string autoLogonContent, VirtualMachine inputVM) { var osProfile = inputVM.OsProfile; osProfile.CustomData = CustomData; osProfile.WindowsConfiguration = new WindowsConfiguration { ProvisionVMAgent = true, EnableAutomaticUpdates = false, TimeZone = PacificStandardTime, AdditionalUnattendContent = new List <AdditionalUnattendContent> { new AdditionalUnattendContent { PassName = OOBESystem, ComponentName = MicrosoftWindowsShellSetup, SettingName = AutoLogon, Content = autoLogonContent } }, WinRM = new WinRMConfiguration { Listeners = new List <WinRMListener> { new WinRMListener { Protocol = ProtocolTypes.Http, CertificateUrl = null, }, new WinRMListener { Protocol = ProtocolTypes.Https, CertificateUrl = winRMCertificateUrl, } } } }; osProfile.Secrets = new List <VaultSecretGroup> { new VaultSecretGroup { SourceVault = SecretVaultHelper.GetVaultId(m_subId, rgName, keyVaultName).Result, VaultCertificates = new List <VaultCertificate> { new VaultCertificate { CertificateStore = "My", CertificateUrl = winRMCertificateUrl } } } }; }
public void TestVMWithWindowsOSProfile() { using (var context = UndoContext.Current) { context.Start(); EnsureClientsInitialized(); string rgName = TestUtilities.GenerateName(TestPrefix); string keyVaultName = TestUtilities.GenerateName(TestPrefix); string winRMCertificateBase64 = Convert.ToBase64String( Encoding.UTF8.GetBytes( ReadFromEmbeddedResource(typeof(OSProfileTests), WinRMCertificateResourceName))); // The following variables are defined here to allow validation string autoLogonContent = null; Uri winRMCertificateUrl = SecretVaultHelper.AddSecret(m_subId, rgName, keyVaultName, winRMCertificateBase64).Result; Action <VirtualMachine> enableWinRMCustomDataAndUnattendContent = inputVM => { autoLogonContent = GetAutoLogonContent(5, inputVM.OSProfile.AdminUsername, inputVM.OSProfile.AdminPassword); EnableWinRMCustomDataAndUnattendContent(rgName, keyVaultName, winRMCertificateUrl, autoLogonContent, inputVM); }; Action <VirtualMachine> validateWinRMCustomDataAndUnattendContent = outputVM => ValidateWinRMCustomDataAndUnattendContent(rgName, keyVaultName, winRMCertificateUrl, autoLogonContent, outputVM); SecretVaultHelper.CreateKeyVault(m_subId, rgName, keyVaultName).Wait(); TestVMWithOSProfile( rgName: rgName, useWindowsProfile: true, vmCustomizer: enableWinRMCustomDataAndUnattendContent, vmValidator: validateWinRMCustomDataAndUnattendContent); SecretVaultHelper.DeleteKeyVault(m_subId, rgName, keyVaultName).Wait(); } }