Skip to content

TERRA-68 ⁃ Add support for database lookup via database name #144

@muresan

Description

@muresan

Affected Data source

  • data.astra_database

Expected Behavior

Allow lookup of database by name. I am currently looking up databases via data.astra_databases but this has the problem that it does not fail if at least one database is present in the organization and leads to code like:

locals {
  database_id_tmp = join("", [for db in data.astra_databases.list.results : db.id if db.name == var.database_name])
  database_id = local.database_id_tmp != "" ? local.database_id_tmp : "00000000-0000-0000-0000-000000000000"
}

which has the issue that:

  • when database does not exist, database_id_tmp is empty so all places where you would use it, like other astra resources, they fail at the validation step because they expect the database_id to be in UUID format.
  • I "fixed" this by using "00000000-0000-0000-0000-000000000000" which created even more fun failure scenarios on the provider.
    A data structure would fail directly if the DB does not exist and would "propagate" the error to the rest of terraform, without that there's no clear error and in some cases you end up with an API call with the database_id = "00000000-0000-0000-0000-000000000000" which fails with another cryptic error.

Important Factoids

The API only supports lookup using the DB id and database name may not be enforced to be unique so this may not be possible. Implementing this by enumerating all the databases and selecting the one matching the name might be too inefficient.

References

https://docs.datastax.com/en/astra/docs/_attachments/devopsv2.html#tag/Database-Operations/operation/getDatabase

┆Issue is synchronized with this Jira Task by Unito
┆friendlyId: TERRA-68
┆priority: Major

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions