mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
242 stars 168 forks source link

importing existing cluster does not populate backup status #768

Closed bwoznicki closed 2 years ago

bwoznicki commented 2 years ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

terraform version 0.13.7
mongodb atlas provider version 1.3.1

Terraform Configuration File

// minimum setup to perform import
resource "mongodbatlas_cluster" "cluster-test" {
  project_id   = "project_id"
  name         = "cluster_name"
  provider_name               = "AWS"
  provider_instance_size_name = "M40"
  //cloud_backup = true
  //provider_backup_enabled = false
}

Steps to Reproduce

We have existing configuration that was deployed with mongodb atlas provider version 0.8.2 and in process of upgrading to 1.3.1. In the existing configuration we used provider_backup_enabled which is now renamed to cloud_backup for testing we have created a minimum config for the purpuse of import just to check existing values.

After running

terraform import mongodbatlas_cluster.cluster-test <project_id>-<cluster_name>

in state, the cloud_backup and provider_backup_enabled both have null values, resulting in the bellow plan output:

 # mongodbatlas_cluster.cluster-test will be updated in-place
  ~ resource "mongodbatlas_cluster" "cluster-test" {
        ...
      + cloud_backup                            = false
       ...
      + provider_backup_enabled                 = false

we have no intention of applying any changes just upgrading the provider. I know I can go and phisicaly add those values to state file, but the import should return current backup status, and not force user to still set value for provider_backup_enabled since that is now deprecated.

Expected Behavior

show difference in cloud_backup value, but suppress provider_backup_enabled. Since this is an import user should not be forced to apply anything

Actual Behavior

Terraform does not return actual status of backup, but if we run atlas CLI we can see that it is enabled. eg:

$ atlas cluster describe <my_cluster>
{
  "backupEnabled": true,
  "biConnector": {
    "enabled": false,
    "readPreference": "secondary"
  },
  "clusterType": "REPLICASET",
...

Debug Output

Crash Output

Additional Context

References

themantissa commented 2 years ago

@bwoznicki thank you for the report. We'll take a look and see if we can determine what's going on w/ the import here.

martinstibbe commented 2 years ago

@bwoznicki Confirmed that import state from 0.8.2 to newer version 1.4.5 in my test case "backup_enabled": false "cloud_backup": nullappears in the statefile after import completes no specific code in import function to manage cloud_backup and legacy provider_backup_enabled value

martinstibbe commented 2 years ago

@bwoznicki I was able with new release version (v1.4.6) 1) run a cluster build using 0.8.2 with provider_backup_enabled = true 2) delete cluster from state file 3) set version.tf to 1.4.6 from 0.8.2 for provider version 4) terraform init -upgrade 5) terraform import 6) comment out backup_enabled 7) set cloud_backup in tf file 8) terraform apply no changes detected cloud_backup set to match old value of provider_backup_enabled in statefile

martinstibbe commented 2 years ago

@bwoznicki v1.4.6 released feel free to test new release as it should correct this import issue