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

Making FAST stage 1 resman destroy process more reliable #1661

Closed
LucaPrete opened this issue Sep 8, 2023 · 2 comments
Closed

Making FAST stage 1 resman destroy process more reliable #1661

LucaPrete opened this issue Sep 8, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@LucaPrete
Copy link
Member

It happened to me multiple times that, when the FAST resman stage destroy process breaks half way through -for whatever reason- and I run terraform destroy again I get:

Error: Unsupported attribute
│
│   on outputs.tf line 226, in locals:
│  226:     tag_keys         = { for k, v in module.organization.tag_keys : k => v.id }
│     ├────────────────
│     │ module.organization is object with 8 attributes
│
│ This object does not have an attribute named "tag_keys".
╵
╷
│ Error: Unsupported attribute
│
│   on outputs.tf line 228, in locals:
│  228:     tag_values       = { for k, v in module.organization.tag_values : k => v.id }
│     ├────────────────
│     │ module.organization is object with 8 attributes
│
│ This object does not have an attribute named "tag_values".

I usually solve this adding a try in the related stage outputs:

...
tfvars = {
    folder_ids       = local.folder_ids
    service_accounts = local.service_accounts
    tag_keys         = { for k, v in try(module.organization.tag_keys, {}) : k => v.id }
    tag_names        = var.tag_names
    tag_values       = { for k, v in try(module.organization.tag_values, {}) : k => v.id }
  }
...

Before committing this fix, I was wondering if we can state why this happens and if we can make any change at the module level. Anyway, the organization module should at most return empty dictionaries, so I don't see anything wrong there:

output "tag_keys" {
  description = "Tag key resources."
  value = {
    for k, v in google_tags_tag_key.default : k => v if(
      v.purpose == null || v.purpose == ""
    )
  }
}

output "tag_values" {
  description = "Tag value resources."
  value = {
    for k, v in google_tags_tag_value.default :
    k => v if !local.tag_values[k].tag_network
  }
}

Thoughts?

@LucaPrete LucaPrete added the enhancement New feature or request label Sep 8, 2023
@LucaPrete LucaPrete changed the title Making destroy process more reliable Making FAST stage 1 resman destroy process more reliable Sep 8, 2023
@juliocc
Copy link
Collaborator

juliocc commented Sep 8, 2023

Before committing this fix, I was wondering if we can state why this happens and if we can make any change at the module level. Anyway, the organization module should at most return empty dictionaries, so I don't see anything wrong there:

I've seen this happen before and I know the fix is to add a try, but I've never understood why it happens. +1 to try to figure it out and document it.

@ludoo
Copy link
Collaborator

ludoo commented Sep 8, 2023

This happens for several things during destroy, there are try statements scattered throughout the codebase to deal with this, but we add them piecemeal only after we see errors. So I don't have a good explanation on the why, but the proposed fixes are good. :)

@LucaPrete LucaPrete assigned LucaPrete and unassigned ludoo and juliocc Sep 8, 2023
LucaPrete added a commit that referenced this issue Sep 8, 2023
Co-authored-by: Luca Prete <lucaprete@google.com>
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

3 participants