terraform-provider-mongodbatlas icon indicating copy to clipboard operation
terraform-provider-mongodbatlas copied to clipboard

Renaming a project forces replacement

Open nathankodilla opened this issue 4 years ago • 3 comments

Changing the name of a mongodbatlas_project causes a replacement which then trickles down and causes a replacement for all the clusters (and other resources) as well. A simple rename should not cause a replacement, as I can rename a project in the Atlas Web UI and it does not force anything to be recreated.

# module.name.mongodbatlas_project.main must be replaced
-/+ resource "mongodbatlas_project" "main" {
      ~ cluster_count = 1 -> (known after apply)
      ~ created       = "2019-11-01T23:57:42Z" -> (known after apply)
      ~ id            = "xxxxxxxxxxxx" -> (known after apply)
      ~ name          = "Old Name" -> "New Name" # forces replacement
        org_id        = "yyyyyyyyyyyyy"
    }

nathankodilla avatar Dec 11 '19 13:12 nathankodilla

@nathankodilla

The project rename is an Atlas UI feature and there is no public API to achieve this. Therefore, terraform is applying the changes in correct manner as it does not finds any reference to the old cluster name anywhere in the .tf file.

So, when the name is changed, terraform sees that you do not need the older project anymore and there is no reference to the old name in .tf files. Therefore, it deletes the entire project with the cluster(all the data gone) -> creates a new project -> launches the cluster(this will have no data).

@themantissa Please correct if I am wrong with this workflow.

nikhil-mongo avatar Dec 12 '19 05:12 nikhil-mongo

@nikhil-mongo thank you for helping and yes, I believe you are correct. There is no API method to update project names https://docs.atlas.mongodb.com/reference/api/projects/ hence we cannot support this in the Provider. However we should find a way to handle as deleting the project just by changing the name is not a desired behavior - @PacoDw @marinsalinas thoughts?

themantissa avatar Dec 12 '19 22:12 themantissa

I repro'ed changing the project name yesterday and Terraform properly notifies upon both plan and apply that changing the name will destroy all the related resources and create them again (it does not show anything changed). As I noted yesterday the API's Project resource has no PATCH method so while the name can be changed in the UI it cannot be done so by infrastructure managed by Terraform at this time (a request for a PATCH method has been submitted internally). We protect users from deleting a project with clusters in the UI and via the DELETE method for Projects, however in doing things the Terraform way it skips these checks. The team is investigating a way to protect users who miss the aforementioned Terraform feedback. In the mean time we will make it clear on the page for the Projects resources that the name cannot be changed via the Terraform provider without fully deleting and re-creating the project.

themantissa avatar Dec 13 '19 18:12 themantissa

Closing this issue out as actions taken seem to have prevented more pain in this area. We have an internal request to add a PATCH to project so we can implement with INTMDB-220. fyi @Zuhairahmed

themantissa avatar Oct 19 '22 19:10 themantissa

This is still the case in the latest provider version (1.8.2), API method to PATCH project name has been added: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Projects/operation/updateProject

nkkowa avatar Apr 25 '23 07:04 nkkowa

Thanks @nkkowa yes this is on our roadmap to support and should be out later this year for Terraform support. Feel free to create a new issue if you need anything else

Zuhairahmed avatar Apr 25 '23 16:04 Zuhairahmed