Public/Set-DuneDeployment.ps1
|
<# .SYNOPSIS Update properties of a deployment. .DESCRIPTION Updates one or more properties of a `DuneDeployment` via the corresponding API endpoints. Each property maps to a separate PATCH call (state, budget, display name/description, environment, needsAttention, tags). Provide the deployment by `Id` or pass a `DuneDeployment` object via pipeline. Observes `ShouldProcess`. To change the lifetime/expiry, use `Set-DuneDeploymentLifetime`. .PARAMETER Id The GUID of the deployment. Mandatory in the `Id` parameter set. .PARAMETER Deployment A `DuneDeployment` object; supports pipeline input. Mandatory in the `Object` parameter set. .PARAMETER State Set the deployment lifecycle state (value from the `LifecycleStates` enum). .PARAMETER MonthlyBudget Set the monthly budget amount. .PARAMETER BudgetWarningThresholdPercent Budget warning threshold as a percentage (0-100). .PARAMETER SendBudgetNotificationMails Enable or disable budget notification e-mails. .PARAMETER DisplayName Set the display name. .PARAMETER Description Set the description. .PARAMETER Environment Set the target environment (value from the `Environments` enum). .PARAMETER NeedsAttention Flag the deployment as needing attention. .PARAMETER Tags Set tags as an array of hashtables (each with Name and Value keys). .EXAMPLE PS> Set-DuneDeployment -Id 3d8f6b5a-... -State Deployed Set the deployment state to Deployed. .EXAMPLE PS> Get-DuneDeployment -Name "app" | Set-DuneDeployment -DisplayName "My App" -Description "Production app" Pipeline example updating display name and description. .EXAMPLE PS> Get-DuneDeployment -Name "app" | Set-DuneDeployment -MonthlyBudget 500 -BudgetWarningThresholdPercent 80 Set budget and warning threshold. .EXAMPLE PS> Get-DuneDeployment -Name "app" | Set-DuneDeployment -Tags @(@{Name="team";Value="platform"},@{Name="env";Value="prod"}) Set tags on a deployment. #> function Set-DuneDeployment { [CmdletBinding( SupportsShouldProcess, ConfirmImpact = 'None', DefaultParameterSetName = "Id" )] param ( [Parameter(Mandatory, ParameterSetName = "Id")] [guid]$Id, [Parameter(Mandatory, ValueFromPipeline, ParameterSetName = "Object")] [DuneDeployment]$Deployment, [Parameter()] [LifecycleStates]$State, [Parameter()] [double]$MonthlyBudget, [Parameter()] [long]$BudgetWarningThresholdPercent, [Parameter()] [bool]$SendBudgetNotificationMails, [Parameter()] [string]$DisplayName, [Parameter()] [string]$Description, [Parameter()] [Environments]$Environment, [Parameter()] [bool]$NeedsAttention, [Parameter()] [hashtable[]]$Tags ) begin {} process { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)" if ($PSCmdlet.ParameterSetName -eq "Id") { $Deployment = Get-DuneDeployment -Id $Id -ErrorAction Stop } $BaseUri = "deployments/{0}" -f $Deployment.Id # State if ($PSBoundParameters.ContainsKey('State')) { $Body = @{ State = $State.ToString() } if ($PSCmdlet.ShouldProcess($Deployment.Name, "Set State to '$State'")) { $Null = Invoke-DuneApiRequest -Uri "$BaseUri/state" -Method PATCH -Body $Body -ErrorAction Stop } } # Budget if ($PSBoundParameters.ContainsKey('MonthlyBudget') -or $PSBoundParameters.ContainsKey('BudgetWarningThresholdPercent') -or $PSBoundParameters.ContainsKey('SendBudgetNotificationMails')) { $Body = @{} if ($PSBoundParameters.ContainsKey('MonthlyBudget')) { $Body.MonthlyBudget = $MonthlyBudget } if ($PSBoundParameters.ContainsKey('BudgetWarningThresholdPercent')) { $Body.BudgetWarningThresholdPercent = $BudgetWarningThresholdPercent } if ($PSBoundParameters.ContainsKey('SendBudgetNotificationMails')) { $Body.SendBudgetNotificationMails = $SendBudgetNotificationMails } if ($PSCmdlet.ShouldProcess($Deployment.Name, "Set Budget")) { $Null = Invoke-DuneApiRequest -Uri "$BaseUri/budget" -Method PATCH -Body $Body -ErrorAction Stop } } # DisplayName / Description if ($PSBoundParameters.ContainsKey('DisplayName') -or $PSBoundParameters.ContainsKey('Description')) { $Body = @{} if ($PSBoundParameters.ContainsKey('DisplayName')) { $Body.DisplayName = $DisplayName } if ($PSBoundParameters.ContainsKey('Description')) { $Body.Description = $Description } if ($PSCmdlet.ShouldProcess($Deployment.Name, "Set DisplayName/Description")) { $Null = Invoke-DuneApiRequest -Uri "$BaseUri/displaynamedescription" -Method PATCH -Body $Body -ErrorAction Stop } } # Environment if ($PSBoundParameters.ContainsKey('Environment')) { $Body = @{ Environment = $Environment.ToString() } if ($PSCmdlet.ShouldProcess($Deployment.Name, "Set Environment to '$Environment'")) { $Null = Invoke-DuneApiRequest -Uri "$BaseUri/environment" -Method PATCH -Body $Body -ErrorAction Stop } } # NeedsAttention if ($PSBoundParameters.ContainsKey('NeedsAttention')) { $Body = @{ NeedsAttention = $NeedsAttention } if ($PSCmdlet.ShouldProcess($Deployment.Name, "Set NeedsAttention to '$NeedsAttention'")) { $Null = Invoke-DuneApiRequest -Uri "$BaseUri/needsattention" -Method PATCH -Body $Body -ErrorAction Stop } } # Tags if ($PSBoundParameters.ContainsKey('Tags')) { $Body = @{ Tags = $Tags } if ($PSCmdlet.ShouldProcess($Deployment.Name, "Set Tags")) { $Null = Invoke-DuneApiRequest -Uri "$BaseUri/tags" -Method PATCH -Body $Body -ErrorAction Stop } } } end {} } |