@@ -75,13 +75,6 @@ function New-AzAksArcCluster {
7575 [System.String ]
7676 # ARM Id of the extended location.
7777 ${CustomLocationName} ,
78-
79- [Parameter (Mandatory )]
80- [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
81- [System.String ]
82- # List of ARM resource Ids (maximum 1) for the infrastructure network object e.g.
83- # /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHCI/logicalNetworks/{logicalNetworkName}
84- ${VnetId} ,
8578
8679 [Parameter ()]
8780 [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
@@ -92,15 +85,21 @@ function New-AzAksArcCluster {
9285 [Parameter ()]
9386 [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
9487 [System.String ]
95- # Location
9688 ${Location} ,
9789
9890 [Parameter ()]
9991 [AllowEmptyCollection ()]
10092 [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
10193 [System.String []]
10294 ${AdminGroupObjectID} ,
103-
95+
96+ [Parameter (ParameterSetName = ' CreateExpanded' )]
97+ [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
98+ [System.String ]
99+ # List of ARM resource Ids (maximum 1) for the infrastructure network object e.g.
100+ # /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHCI/logicalNetworks/{logicalNetworkName}
101+ ${VnetId} ,
102+
104103 [Parameter (ParameterSetName = ' CreateExpanded' )]
105104 [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
106105 [System.String ]
@@ -126,7 +125,7 @@ function New-AzAksArcCluster {
126125 # The version of Kubernetes in use by the provisioned cluster.
127126 ${KubernetesVersion} ,
128127
129- [Parameter ()]
128+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
130129 [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
131130 [System.Management.Automation.SwitchParameter ]
132131 # Indicates whether Azure Hybrid Benefit is opted in.
@@ -190,12 +189,9 @@ function New-AzAksArcCluster {
190189 [Parameter (ParameterSetName = ' AutoScaling' , Mandatory )]
191190 [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
192191 [System.Management.Automation.SwitchParameter ]
193- # Indicates whether to enable NFS CSI Driver.
194- # The default value is true.
195192 ${EnableAutoScaling} ,
196193
197194 [Parameter (ParameterSetName = ' CreateExpanded' )]
198- [Parameter (ParameterSetName = ' AutoScaling' , Mandatory )]
199195 [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Path' )]
200196 [System.Int32 ]
201197 ${MaxPod} ,
@@ -410,36 +406,10 @@ function New-AzAksArcCluster {
410406 )
411407
412408 process {
413- $Scope = GetConnectedClusterResourceURI - SubscriptionId $SubscriptionId - ResourceGroupName $ResourceGroupName - ClusterName $ClusterName
414- $null = $PSBoundParameters.Remove (" SubscriptionId" )
415- $null = $PSBoundParameters.Remove (" ResourceGroupName" )
416- $null = $PSBoundParameters.Remove (" ClusterName" )
417- $null = $PSBoundParameters.Add (" ConnectedClusterResourceUri" , $Scope )
418-
419- # Network Validations
420- # Logical Network
421- if (($PSBoundParameters.ContainsKey (' ControlPlaneIP' )) -And ($VnetId -match $logicalNetworkArmIDRegex )) {
422- $response = Invoke-AzRestMethod - Path " $VnetId /?api-version=2024-01-01" - Method GET
423- if ($response.StatusCode -eq 200 ) {
424- $lnet = ($response.Content | ConvertFrom-Json )
425- $err = ValidateLogicalNetwork - lnet $lnet - ControlPlaneIP $ControlPlaneIP
426- if ($err ) {
427- throw $err
428- }
429- } else {
430- throw " Logical network with ID $VnetId not found."
431- }
432- }
433-
434- # Edit parameters
435- $null = $PSBoundParameters.Add (" InfraNetworkProfileVnetSubnetId" , @ ($VnetId ))
436- $null = $PSBoundParameters.Add (" ExtendedLocationType" , " CustomLocation" )
437- $null = $PSBoundParameters.Add (" NetworkProfileNetworkPolicy" , " calico" )
438- $null = $PSBoundParameters.Remove (" Location" )
439- $null = $PSBoundParameters.Remove (" VnetId" )
440-
441- $CustomLocationID = ConvertCustomLocationNameToID - CustomLocationName $CustomLocationName - SubscriptionId $SubscriptionId - ResourceGroupName $ResourceGroupName
442- $null = $PSBoundParameters.Add (" ExtendedLocationName" , $CustomLocationID )
409+ # Get custom location resource ID.
410+ $CustomLocationID = ConvertCustomLocationNameToID - CustomLocationName $CustomLocationName `
411+ - SubscriptionId $SubscriptionId `
412+ - ResourceGroupName $ResourceGroupName
443413 $null = $PSBoundParameters.Remove (" CustomLocationName" )
444414
445415 # Create connected cluster parent resource
@@ -450,56 +420,82 @@ function New-AzAksArcCluster {
450420 } elseif ($Location -ne $cllocation ) {
451421 throw " Location parameter must be equal to custom location's location $cllocation "
452422 }
453-
454- CreateConnectedCluster - SubscriptionId $SubscriptionId - ResourceGroupName $ResourceGroupName - ClusterName $ClusterName - Location $Location - AdminGroupObjectID $AdminGroupObjectID - EnableAzureRbac:$EnableAzureRbac
423+ $connectedCluster = CreateConnectedCluster - SubscriptionId $SubscriptionId `
424+ - ResourceGroupName $ResourceGroupName `
425+ - ClusterName $ClusterName `
426+ - Location $Location `
427+ - AdminGroupObjectID $AdminGroupObjectID `
428+ - EnableAzureRbac:$EnableAzureRbac
429+ $connectedClusterObject = $connectedCluster.Content | ConvertFrom-Json
430+ $null = $PSBoundParameters.Add (" ConnectedClusterResourceUri" , $connectedClusterObject.id )
431+ $null = $PSBoundParameters.Remove (" Location" )
455432 $null = $PSBoundParameters.Remove (" AdminGroupObjectID" )
456-
457- # Generate public ssh key if one is not provided
458- $SshPublicKeyObj = [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Models.LinuxProfilePropertiesSshPublicKeysItem ]::New()
459- if ($PSBoundParameters.ContainsKey (' SshKeyValue' )) {
460- $SshPublicKeyObj.KeyData = $SshKeyValue
461- } else {
462- $SshPublicKeyObj = GenerateSSHKey ClusterName $ClusterName
463- }
464- $null = $PSBoundParameters.Remove (" SshKeyValue" )
465- $null = $PSBoundParameters.Add (" SshPublicKey" , @ ($SshPublicKeyObj ))
466-
467- # Configure Agent Pool
468- $AgentPoolProfile = CreateAgentPoolProfile - EnableAutoScaling:$EnableAutoScaling - MinCount $MinCount - MaxCount $MaxCount - MaxPod $MaxPod - NodeTaint $NodeTaint - NodeLabel $NodeLabel
469- $null = $PSBoundParameters.Add (" AgentPoolProfile" , $AgentPoolProfile )
470-
471- if ($PSBoundParameters.ContainsKey (' EnableAzureHybridBenefit' )) {
472- $null = $PSBoundParameters.Remove (" EnableAzureHybridBenefit" )
473- }
474-
475- if ($PSBoundParameters.ContainsKey (' NodeTaint' )) {
476- $null = $PSBoundParameters.Remove (" NodeTaint" )
477- }
478-
479- if ($PSBoundParameters.ContainsKey (' NodeLabel' )) {
480- $null = $PSBoundParameters.Remove (" NodeLabel" )
481- }
482-
483- if ($PSBoundParameters.ContainsKey (' MinCount' )) {
484- $null = $PSBoundParameters.Remove (" MinCount" )
485- }
486-
487- if ($PSBoundParameters.ContainsKey (' MaxCount' )) {
488- $null = $PSBoundParameters.Remove (" MaxCount" )
489- }
490-
491- if ($PSBoundParameters.ContainsKey (' MaxPod' )) {
492- $null = $PSBoundParameters.Remove (" MaxPod" )
493- }
433+ $null = $PSBoundParameters.Remove (" EnableAzureRbac" )
434+ $null = $PSBoundParameters.Remove (" SubscriptionId" )
435+ $null = $PSBoundParameters.Remove (" ResourceGroupName" )
436+ $null = $PSBoundParameters.Remove (" ClusterName" )
494437
495- # Create Provisioned Cluster
496- if ($EnableAzureHybridBenefit ) {
497- $null = $PSBoundParameters.Add (" LicenseProfileAzureHybridBenefit" , $true )
498- } else {
499- $null = $PSBoundParameters.Add (" LicenseProfileAzureHybridBenefit" , $false )
438+ # TODO: If user passed in JsonFilePath or JsonString, let the back-end validate its correctness for now.
439+ # Below is validation for CreateExpanded parameter set.
440+ if (($PSCmdlet.ParameterSetName -ne " CreateViaJsonFilePath" ) -and ($PSCmdlet.ParameterSetName -ne " CreateViaJsonString" )) {
441+ # Edit parameters
442+ $null = $PSBoundParameters.Add (" InfraNetworkProfileVnetSubnetId" , @ ($VnetId ))
443+ $null = $PSBoundParameters.Remove (" VnetId" )
444+ $null = $PSBoundParameters.Add (" ExtendedLocationType" , " CustomLocation" )
445+ $null = $PSBoundParameters.Add (" NetworkProfileNetworkPolicy" , " calico" )
446+ $null = $PSBoundParameters.Add (" ExtendedLocationName" , $CustomLocationID )
447+
448+ # Generate public ssh key if one is not provided.
449+ $SshPublicKeyObj = [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Models.LinuxProfilePropertiesSshPublicKeysItem ]::New()
450+ if ($PSBoundParameters.ContainsKey (' SshKeyValue' )) {
451+ $SshPublicKeyObj.KeyData = $SshKeyValue
452+ } else {
453+ try {
454+ $SshPublicKeyObj = GenerateSSHKey ClusterName $ClusterName
455+ } catch {
456+ if ($_.Exception.Message -like " *ssh-keygen not found*" ) {
457+ throw " ssh-keygen command not found. Please install OpenSSH client tools and ensure ssh-keygen is in your PATH, or pass your SSH public key to the -SshKeyValue parameter."
458+ } else {
459+ throw $_.Exception.Message
460+ }
461+ }
462+ }
463+ $null = $PSBoundParameters.Remove (" SshKeyValue" )
464+ $null = $PSBoundParameters.Add (" SshPublicKey" , @ ($SshPublicKeyObj ))
465+
466+ # Configure Agent Pool
467+ $AgentPoolProfile = CreateAgentPoolProfile - EnableAutoScaling:$EnableAutoScaling `
468+ - MinCount $MinCount `
469+ - MaxCount $MaxCount `
470+ - MaxPod $MaxPod `
471+ - NodeTaint $NodeTaint `
472+ - NodeLabel $NodeLabel
473+ $null = $PSBoundParameters.Add (" AgentPoolProfile" , $AgentPoolProfile )
474+ $null = $PSBoundParameters.Remove (" EnableAutoScaling" )
475+
476+ if ($PSBoundParameters.ContainsKey (' MinCount' )) {
477+ $null = $PSBoundParameters.Remove (" MinCount" )
478+ }
479+ if ($PSBoundParameters.ContainsKey (' MaxCount' )) {
480+ $null = $PSBoundParameters.Remove (" MaxCount" )
481+ }
482+ if ($PSBoundParameters.ContainsKey (' MaxPod' )) {
483+ $null = $PSBoundParameters.Remove (" MaxPod" )
484+ }
485+ if ($EnableAzureHybridBenefit ) {
486+ $null = $PSBoundParameters.Add (" LicenseProfileAzureHybridBenefit" , " True" )
487+ $null = $PSBoundParameters.Remove (" EnableAzureHybridBenefit" )
488+ } else {
489+ $null = $PSBoundParameters.Add (" LicenseProfileAzureHybridBenefit" , " False" )
490+ }
491+ if ($PSBoundParameters.ContainsKey (' NodeTaint' )) {
492+ $null = $PSBoundParameters.Remove (" NodeTaint" )
493+ }
494+ if ($PSBoundParameters.ContainsKey (' NodeLabel' )) {
495+ $null = $PSBoundParameters.Remove (" NodeLabel" )
496+ }
500497 }
501-
502498 Az.AksArc.internal\New-AzAksArcCluster @PSBoundParameters
503499 }
504- }
500+ }
505501
0 commit comments