cloudamqp / terraform-provider-cloudamqp

Terraform Provider for CloudAMQP
https://registry.terraform.io/providers/cloudamqp/cloudamqp
Mozilla Public License 2.0
35 stars 39 forks source link

Force recreate instances if switching plan from shared to dedicated or vice versa #49

Closed mantoine96 closed 4 years ago

mantoine96 commented 4 years ago

This PR intends on fixing this error:


[2020-04-03T09:12:39.202Z] Error: UpdateInstance failed, status: 422, message: map[error:Sorry, you can't move to a shared plan automatically. Please create a new instance.]

[2020-04-03T09:12:39.202Z] 

[2020-04-03T09:12:39.202Z]   on .terraform/modules/cloudamqp/modules/cloudamqp-cluster/main.tf line 29, in resource "cloudamqp_instance" "rmq_cluster":

[2020-04-03T09:12:39.202Z]   29: resource "cloudamqp_instance" "rmq_cluster" {}

In this case, I think it makes sense to force replacement if we switch from dedicated to shared plans, or vice versa.

i.e : switching from a bunny plan to a tiger should recreate the cloudamqp_instance

After writing those changes, I tested them with the code base that encountered the aforementioned error:

  # module.cloudamqp.cloudamqp_instance.rmq_cluster must be replaced
-/+ resource "cloudamqp_instance" "rmq_cluster" {
      ~ apikey      = (sensitive value)
      ~ host        = "eloquent-cat.rmq.cloudamqp.com" -> (known after apply)
      ~ id          = "90763" -> (known after apply)
        name        = "myservice"
        nodes       = 1
      ~ plan        = "bunny" -> "tiger" # forces replacement
      + ready       = (known after apply)
        region      = "amazon-web-services::ap-south-1"
        rmq_version = "3.7.21"
      ~ url         = (sensitive value)
      ~ vhost       = "ddqzsxzi" -> (known after apply)
    }
tbroden84 commented 4 years ago

I have tried out your PR and been switching between shared and dedicated and vice versa. Worked fine and didn't find any issues. Will merge your PR and thanks for the contribution.