azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

'az container create' does not support --tags

Open noelbundick opened this issue 8 years ago • 10 comments


Environment summary

MSI / 2.0.28 / Windows 1803.17107 / PowerShell

Feature request - update az container create to allow specifying tags upon creation

The REST API docs https://docs.microsoft.com/en-us/rest/api/container-instances/containergroups/createorupdate show that container groups themselves do support tags on PUT

Tags are commonly used by organizations for tracking metadata, such as internal billing info, which application a resource belongs to, etc. It would be great to be able to use tags with ACI on creation. Currently, users will have to drop down & use ARM templates or do a follow-up az resource tag operation

noelbundick avatar Mar 01 '18 19:03 noelbundick

Any updates on this? az resource tag doesn't work either.

That bug was opened over a year ago too. https://github.com/Azure/azure-cli/issues/8545

krknopp avatar Mar 02 '20 15:03 krknopp

any news?

derrix060 avatar Nov 05 '20 08:11 derrix060

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @dkkapur.

ghost avatar Nov 05 '20 11:11 ghost

this is pretty problematic.. we are using the tags to target a specific instance that is created with terraform. we update the ACI config from azure devops with the cli but this wipes the tags clean. changes in the tags actually forces terraform to recreate the instance. below is how it sortoff works, but it is quite some ceremony for restarting a container with an adjusted env var. notice the sleep command and the no-wait.

  1. when omitting the no-wait. the command waits for the container to be started (which also means it's pulled) which takes way to long keeping our build agent occupied.
  2. when omitting the sleep command the tags command doesn't have any effect (probably because az container create resets them afterwards).

the tags command exits with an error message but the tags are being set.

$configuration = az resource list --tag role=configuration | ConvertFrom-Json | Where-Object type -EQ "Microsoft.ContainerInstance/containerGroups"
if($configuration.Count -gt 0){
    $container = az container show --resource-group $configuration[0].resourceGroup --name $configuration[0].name | ConvertFrom-Json  
    Write-Host "Starting container"
    az container create `
        --no-wait `
        --resource-group $container.resourceGroup `
        --name $configuration[0].name `
        --registry-login-server $env:DOCKER_SERVER `
        --registry-username $env:DOCKER_USERNAME `
        --registry-password $env:DOCKER_PASSWORD `
        --image $image `
        --os-type Linux `
        --network-profile $container.networkProfile.id `
        --restart-policy $container.restartPolicy `
        --environment-variables VARIABLE_1=$var1`
    
    
    Write-Host "force wait"
    $wait = New-TimeSpan -Seconds 5
    Start-Sleep -Seconds  $wait.Seconds
    Write-Host "resetting tags"
    az resource tag --ids $configuration[0].id --tags role=configuration 
    
}

dgcaron avatar Dec 07 '20 09:12 dgcaron

how to set tags while creating with az container create?

jucabot avatar Dec 03 '21 12:12 jucabot

how to set tags while creating with az container create?

You can't via CLI, that's why this issue is opened :)

derrix060 avatar Dec 06 '21 00:12 derrix060

Any news on the subject?

amigotto avatar Apr 08 '22 08:04 amigotto

If anyone comes across this, it az resource tag does seem to work now:

az resource tag --tags vmlist=vm1 --ids /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}

# or

az resource tag --tags vmlist=vm1 --resource-group MyResourceGroup --name containerGroupName --resource-type "Microsoft.ContainerInstance/containerGroups"

nosvalds avatar Jun 16 '22 10:06 nosvalds

Using az resource tag --tags will work for subscriptions where tagging is not enforced with Azure Policy. This option needs to be added for such scenario where customers are enforcing tagging with Azure Policy which will block the creation of the container instance in the first place.

kabal2010 avatar Sep 28 '22 15:09 kabal2010

Any update on this?

mahinthan avatar Jan 18 '23 15:01 mahinthan

Any updates? This is a must-have for organisations enforcing tag policies on resource creation.

flaviocaduff avatar Feb 13 '23 13:02 flaviocaduff

Any update on this?

agyss avatar Aug 29 '23 14:08 agyss

Bumping this. Any update here?

adarshm-tb avatar Sep 02 '23 06:09 adarshm-tb

any update?

alexanu avatar Oct 19 '23 08:10 alexanu