hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.3k stars 1.73k forks source link

Add support for database leader and witness region selection with google_spanner_database #16660

Open jbnair opened 10 months ago

jbnair commented 10 months ago

Community Note

Description

I would like to set a Spanner Database's database leader region and witness region using Terraform.

At present the leader region and witness region can only be set using the DDL using ALTER DATABASE. When we create multiple databases with different leader / witness region, this results in duplication of DDL (definitions other than ALTER DATABASE) for each database.

It will be very useful if google_spanner_database can implement the logic to set the leader and witness regions (similar to PITR, terraform argument: version_retention_period)

New or Affected Resource(s)

Potential Terraform Configuration


resource "google_spanner_database" "sample" {
  instance                 = "sample"
  name                     = "sample-leader-witness"
  default_leader           = "us-east1"
  witness_location         = "us-east4" 
}

References

b/314943955

melinath commented 9 months ago

This can be done with the ddl field already; it sounds like the request is to add client-side only fields that give you a "shortcut" by adding the fields to the DDL under the hood. There are other fields that operate this way, but it has ended up being somewhat complex and difficult to maintain so it may not be a pattern we want to continue.

Ideally if this feature is desired it would be exposed via the control plane API and then support for the API fields would be added in Terraform.

jbnair commented 9 months ago

@melinath Ok. At present, we are doing with the ddl field using a DDL file. We are applying the same DDL to multiple databases in our use case. Hence other than the line that sets the leader and replica region rest of the DDL contents are duplicated for each DDL file. That was the reason for exploring this option.