question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow generation of stable but unique name for resources

See original GitHub issue

Is your feature request related to a problem? Please describe. Generating globally unique names for resources that require a (globally unique) dns entry is challenging. In ARM templates, I would use the uniqueString function, seeding it with the “name” of the storage account (and possibly containing resource group name) that I want to create in order to get a “presudo-random” (but stable) name. Attempting to do so from a shell script is annoying.

Describe the solution you’d like It would be of a lot of value to expose the functionality from the az create commands - e.g. az storage account create -g somegroup -n somename --uniqify-name

Describe alternatives you’ve considered

  • Make name optional and default it to a uniqueString equivalent.
  • Provide an az name create --resource-group some group --name someame

Additional context

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jiaslicommented, Aug 25, 2021

@nthewara, currently there is no plan to implement such feature due to other high priority tasks. Also, adding --uniqify-name argument would require changes in all mgmt-plane commands’ --name arguments, or possibly even --vnet-name from az network vnet subnet create, --account-name from az storage container create. This will certainly make commands exponentially more complicated.

We recommend using your own hash function to achieve the same effect.

I wrote a sample Python script using hashlib and base64 to mimic the behavior of uniqueString:

# unique_string.py

import base64
import hashlib
import sys

str_to_hash = ''.join(sys.argv)

# Use sha1 algorithm to compute the hash in bytes
hash_bytes = hashlib.sha1(str_to_hash.encode()).digest()

# Compute the base32-encoded hash
hash_str = base64.b32encode(hash_bytes).decode()

# Only use the first 13 character
print(hash_str[:13].lower())

To invoke it:

# PowerShell

> python unique_string.py myresourcegroup mystorageaccount
k6b3wuaabd6k6

> $rg_id=az group show --name rg0823 --query id --output tsv
> python unique_string.py $rg_id
epthnx6bnawq7

Of course, you may tweak the script to customize it to suit your needs.

0reactions
nthewaracommented, Aug 22, 2021

@yonzhan @qianwens - Any update on this ? This would be good feature to have specifically when we need to re-run cli scripts

Read more comments on GitHub >

github_iconTop Results From Across the Web

Name generation pattern - Azure Resource Manager
Unique : Azure resource names need to be unique, but the scope of uniqueness depends on the resource. Deterministic: It's important that your ......
Read more >
Identifiers - AWS Cloud Development Kit (AWS CDK) v2
Unique IDs serve as the logical identifiers (or logical names) of resources in the generated AWS CloudFormation templates for constructs that represent AWS ......
Read more >
Projects - Argo CD - Declarative GitOps CD for Kubernetes
Projects provide the following features: restrict what may be deployed (trusted Git source repositories); restrict where apps may be deployed to (destination ...
Read more >
Best practices for using Terraform
To simplify conditional logic, give boolean variables positive names—for ... unique project ID and non-overlapping resource names within each project.
Read more >
Managing Resources
Because kubectl outputs resource names in the same syntax it accepts, ... The labels allow us to slice and dice our resources along...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found