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

Cannot remove project and profile associated to project at the same time #183

Open
cquike opened this issue Dec 9, 2024 · 1 comment
Open
Labels
Incomplete Waiting on more information from reporter

Comments

@cquike
Copy link

cquike commented Dec 9, 2024

I have a project that I deleted in my main.tf. There is a profile which associated to several projects using something like:

 resource "incus_profile" "my_profile" {
  for_each = toset([ "project1", "project2" ])
   name        = "my_profile"
   project     = each.key

When I remove project2 from main.tf and also project2 in the for_each mentioned in the profile I get an error:

Plan: 0 to add, 0 to change, 2 to destroy.
incus_project.testp: Destroying... [name=project2]
incus_profile.my_profile["project2"]: Destroying... [name=my_profile]
incus_profile.my_profile["project2"]: Destruction complete after 1s

Error: Failed to remove project "project2"

Only empty projects can be removed.

I guess the problem is that it is trying to remove the project before removing the profile.

This is not a big deal, since the next time I run tofu apply it worked, since the profile has already been removed, but I just wanted to report it as it would be a nice improvement that the dependencies between profiles and projects are tracked properly.

@stgraber
Copy link
Member

So this may be a Terraform config issue. When you just set project to each.key in this case with the set passed to for_each being just a list of strings, Terraform has no way to model the relationship between that incus_profile entry and the incus_project.

Instead doing:

for_each tosset([incus_project.project1.name, incus_project.project2.name])

Would have provided the relationship data needed for Terraform to understand that this profile depends on the project and should therefore be deleted prior to the project.

I seem to remember seeing a depends_on statement that you can use too for those few cases where you can't have it built for you through references.

@stgraber stgraber added the Incomplete Waiting on more information from reporter label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Incomplete Waiting on more information from reporter
Development

No branches or pull requests

2 participants