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

Powershell Changes for Security Type #37

Draft
wants to merge 5 commits into
base: generation
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ function New-AzMigrateServerReplication {
# Specifies the Operating System disk for the source server to be migrated.
${OSDiskID},

[ValidateSet("Standard" , "TrustedLaunch")]
[ArgumentCompleter( { "Standard" , "TrustedLaunch" })]
[Microsoft.Azure.PowerShell.Cmdlets.Migrate.Category('Path')]
[System.String]
# Specifies the security type for the Azure VM.
${TargetSecurityType},

[ValidateSet("true" , "false")]
[ArgumentCompleter( { "true" , "false" })]
[Microsoft.Azure.PowerShell.Cmdlets.Migrate.Category('Path')]
[System.String]
# Specifies if secure boot needs to be enabled on target VM.
${TargetVMSecureBootEnabled},

[Parameter(ParameterSetName = 'ByIdDefaultUser')]
[Parameter(ParameterSetName = 'ByInputObjectDefaultUser')]
[Microsoft.Azure.PowerShell.Cmdlets.Migrate.Category('Path')]
Expand Down Expand Up @@ -261,6 +275,8 @@ function New-AzMigrateServerReplication {
$HasResync = $PSBoundParameters.ContainsKey('PerformAutoResync')
$HasDiskEncryptionSetID = $PSBoundParameters.ContainsKey('DiskEncryptionSetID')
$HasTargetVMSize = $PSBoundParameters.ContainsKey('TargetVMSize')
$HasTargetSecurityType = $PSBoundParameters.ContainsKey('TargetSecurityType')
$HasTargetVMSecureBootEnabled = $PSBoundParameters.ContainsKey('TargetVMSecureBootEnabled')

$null = $PSBoundParameters.Remove('ReplicationContainerMapping')
$null = $PSBoundParameters.Remove('VMWarerunasaccountID')
Expand All @@ -286,6 +302,8 @@ function New-AzMigrateServerReplication {
$null = $PSBoundParameters.Remove('SqlServerLicenseType')
$null = $PSBoundParameters.Remove('LicenseType')
$null = $PSBoundParameters.Remove('DiskEncryptionSetID')
$null = $PSBoundParameters.Remove('TargetSecurityType')
$null = $PSBoundParameters.Remove('TargetVMSecureBootEnabled')

$null = $PSBoundParameters.Remove('MachineId')
$null = $PSBoundParameters.Remove('InputObject')
Expand Down Expand Up @@ -426,7 +444,7 @@ function New-AzMigrateServerReplication {
if ($FabricName -eq "") {
throw "Fabric not found for given resource group."
}

$null = $PSBoundParameters.Add('FabricName', $FabricName)
$peContainers = Az.Migrate\Get-AzMigrateReplicationProtectionContainer @PSBoundParameters
$ProtectionContainerName = ""
Expand Down Expand Up @@ -539,6 +557,19 @@ public static int hashForArtifact(String artifact)
$ProviderSpecificDetails.InstanceType = 'VMwareCbt'
$ProviderSpecificDetails.LicenseType = $LicenseType
$ProviderSpecificDetails.PerformAutoResync = $PerformAutoResync
if ($HasTargetVMSecureBootEnabled) {
$ProviderSpecificDetails.TargetVMSecurityProfileIsTargetVmsecureBootEnabled = $TargetVMSecureBootEnabled
} elseif ($TargetSecurityType -eq "TrustedLaunch") {
$ProviderSpecificDetails.TargetVMSecurityProfileIsTargetVmsecureBootEnabled = "true"
}

if ($HasTargetSecurityType -and $TargetSecurityType -ne "Standard") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if SecureBoot is not passed and SecurityType is TrustedLaunch?
Do we need to keep default value of SecureBoot as True or throw error asking user to provide SecureBoot input? Check with PM.

$ProviderSpecificDetails.TargetVMSecurityProfileTargetVmsecurityType = $TargetSecurityType
$ProviderSpecificDetails.TargetVMSecurityProfileIsTargetVmtpmEnabled = $true
} elseif ($HasTargetVMSecureBootEnabled) {
throw "SecureBoot is supported only when security type is trusted launch virtual machine."
}

if ($HasTargetAVSet) {
$ProviderSpecificDetails.TargetAvailabilitySetId = $TargetAvailabilitySet
}
Expand Down Expand Up @@ -639,6 +670,7 @@ public static int hashForArtifact(String artifact)
}

Import-Module Az.Resources
Import-Module Az.Compute

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove if not required.

$vmId = $ProviderSpecificDetails.TargetResourceGroupId + "/providers/Microsoft.Compute/virtualMachines/" + $TargetVMName
$VMNamePresentinRg = Get-AzResource -ResourceId $vmId -ErrorVariable notPresent -ErrorAction SilentlyContinue
if ($VMNamePresentinRg) {
Expand All @@ -664,9 +696,6 @@ public static int hashForArtifact(String artifact)
$DiskObject.IsOSDisk = "false"
$DiskObject.LogStorageAccountSasSecretName = $LogStorageAccountSas
$DiskObject.LogStorageAccountId = $LogStorageAccountID
if ($HasDiskEncryptionSetID) {
$DiskObject.DiskEncryptionSetId = $DiskEncryptionSetID
}
$DiskToInclude += $DiskObject
}
}
Expand Down Expand Up @@ -719,7 +748,5 @@ public static int hashForArtifact(String artifact)
$null = $PSBoundParameters.Add('ResourceGroupName', $ResourceGroupName)

return Az.Migrate.internal\Get-AzMigrateReplicationJob @PSBoundParameters

}

}
}