azure-powershell
azure-powershell copied to clipboard
Az.App (Container App) feature - Secrets handling with cmdlets new-azcontainerappsecretobject & update-azcontainerapp
Description
How should one append a additional secret to an existing container app that is already one or several secrets assigned to it? If I manually configure multiple secrets to one container app - I can retrieve it using the corresponding get-azcontainerappsecret cmdlet. However, if I try to build a new secret object and then insert that secret using the update-azcontainerapp -ConfigurationSecret - it will overwrite existing secrets (no append avail). Please advice or confirm issue.
Script or Debug output
No response
Environment data
No response
Module versions
PS C:\Users\lawur> get-command *secre* | where {$_.Source -eq "Az.App"}
CommandType Name Version Source
----------- ---- ------- ------
Function Get-AzContainerAppManagedEnvDaprSecret 0.1.0 Az.App
Function Get-AzContainerAppSecret 0.1.0 Az.App
Function New-AzContainerAppSecretObject 0.1.0 Az.App
Error output
No response
@lijinpei2008 , could you help to look into it?
Hi @larswurm, You can solve the issue by using the following example:
$secretObject = Get-AzContainerAppSecret -ContainerAppName containerappName -ResourceGroupName testgroup
$newSecretObject = @(0..($secretObject.Count-1))
[array]::copy($secretObject,$newSecretObject,$secretObject.Count)
$secretObject += New-AzContainerAppSecretObject -Name "yourkey" -Value "yourvalue"
Update-AzContainerApp -ContainerAppName containerappName -ResourceGroupName testgroup -Location canadacentral -ConfigurationSecret $secretObject
Awesome - thanks for the feedback / example. Might be good as an example for the general public in order to accomplish (Add) since there is no add-azcontainerappsecret cmdlet as of now...
3 things we have learned from this case.
- We will add example to tell user how to use that.
- Cmdlet of Get should return a non-fixed size array. Then user can add new property just in one line. https://github.com/Azure/autorest.powershell/issues/978
- We will look into the usage of secret. If usage is high, we should introduce additional cmdlet to serve
Add-AzContainerAppSecretandRemove-AzContainerAppSecret
Hi @larswurm, You can solve the issue by using the following example:
$secretObject = Get-AzContainerAppSecret -ContainerAppName containerappName -ResourceGroupName testgroup $newSecretObject = @(0..($secretObject.Count-1)) [array]::copy($secretObject,$newSecretObject,$secretObject.Count) $secretObject += New-AzContainerAppSecretObject -Name "yourkey" -Value "yourvalue" Update-AzContainerApp -ContainerAppName containerappName -ResourceGroupName testgroup -Location canadacentral -ConfigurationSecret $secretObject
As per testing solution, I get error: InvalidOperation: Method invocation failed because [Microsoft.Azure.PowerShell.Cmdlets.App.Models.Api20220301.ContainerAppSecret] does not contain a method named 'op_Addition'.
Checking on $secretObject | gm
TypeName: Microsoft.Azure.PowerShell.Cmdlets.App.Models.Api20220301.ContainerAppSecret
Name MemberType Definition
Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToJson Method Microsoft.Azure.PowerShell.Cmdlets.App.Runtime.Json.JsonNode ToJson(Microsoft.Azure.PowerShell.Cmdlets.App.Runtime.Json.JsonObject… ToJsonString Method string ToJsonString() ToString Method string ToString() Name Property string Name {get;} Value Property string Value {get;}
A new version of Az.App has been released! (https://www.powershellgallery.com/packages/Az.App/1.0.0) Documentation has been updated, and hopefully the updated documentation will help you. https://learn.microsoft.com/en-us/powershell/module/az.app/update-azcontainerapp?view=azps-11.1.0#example-2-update-container-app