FlexibleEngineCloud / terraform-provider-flexibleengine

Terraform flexibleengine provider
https://www.terraform.io/docs/providers/flexibleengine/
Mozilla Public License 2.0
30 stars 53 forks source link

[CBR] auto_expand generates changes #1093

Closed But4ler closed 7 months ago

But4ler commented 7 months ago

Hi

Terraform Version

terraform --version
Terraform v1.6.6
on linux_amd64
+ provider registry.terraform.io/flexibleenginecloud/flexibleengine v1.45.0

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

variable "vm_list_regex" {
  type = map(string)
  default = {
    "clouds" = "^cloud-(?!k8s).*$",
    "dt_generic" = "^dt-(?!gitlab).*$",
    "gitlab" = "^dt-gitlab.*$"
  }
}

# CBR Vault

resource "flexibleengine_cbr_policy" "ecs_policy" {
  name  = "ecs_policy_business_days_21h"
  type  = "backup"
  time_period = 1

  # execution_times est en UTC
  backup_cycle {
    # days = "MO,TU,WE,TH,FR,SA,SU"
    days = "MO,TU,WE,TH,FR"
    execution_times = ["21:00"]
  }
}

resource "flexibleengine_cbr_vault" "vault" {
  for_each = data.flexibleengine_compute_instances.get_vms_regex

  name            = "vault_${each.key}"
  type            = "server"
  protection_type = "backup"
  size            = 50
  auto_expand     = true

  dynamic "resources" {
    for_each = toset(each.value.instances[*].id)
    content {
      server_id = resources.key
    }
  }

  policy {
    id = flexibleengine_cbr_policy.ecs_policy.id
  }
}

Expected Behavior

Terraform should not affect the size of the Vault, as the auto_expand option is set to true.

Actual Behavior

Terraform wants to restore the initial Vault size, but does not take into account the current Vault size with auto_expand set to true.

  # flexibleengine_cbr_vault.vault["clouds"] will be updated in-place
  ~ resource "flexibleengine_cbr_vault" "vault" {
        id                    = "axxxxx"
        name                  = "vault_clouds"
      ~ size                  = 75 -> 50
        tags                  = {}
        # (13 unchanged attributes hidden)

        # (8 unchanged blocks hidden)
    }

  # flexibleengine_cbr_vault.vault["gitlab"] will be updated in-place
  ~ resource "flexibleengine_cbr_vault" "vault" {
        id                    = "cxxxxx"
        name                  = "vault_gitlab"
      ~ size                  = 96 -> 50
        tags                  = {}
        # (13 unchanged attributes hidden)

Thanks

ShiChangkuo commented 7 months ago

@But4ler auto_expand will update the size of CBR vault, so I suggest ignoring the changes as follows:

resource "flexibleengine_cbr_vault" "test" {
    ...

  lifecycle {
    ignore_changes = [ size ]
  }
}
But4ler commented 7 months ago

Hello Thanks, good solution !