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 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
7 changes: 2 additions & 5 deletions azure_jumpstart_hcibox/artifacts/PowerShell/Bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ Start-Transcript -Path "$($HCIBoxConfig.Paths["LogsDir"])\Bootstrap.log"
Write-Host "Extending C:\ partition to the maximum size"
Resize-Partition -DriveLetter C -Size $(Get-PartitionSupportedSize -DriveLetter C).SizeMax

# Installing Posh-SSH PowerShell Module
# Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

# Installing tools
Write-Header "Installing Chocolatey Apps"
try {
Expand Down Expand Up @@ -210,5 +207,5 @@ Install-WindowsFeature -Name Hyper-V -IncludeAllSubFeature -IncludeManagementToo
# Clean up Bootstrap.log
Write-Header "Clean up Bootstrap.log."
Stop-Transcript
$logSuppress = Get-Content $($HCIBoxConfig.Paths["LogsDir"])\Bootstrap.log | Where-Object { $_ -notmatch "Host Application: powershell.exe" }
$logSuppress | Set-Content $($HCIBoxConfig.Paths["LogsDir"])\Bootstrap.log -Force
$logSuppress = Get-Content $($HCIBoxConfig.Paths.LogsDir)\Bootstrap.log | Where-Object { $_ -notmatch "Host Application: powershell.exe" }
$logSuppress | Set-Content $($HCIBoxConfig.Paths.LogsDir)\Bootstrap.log -Force
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ 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
Install-Module Az.ConnectedMachine -Force
Install-Module -Name Az.Resources -AllowClobber -Force
Install-Module -Name Az.ConnectedMachine -AllowClobber -Force
Import-Module -Name Az.Resources, Az.ConnectedMachine -Force

# Add necessary role assignments
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
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
16 changes: 7 additions & 9 deletions azure_jumpstart_hcibox/scripts/preprovision.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ if (-not (Get-Command -Name Get-AzContext)) {

# 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