yandex-cloud / terraform-provider-yandex

Terraform Yandex provider
https://www.terraform.io/docs/providers/yandex/
Mozilla Public License 2.0
211 stars 116 forks source link

Ошибка при создании PostgreSQL Cluster с параметром planned_usage_threshold. Версия провайдера 0.117.0 #436

Closed totik234 closed 2 months ago

totik234 commented 6 months ago

Ошибка при создании PostgreSQL Cluster с параметром planned_usage_threshold

Error: Error while requesting API to create PostgreSQL Cluster: server-request-id = 2061f964-1d88-4769-a675-92cd55ce5356 server-trace-id = d579f0820e44382a:fc0309a5fe409984:d579f0820e44382a:1 client-request-id = 18d5309e-6c4f-486d-8141-04c65102d330 client-trace-id = f16cac3c-7af3-4c1d-b4f1-a65683c2aef8 rpc error: code = InvalidArgument desc = If planned usage threshold is set maintenance window must be specified.

Пример конфигурации

resource "yandex_mdb_postgresql_cluster" "this" {
  name                = "${var.cluster_name}-pg"
  environment         = var.environment
  network_id          = var.vpc_id
  deletion_protection = var.deletion_protection
  security_group_ids  = [yandex_vpc_security_group.pg_sg.id]

  config {
    version = 16
    resources {
      resource_preset_id = var.pg_cluster.resource_preset_id
      disk_type_id       = var.pg_cluster.disk_type_id
      disk_size          = var.pg_cluster.disk_size
    }
    disk_size_autoscaling {
      disk_size_limit = var.pg_cluster.disk_size_autoscaling.disk_size_limit
      planned_usage_threshold   = 75
      emergency_usage_threshold = 90
    }
    postgresql_config = {
      max_connections                = 395
      enable_parallel_hash           = true
      autovacuum_vacuum_scale_factor = 0.34
      default_transaction_isolation  = "TRANSACTION_ISOLATION_READ_COMMITTED"
      shared_preload_libraries       = "SHARED_PRELOAD_LIBRARIES_AUTO_EXPLAIN,SHARED_PRELOAD_LIBRARIES_PG_HINT_PLAN"
    }
  }

  maintenance_window {
    type = "WEEKLY"
    day  = "SUN"
    hour = 4
  }

  host {
    zone             = var.yc_zone
    subnet_id        = local.subnet_ids[0]
    assign_public_ip = false
  }
}

Так же если создать кластер без planned_usage_threshold, а потом его добавить все отрабатывает.

anbioZz commented 6 months ago

Ловим аналогичную ошибку (версия провайдера -- 0.117.0):

$ terraform apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # yandex_mdb_postgresql_cluster.pg-cluster-test will be created
  + resource "yandex_mdb_postgresql_cluster" "pg-cluster-test" {
      + created_at          = (known after apply)
      + deletion_protection = (known after apply)
      + environment         = "PRODUCTION"
      + folder_id           = (known after apply)
      + health              = (known after apply)
      + host_group_ids      = (known after apply)
      + host_master_name    = (known after apply)
      + id                  = (known after apply)
      + labels              = (known after apply)
      + name                = "test"
      + network_id          = (known after apply)
      + security_group_ids  = (known after apply)
      + status              = (known after apply)

      + config {
          + autofailover              = (known after apply)
          + backup_retain_period_days = (known after apply)
          + postgresql_config         = (known after apply)
          + version                   = "14"

          + disk_size_autoscaling {
              + disk_size_limit           = 50
              + emergency_usage_threshold = 90
              + planned_usage_threshold   = 70
            }

          + resources {
              + disk_size          = 16
              + disk_type_id       = "network-ssd"
              + resource_preset_id = "s2.micro"
            }
        }

      + host {
          + fqdn               = (known after apply)
          + replication_source = (known after apply)
          + role               = (known after apply)
          + subnet_id          = (known after apply)
          + zone               = "ru-central1-a"
        }

      + maintenance_window {
          + day  = "SAT"
          + hour = 12
          + type = "WEEKLY"
        }
    }

  # yandex_vpc_network.network-test will be created
  + resource "yandex_vpc_network" "network-test" {
      + created_at                = (known after apply)
      + default_security_group_id = (known after apply)
      + folder_id                 = (known after apply)
      + id                        = (known after apply)
      + labels                    = (known after apply)
      + name                      = (known after apply)
      + subnet_ids                = (known after apply)
    }

  # yandex_vpc_subnet.subnet-test will be created
  + resource "yandex_vpc_subnet" "subnet-test" {
      + created_at     = (known after apply)
      + folder_id      = (known after apply)
      + id             = (known after apply)
      + labels         = (known after apply)
      + name           = (known after apply)
      + network_id     = (known after apply)
      + v4_cidr_blocks = [
          + "10.5.0.0/24",
        ]
      + v6_cidr_blocks = (known after apply)
      + zone           = "ru-central1-a"
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

yandex_vpc_network.network-test: Creating...
yandex_vpc_network.network-test: Creation complete after 2s [id=enph7slsn081a675j1f4]
yandex_vpc_subnet.subnet-test: Creating...
yandex_vpc_subnet.subnet-test: Creation complete after 1s [id=e9bd6sqa2re74ca5fhgd]
yandex_mdb_postgresql_cluster.pg-cluster-test: Creating...
╷
│ Error: Error while requesting API to create PostgreSQL Cluster: server-request-id = 5847e7e2-73ef-4131-a91e-50c393e98d22 server-trace-id = cf88da70b1e31be5:9f2694499f52559b:cf88da70b1e31be5:1 client-request-id = 081569ec-2526-4a0a-8822-20ad8fcf270d client-trace-id = 47f18a53-56f0-439e-b2eb-01c0813b2914 rpc error: code = InvalidArgument desc = If planned usage threshold is set maintenance window must be specified.
│ 
│   with yandex_mdb_postgresql_cluster.pg-cluster-test,
│   on main.tf line 1, in resource "yandex_mdb_postgresql_cluster" "pg-cluster-test":
│    1: resource "yandex_mdb_postgresql_cluster" "pg-cluster-test" {
│ 
╵
Denchick commented 6 months ago

Привет! Да, это баг. Обсудим в команде как лучше его поправить: либо в самом api, либо в провайдере. Спасибо, что написали.

Denchick commented 5 months ago

Привет! Поправили в 958ad46 и 3c5e0ff. Выйдет в новой версии провайдера.

opportunity356 commented 2 months ago

Was fixed in https://github.com/yandex-cloud/terraform-provider-yandex/releases/tag/v0.120.0