MagaluCloud / terraform-provider-mgc

Magalu Cloud terraform provider
https://docs.magalu.cloud/docs/terraform/overview
8 stars 1 forks source link

Falha ao trocar associate_public_ip de false para true #6

Closed gomex closed 4 months ago

gomex commented 5 months ago

Como reproduzir:

Cria um recurso com esse código:

resource "mgc_virtual-machine_instances" "basic_instance" {
  name = "basic-instance"
  machine_type = {
    name = "cloud-bs1.xsmall"
  }
  image = {
    name = "cloud-ubuntu-22.04 LTS"
  }
  network = {
    associate_public_ip = false
  }
  delete_public_ip = false
  ssh_key_name     = "gomex"
}

Ele dará esse retorno no plan/apply:

Terraform will perform the following actions:

  # mgc_virtual-machine_instances.basic_instance will be created
  + resource "mgc_virtual-machine_instances" "basic_instance" {
      + availability_zone    = (known after apply)
      + created_at           = (known after apply)
      + current_image        = (known after apply)
      + current_machine_type = (known after apply)
      + current_name         = (known after apply)
      + current_network      = (known after apply)
      + current_ssh_key_name = (known after apply)
      + delete_public_ip     = false
      + error                = (known after apply)
      + id                   = (known after apply)
      + image                = {
          + name = "cloud-ubuntu-22.04 LTS"
        }
      + machine_type         = {
          + name = "cloud-bs1.xsmall"
        }
      + name                 = "basic-instance"
      + network              = {
          + associate_public_ip = false
        }
      + ssh_key_name         = "gomex"
      + state                = (known after apply)
      + status               = (known after apply)
      + updated_at           = (known after apply)
      + user_data            = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Depois troque a opção delete_public_ip de false para true e execute o plan/apply novamente, o retorno do plan será o seguinte:

mgc_virtual-machine_instances.basic_instance: Refreshing state... [id=ad5570f6-1d8b-4756-a4a3-19b279401b94]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # mgc_virtual-machine_instances.basic_instance must be replaced
-/+ resource "mgc_virtual-machine_instances" "basic_instance" {
      + availability_zone    = (known after apply) # forces replacement
      ~ created_at           = "2024-06-12T19:17:38Z" -> (known after apply)
      ~ current_image        = {
          ~ id       = "96ba4819-5e3b-47e5-8f65-b3f0a70b01a7" -> (known after apply)
          + name     = (known after apply)
          + platform = (known after apply)
        } -> (known after apply)
      ~ current_machine_type = {
          + disk  = (known after apply)
          ~ id    = "fb634f1c-4280-4acb-b9a4-24dea423a9a6" -> (known after apply)
          + name  = (known after apply)
          + ram   = (known after apply)
          + vcpus = (known after apply)
        } -> (known after apply)
      ~ current_name         = "basic-instance" -> (known after apply)
      ~ current_network      = {
          ~ object1 = {
              ~ ports = [
                  - {
                      - id = "378814c7-5f65-4d67-b86f-7e89da51e7ad" -> null
                    },
                ] -> (known after apply)
            } -> (known after apply)
          + object2 = (known after apply)
        } -> (known after apply)
      ~ current_ssh_key_name = "gomex" -> (known after apply)
      + error                = (known after apply)
      ~ id                   = "ad5570f6-1d8b-4756-a4a3-19b279401b94" -> (known after apply)
        name                 = "basic-instance"
      ~ network              = {
          ~ associate_public_ip = false -> true
        }
      ~ state                = "running" -> (known after apply)
      ~ status               = "completed" -> (known after apply)
      ~ updated_at           = "2024-06-12T19:17:54Z" -> (known after apply)
      + user_data            = (known after apply) # forces replacement
        # (4 unchanged attributes hidden)
    }

Plan: 1 to add, 0 to change, 1 to destroy.

Ao rodar o apply o retorno deveria ser que a máquina foi destruída e recriar com sucesso, mas o retorno é esse:

mgc_virtual-machine_instances.basic_instance: Destroying... [id=ad5570f6-1d8b-4756-a4a3-19b279401b94]
mgc_virtual-machine_instances.basic_instance: Destruction complete after 0s
mgc_virtual-machine_instances.basic_instance: Creating...
╷
│ Error: Unable to create mgc_virtual-machine_instances
│ 
│   with mgc_virtual-machine_instances.basic_instance,
│   on main.tf line 1, in resource "mgc_virtual-machine_instances" "basic_instance":
│    1: resource "mgc_virtual-machine_instances" "basic_instance" {
│ 
│ Service returned with error: (generic) 400 Bad Request - Instance: 'basic-instance' already exists (request-id: aa25ba4d-e678-4560-847e-53f633d88f5b)

Algo na API está liberando o terraform pra criar a instância sem ter removido o registro do nome da instância, dessa forma, como o nome é único ele da erro ao recriar.

antonionovaesjr commented 5 months ago

Vamos trocar experiências https://t.me/openmagalucloud

publi0 commented 4 months ago

Corrigido na ultima versão 0.21.0