18

I would like to know if there is a way to rename an existing 'gcloud topic configurations' e.g. I would like rename 'foo' to 'bar' in the below example.

I couldn't find anything on this in the gcloud reference documents.

enter image description here

jayBana
  • 415
  • 4
  • 9

2 Answers2

33

Technically, it is not possible to change the name of that configuration using the gcloud command.

However, you can change it doing this little workaround:

  • Use gcloud config configurations activate [YOUR_CONFIG_NAME] to activate the configuration you wish.
  • Use gcloud info --format='get(config.paths.active_config_path)' to find the directory where your configurations are stored. You will get the path of the file of that specific configuration, looking like this /tmp/tmp.XAfddVDdg/configurations/[YOUR_CONFIG_NAME]
  • If you cd into the directory /tmp/tmp.XAfddVDdg/configurations/, you will find all your configurations there. Every configuration will be named there like this config_[YOUR_CONFIG_NAME]. Modifying the part that matches the name of your configuration will successfully change its name. DO NOT delete the config_ part of the name.
  • After this, is you print all the configurations using gcloud config configurations list, you will find your configuration renamed, but none will be active now. Just activate it with gcloud config configurations activate [YOUR_CONFIG_NAME], and you will be good to go.
  • Thank you. This is what I did shortly after asking this question with the only difference of activating another config set before renaming the one that I wanted to. This was to avoid any potential issues. – jayBana Mar 13 '19 at 20:45
  • Yes, I took the same precaution, that is why I wrote the first step. – Pablo Almécija Rodríguez Mar 14 '19 at 13:05
  • For me on Windows, the `--format` parameter doesn't work, but it's still pretty easy to pick out the file path from the resulting output. For windows users, the path should be similar to `C:\Users\USER\AppData\Roaming\gcloud\configurations\config_NAME` where `USER` is your username and `NAME` is the name of the configuration. – patricknelson Oct 15 '19 at 00:38
  • @chunk_split On Windows you should just use double quotes instead of single quotes. Like `gcloud info --format="get(config.paths.active_config_path)"`. – Ruslan Stelmachenko Dec 05 '19 at 06:50
  • More recent versions of glcoud on Linux store the configurations in `~/.config/gcloud/configurations/`. – aaron.cimolini Jan 12 '22 at 01:40
  • 1
    Brennan's answer should be the chosen one in 2022. – iPhoney Jul 04 '22 at 10:46
6

Don't know when this was added, but there is a remame command for configurations. So no more need to jump through hoops by deleting and recreating configurations or directly editing the file.

gcloud config configurations rename CONFIGURATION_NAME --new-name=NEW_NAME

https://cloud.google.com/sdk/gcloud/reference/config/configurations/rename

Brennan
  • 337
  • 5
  • 10