Skip to content

ClickHouse DBs defined in external block do not connect to cluster #575

@ngoral

Description

@ngoral

I was trying to define a clickhouse cluster with a database in it.
Here's the example code:

resource "yandex_mdb_clickhouse_cluster" "my-click-cluster" {
  name                     = "my-click-cluster"
  environment              = "PRODUCTION"
  ...
}

resource "yandex_mdb_clickhouse_database" "my_click_db" {
  cluster_id = yandex_mdb_clickhouse_cluster.my-click-cluster.id
  name       = "my_click_db"
}

It applies just fine, creating what we would it expect to create: cluster and a database in it.

But should I run plan again, no matter with or without changes in code in this particular cluster and database, terraform sees this database as new inside the cluster (as added inside the deprecated block database inside the cluster block), saying I have cerated it outside of the code.
So in the next apply it tries to delete the db. The database created earlier is listed in the state as yandex_mdb_clickhouse_database.my_click_db and it does not try to do anything with it.
Here's the output of plan command, it should be easier to understand :-)

Terraform detected the following changes made outside of Terraform since the
last "terraform apply" which may have affected this plan:
  # yandex_mdb_clickhouse_cluster.my-click-cluster has changed
  ~ resource "yandex_mdb_clickhouse_cluster" "my-click-cluster" {
        id                        = "......."
        name                      = "my-click-cluster"
        # (16 unchanged attributes hidden)
      + database {
          + name = "my_click_db"
        }
      + user {
          # At least one attribute in this block is (or was) sensitive,
          # so its contents will not be displayed.
        }
        # (8 unchanged blocks hidden)
    }
Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes.
─────────────────────────────────────────────────────────────────────────────
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place
Terraform will perform the following actions:
  # yandex_mdb_clickhouse_cluster.my-click-cluster will be updated in-place
  ~ resource "yandex_mdb_clickhouse_cluster" "my-click-cluster" {
        id                        = "..."
        name                      = "my-click-cluster"
        # (16 unchanged attributes hidden)
      - database {
          - name = "my_click_db" -> null
        }
      - user {
          # At least one attribute in this block is (or was) sensitive,
          # so its contents will not be displayed.
        }
        # (8 unchanged blocks hidden)
    }
Plan: 0 to add, 1 to change, 0 to destroy.

Just in case: I think that the expected behaviour is that the database from the state should be linked to the cluster resource and not been deleted every run.
Now we have to either use old syntax or add database to ignore

Version of provider is 0.162.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions