Skip to content

Commit

Permalink
fix(spanner): fix escaping of database name in spanner ddl with POSTG…
Browse files Browse the repository at this point in the history
…RES dialect (#5938) (#11518)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Apr 15, 2022
1 parent 45572c2 commit f8da56e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/5938.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
spanner: fix escaping of database names with Postgres dialect in `google_spanner_database`
```
2 changes: 1 addition & 1 deletion google/resource_spanner_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func expandSpannerDatabaseInstance(v interface{}, d TerraformResourceData, confi
func resourceSpannerDatabaseEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
obj["createStatement"] = fmt.Sprintf("CREATE DATABASE `%s`", obj["name"])
if dialect, ok := obj["databaseDialect"]; ok && dialect == "POSTGRESQL" {
obj["createStatement"] = fmt.Sprintf("CREATE DATABASE %s", obj["name"])
obj["createStatement"] = fmt.Sprintf("CREATE DATABASE \"%s\"", obj["name"])
}
delete(obj, "name")
delete(obj, "instance")
Expand Down
4 changes: 2 additions & 2 deletions google/resource_spanner_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ resource "google_spanner_instance" "basic" {
resource "google_spanner_database" "basic_spangres" {
instance = google_spanner_instance.basic.name
name = "%s_spangres"
name = "%s-spangres"
database_dialect = "POSTGRESQL"
deletion_protection = false
}
Expand All @@ -187,7 +187,7 @@ resource "google_spanner_instance" "basic" {
resource "google_spanner_database" "basic_spangres" {
instance = google_spanner_instance.basic.name
name = "%s_spangres"
name = "%s-spangres"
database_dialect = "POSTGRESQL"
ddl = [
"CREATE TABLE t1 (t1 bigint NOT NULL PRIMARY KEY)",
Expand Down

0 comments on commit f8da56e

Please sign in to comment.