Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Google Spanner Support (google_spanner_database) #271

Merged
merged 14 commits into from
Aug 14, 2017

Conversation

nickithewatt
Copy link
Contributor

This PR aims to addresses #67 which looks to add Google Spanner Support, specifically adding a new resource google_spanner_database. CC @rileykarson @danawillow

In order to make these PR's easier to digest and review, instead of creating one big PR with all Spanner support in it, I have created one for each new resource to be added. This is the 2nd which adds support for the google_spanner_database resource. A separate one (PR #270) added the foundational support for creating the Instance, i.e. the google_spanner_instance resource.

This PR does build off PR #270 as it uses the the google_spanner_instance resource so that should probably be reviewed first, then this one. Alternatively if you want to review all the Spanner support, this PR will have that.

@nickithewatt nickithewatt changed the title Spanner support database Add Google Spanner Support (google_spanner_database) Jul 31, 2017
@nickithewatt nickithewatt force-pushed the spanner-support-database branch from 91baff7 to a6ac605 Compare August 4, 2017 08:42
@rosbo rosbo self-requested a review August 4, 2017 22:09
@nickithewatt nickithewatt force-pushed the spanner-support-database branch from a6ac605 to 134534a Compare August 6, 2017 23:14
Copy link
Contributor

@rosbo rosbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi again Nicki.

Thanks a lot for your contribution.

Just a few comments. Very good overall.

"ddl": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an update method for this. If you decide not to implement it in this PR, please file an issue and add a TODO here link to the issue.

Copy link
Contributor Author

@nickithewatt nickithewatt Aug 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure an update makes sense here? My understanding is that the DDL update here is more additive style statements to apply to the database, rather than the definitive list of statements, i.e. could include update statements as well. Without support for clauses like DROP IF EXISTS, this could be quite hard to make idempotent.

Moving from this:

resource "google_spanner_database" "db1" {
  instance = "${google_spanner_instance.instance1.name}"
  name     = "mydb1"

  ddl           =  [
    "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
    "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"]
}

to this:

resource "google_spanner_database" "db1" {
  instance = "${google_spanner_instance.instance1.name}"
  name     = "mydb1"

  ddl           =  [
    "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
    "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)",
    "CREATE TABLE t3 (t3 INT64 NOT NULL,) PRIMARY KEY(t3)"]
}

Would fail with an Error code 3 Duplicate name in schema: t1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. We should leave the ForceNew.

return handleNotFoundError(err, d, fmt.Sprintf("Spanner database %q", id.databaseUri()))
}

d.SetId(id.terraformId())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to set the id here, it is set either in the create method or the import method.


## Attributes Reference

No additional attributes are computed other than those defined above.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the computed state field here once you added it.

Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add the Computed state field.

@nickithewatt nickithewatt force-pushed the spanner-support-database branch from 312fbef to 7c72ab5 Compare August 12, 2017 02:24
@nickithewatt nickithewatt force-pushed the spanner-support-database branch from 7c72ab5 to ddbabb6 Compare August 12, 2017 02:29
@nickithewatt
Copy link
Contributor Author

@rosbo Thanks again for review. Have made one comment re DDL update (see above). Rebased off the spanner-support-instance branch and made other changes as requested. Let me know if there is anything else that needs doing on this :)

Copy link
Contributor

@rosbo rosbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for adding Spanner support

@rosbo
Copy link
Contributor

rosbo commented Aug 14, 2017

make testacc TESTARGS="-run TestAccSpannerDatabase_" TEST="./google"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./google -v -run TestAccSpannerDatabase_ -timeout 120m
=== RUN TestAccSpannerDatabase_importInstanceDatabase
--- PASS: TestAccSpannerDatabase_importInstanceDatabase (24.50s)
=== RUN TestAccSpannerDatabase_importProjectInstanceDatabase
--- PASS: TestAccSpannerDatabase_importProjectInstanceDatabase (24.20s)
=== RUN TestAccSpannerDatabase_basic
--- PASS: TestAccSpannerDatabase_basic (24.00s)
=== RUN TestAccSpannerDatabase_basicWithInitialDDL
--- PASS: TestAccSpannerDatabase_basicWithInitialDDL (24.17s)
=== RUN TestAccSpannerDatabase_duplicateNameError
--- PASS: TestAccSpannerDatabase_duplicateNameError (24.31s)
PASS
ok github.com/terraform-providers/terraform-provider-google/google 121.315s

@rosbo rosbo merged commit 752b406 into hashicorp:master Aug 14, 2017
z1nkum pushed a commit to z1nkum/terraform-provider-google that referenced this pull request Aug 15, 2017
@nickithewatt nickithewatt deleted the spanner-support-database branch August 21, 2017 00:30
negz pushed a commit to negz/terraform-provider-google that referenced this pull request Oct 17, 2017
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this pull request May 21, 2019
@ghost
Copy link

ghost commented Mar 31, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants