Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow renaming a folder name without destroying the folder #40

Closed
lemoo5sg opened this issue May 6, 2022 · 1 comment
Closed

Allow renaming a folder name without destroying the folder #40

lemoo5sg opened this issue May 6, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@lemoo5sg
Copy link

lemoo5sg commented May 6, 2022

TL;DR

If we rename a previously created folder through names variable, terraform will destroy the folder and recreate a new one, as the folder name is used as the for_each key.

Note 1: If after the initial creation, we have created resources under the folder such as projects, the deletion will fail and the renaming will never occur.
Note 2: the workaround to remove the folder from the state and delete the folder with manual action is not acceptable
Note 3: Also the potential workaround to add the new folder name as a new value in the list and keep the old name as it is is not acceptable as we do not want to keep a second folder, we need a renaming.

Terraform Resources

names = ["previous_name"]
changed to:
names = ["new_name"]

-------------------------------
Plan result:

# module.module1.google_folder.folders["previous_name"] will be destroyed
[...]
# module.module1.google_folder.folders["new_name"] will be created
[...]

Detailed design

The variables needs to be adapted to isolate the requested folder display name from the for_each resource key to allow renaming.

For example:
instead of flat names variable, use a list such as:
     names= [
                      {folder_key = "my_folder_1", folder_name= "requested_display_name"},
    ]

and for folders resource, replace toset with something similar to:
resource "google_folder" "folders" {
  for_each = {for folder in var.names:  folder.folder_key => folder}
  display_name = "${local.prefix}${each.value.folder_name}"

This way, when we change folder_name later to "new_name", we do not change folder_key, the state key is unchanged and the folder is renamed as expected.

Additional information

No response

@lemoo5sg lemoo5sg added the enhancement New feature or request label May 6, 2022
@morgante
Copy link
Contributor

morgante commented May 6, 2022

Duplicate of #38.

@morgante morgante closed this as completed May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants