Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hcibox deployment experience - small improvements #2395

Merged
merged 10 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ Write-Host 'Creating credentials and connecting to Azure'
$azureAppCred = (New-Object System.Management.Automation.PSCredential $env:spnClientID, (ConvertTo-SecureString -String $env:spnClientSecret -AsPlainText -Force))
Connect-AzAccount -ServicePrincipal -Subscription $env:subscriptionId -Tenant $env:spnTenantId -Credential $azureAppCred

# Check that extensions are finished installing on HCI nodes
# foreach ($node in $HCIBoxConfig.NodeHostConfig) {

# }

# Install some modules
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name Az.Resources -Force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function GenerateAnswerFile {
)

$formattedMAC = Get-FormattedWACMAC -HCIBoxConfig $HCIBoxConfig
$encodedPassword = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($($HCIBoxConfig.SDNAdminPassword) + "AdministratorPassword"))
$wacAnswerXML = @"
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
Expand Down Expand Up @@ -150,8 +151,8 @@ function GenerateAnswerFile {
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserAccounts>
<AdministratorPassword>
<Value>$($HCIBoxConfig.SDNAdminPassword)</Value>
<PlainText>true</PlainText>
<PlainText>false</PlainText>
<Value>$encodedPassword</Value>
</AdministratorPassword>
</UserAccounts>
<TimeZone>UTC</TimeZone>
Expand Down Expand Up @@ -283,8 +284,8 @@ $components</settings>
</OOBE>
<UserAccounts>
<AdministratorPassword>
<Value>$($HCIBoxConfig.SDNAdminPassword)</Value>
<PlainText>true</PlainText>
<PlainText>false</PlainText>
<Value>$encodedPassword</Value>
</AdministratorPassword>
</UserAccounts>
</component>
Expand Down Expand Up @@ -1537,9 +1538,9 @@ else {
Write-Error "GUI.vhdx is corrupt. Aborting deployment. Re-run C:\HCIBox\HCIBoxLogonScript.ps1 to retry"
throw
}
# BITSRequest -Params @{'Uri'='https://partner-images.canonical.com/hyper-v/desktop/focal/current/ubuntu-focal-hyperv-amd64-ubuntu-desktop-hyperv.vhdx.zip'; 'Filename'="$($HCIBoxConfig.Paths.VHDDir)\Ubuntu.vhdx.zip"}
# Expand-Archive -Path "$($HCIBoxConfig.Paths.VHDDir)\Ubuntu.vhdx.zip" -DestinationPath $($HCIBoxConfig.Paths.VHDDir)
# Move-Item -Path "$($HCIBoxConfig.Paths.VHDDir)\livecd.ubuntu-desktop-hyperv.vhdx" -Destination "$($HCIBoxConfig.Paths.VHDDir)\Ubuntu.vhdx"
BITSRequest -Params @{'Uri'='https://partner-images.canonical.com/hyper-v/desktop/focal/current/ubuntu-focal-hyperv-amd64-ubuntu-desktop-hyperv.vhdx.zip'; 'Filename'="$($HCIBoxConfig.Paths.VHDDir)\Ubuntu.vhdx.zip"}
Expand-Archive -Path "$($HCIBoxConfig.Paths.VHDDir)\Ubuntu.vhdx.zip" -DestinationPath $($HCIBoxConfig.Paths.VHDDir)
Move-Item -Path "$($HCIBoxConfig.Paths.VHDDir)\livecd.ubuntu-desktop-hyperv.vhdx" -Destination "$($HCIBoxConfig.Paths.VHDDir)\Ubuntu.vhdx"

# Set credentials
$localCred = new-object -typename System.Management.Automation.PSCredential `
Expand Down
2 changes: 1 addition & 1 deletion azure_jumpstart_hcibox/artifacts/hci.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
"identity": {
"type": "SystemAssigned"
},
"location": "[parameters('location')]",
"location": "eastus",
"properties": {
}
},
Expand Down
18 changes: 8 additions & 10 deletions azure_jumpstart_hcibox/scripts/preprovision.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ Write-Host "Connecting to Azure..."
# Install Azure module if not already installed
if (-not (Get-Command -Name Get-AzContext)) {
Write-Host "Installing Azure module..."
Install-Module -Name Az -AllowClobber -Scope CurrentUser -ErrorAction Stop
Install-Module -Name Az -AllowClobber -Scope CurrentUser -Force -ErrorAction Stop
}

# If not signed in, run the Connect-AzAccount cmdlet
if (-not (Get-AzContext)) {
Write-Host "Logging in to Azure..."
Write-Host "Logging in to Azure with subscription id $env:AZURE_SUBSCRIPTION_ID"
If (-not (Connect-AzAccount -SubscriptionId $env:AZURE_SUBSCRIPTION_ID -ErrorAction Stop)){
Throw "Unable to login to Azure. Please check your credentials and try again."
}
}
$tenantId = (Get-AzContext).tenant.id
# Write-Host "Setting Azure context..."
$context = Set-AzContext -SubscriptionId $env:AZURE_SUBSCRIPTION_ID -Tenant $tenantId -ErrorAction Stop
Write-Host "Setting Azure context with subscription id $env:AZURE_SUBSCRIPTION_ID and tenant id $tenantId..."
$context = Set-AzContext -SubscriptionId $env:AZURE_SUBSCRIPTION_ID -ErrorAction Stop

# Write-Host "Setting az subscription..."
az account set --subscription $env:AZURE_SUBSCRIPTION_ID
Expand Down Expand Up @@ -165,7 +165,7 @@ azd env set JS_RDP_PORT $JS_RDP_PORT

# Attempt to retrieve provider id for Microsoft.AzureStackHCI
Write-Host "Attempting to retrieve Microsoft.AzureStackHCI provider id..."
$spnProviderId=$(az ad sp list --display-name "Microsoft.AzureStackHCI") | ConvertFrom-Json
$spnProviderId=$(az ad sp list --display-name "Microsoft.AzureStackHCI" --output json) | ConvertFrom-Json
if ($null -ne $spnProviderId.id) {
azd env set SPN_PROVIDER_ID -- $($spnProviderId.id)
}
Expand All @@ -177,7 +177,7 @@ Write-Host "Checking for existing stored Azure service principal..."
if ($null -ne $env:SPN_CLIENT_ID) {
Write-Host "Re-using existing service principal..."
} else {
Write-Host "Attempting to create new service principal..."
Write-Host "Attempting to create new service principal with scope /subscriptions/$($env:AZURE_SUBSCRIPTION_ID)..."
$user = (Get-AzContext).Account.Id.split("@")[0]
$uniqueSpnName = "$user-jumpstart-spn-$(Get-Random -Minimum 1000 -Maximum 9999)"
try {
Expand All @@ -191,14 +191,12 @@ if ($null -ne $env:SPN_CLIENT_ID) {
azd env set SPN_TENANT_ID -- $SPN_TENANT_ID
}
catch {

If ($error[0].ToString() -match "Forbidden"){
Throw "You do not have permission to create a service principal. Please contact your Azure subscription administrator to grant you the Owner role on the subscription."
}
elseif ($error[0].ToString() -match "credentials") {
Throw "Please run Connect-AzAccount to sign in and run 'azd up' again."
}
else {
Throw "An error occurred creating the service principal. Please try again."
Throw "An error occurred creating the service principal. Error:" + $error[0].ToString()
}
}

Expand Down