Public/Set-DuneDeploymentTemplate.ps1
|
<# .SYNOPSIS Update a deployment template. .DESCRIPTION Updates allowed environments, allowed resource provider ids, disabled flag and other editable properties of a `DuneDeploymentTemplate`. Provide the template by `Id` or pass a `DuneDeploymentTemplate` object via pipeline. Observes `ShouldProcess`. .PARAMETER Id The GUID of the deployment template to update. Use the `Id` parameter set. .PARAMETER DeploymentTemplate A `DuneDeploymentTemplate` object supplied via pipeline to update. .PARAMETER AllowedEnvironments Array of allowed environments for the template. .PARAMETER AllowedResourceProviderIds Array of resource provider ids allowed for this template. .PARAMETER IsDisabled If set, the template will be marked disabled. .PARAMETER TxId Optional transaction id string sent to the API. .EXAMPLE PS> Set-DuneDeploymentTemplate -Id 3d8f6b5a-... -IsDisabled $true Disable the specified deployment template. .EXAMPLE PS> Get-DuneDeploymentTemplate -Name "webapp" | Set-DuneDeploymentTemplate -AllowedEnvironments Prod,Dev Pipeline example updating allowed environments. #> function Set-DuneDeploymentTemplate { [CmdletBinding( SupportsShouldProcess, ConfirmImpact = 'None', DefaultParameterSetName = "Id" )] param ( [Parameter(Mandatory, ParameterSetName = "Id")] [guid]$Id, [Parameter(Mandatory, ValueFromPipeline, ParameterSetName = "Object")] [DuneDeploymentTemplate]$DeploymentTemplate, # [Parameter()] # [string]$DisplayName, # [Parameter()] # [Environments]$DefaultEnvironment, [Parameter()] [Environments[]]$AllowedEnvironments, [Parameter()] [string[]]$AllowedResourceProviderIds = @(), [Parameter()] [bool]$IsDisabled, [Parameter()] [string]$TxId ) begin {} process { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)" if ($PSCmdlet.ParameterSetName -eq "Id") { $DeploymentTemplate = Get-DuneDeploymentTemplate -Id $DeploymentTemplate.Id } $PropertyUpdates = @() $ModifiedProperties = $PSBoundParameters.Keys | Where-Object { $_ -notin "Id","DeploymentTemplate" } if (-not $ModifiedProperties) { return } foreach ($Item in $ModifiedProperties) { if ($Item -eq 'DefaultEnvironment') { $PSBoundParameters.$Item = $PSBoundParameters.$Item.ToString() } if ($Item -eq 'AllowedResourceProviderIds') { $DeploymentTemplate | Add-Member -MemberType NoteProperty -Name AllowedResourceProviderIds -Value @(($DeploymentTemplate.AllowedResourceProviders).Id) } if ( ($DeploymentTemplate | Get-Member -MemberType *Property).Name -contains $Item -and ($PSBoundParameters.$Item -ne $DeploymentTemplate.$Item -or $Item -eq 'AllowedResourceProviderIds') ) { $DeploymentTemplate.$Item = $PSBoundParameters.$Item $PropertyUpdates += $PSBoundParameters.$Item } } if ($PropertyUpdates) { $Body = ConvertTo-Hashtable $DeploymentTemplate $Uri = 'deploymenttemplates/{0}' -f $DeploymentTemplate.Id if ($PSCmdlet.ShouldProcess($($PropertyUpdates | ConvertTo-Json -Depth 16 -Compress))) { $Null = Invoke-DuneApiRequest -Uri $Uri -Method PUT -Body $Body } } } end {} } |