sleuth-io/terraform-provider-sleuth

Removed project raises an error and causes Terraform to error instead of replacing the missing resource

Closed this issue · 4 comments

jjm commented

We are seeing errors like the following (as detailed in the support request):

Error: Project with slug `my-awesome-project` not found

If someone removes or renames a project in Sleuth that's been managed via Terraform. I think this is due to the following:

proj, err := c.GetProject(&projectSlug)
if err != nil {
return diag.FromErr(err)
}
setProjectFields(d, proj)

Raising an error, which errors the whole terraform plan over the correct way to set the Id to an empty string.

d.SetId("")
mrdon commented

Ok, so to make sure I got this, the code should detect when no project can be found, and if so, set the ID to nothing so it'll be created on the next run. That makes sense, but is that what you want, given that a user deleted the project in the UI?

jjm commented

It should show that the resource has gone, in the current state the pipeline is in an errored state and the only way out of this to either delete the items from state or recreate them so they are detected.

Ideally a UUID should be used for the Id in the terraform state, so that a rename would be detected and shown as being corrected on the next apply. The use of a text slug is quite brittle.

mrdon commented

The slug for Sleuth is immutable, so it should function the same as a UUID here. Renaming the project wouldn't change the slug. I'll create a PR for you to review

jjm commented

@mrdon Cheers, so if a project is renamed (by changing name) then the slug would stay the same? I've not tired doing a project rename in the UI.

If it needs a delete and a recreate I would suggest adding:

ForceNew:    true,

On those Schema items that need first a destroy and a re-create.