-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Allow defining BigQuery table fields inline #1113
Conversation
This looks like a great idea. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with the general idea of this as long as it's well-documented. Thanks @dasch for starting, and sorry it took so long to get around to reviewing! Here are some initial comments.
google/resource_bigquery_table.go
Outdated
@@ -93,6 +93,23 @@ func resourceBigQueryTable() *schema.Resource { | |||
}, | |||
}, | |||
|
|||
"field": { | |||
Type: schema.TypeSet, | |||
Required: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be optional, since we still want to allow people to use the schema
field
google/resource_bigquery_table.go
Outdated
@@ -268,6 +285,17 @@ func resourceTable(d *schema.ResourceData, meta interface{}) (*bigquery.Table, e | |||
table.TimePartitioning = expandTimePartitioning(v) | |||
} | |||
|
|||
fields := d.Get("binding").(*schema.Set) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the attribute in the schema is called "field", this should be d.Get("field")
. Also since we're going to make this optional, let's do a GetOk instead, since if no fields are set then I think d.Get will return nil (it's possible I'm wrong and that it's an empty set, but for consistency with the other d.GetOk calls in this function I think it's a good idea anyway)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, copy-paste error. I think we need to use Get
because field
can be used multiple times – I copied this code from another place that had that behavior.
google/resource_bigquery_table.go
Outdated
|
||
for i, v := range fields.List() { | ||
field := v.(map[string]interface{}) | ||
table.Schema.Fields[i] = &bigquery.TableFieldSchema{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will segfault because table.Schema is nil at this point- take a look around the codebase for some examples of how to fill this in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set table.Schema
on line 289 – can it still be nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, it's a different reason- the Fields array needs to be initialized: https://play.golang.org/p/2AsZv6v55tP is a stripped down version of what's happening here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks!
db2a556
to
899e4df
Compare
899e4df
to
97fb0d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable so far! Next up you'll want to add acceptance tests and documentation.
google/resource_bigquery_table.go
Outdated
|
||
for i, v := range fields.List() { | ||
field := v.(map[string]interface{}) | ||
table.Schema.Fields[i] = &bigquery.TableFieldSchema{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, it's a different reason- the Fields array needs to be initialized: https://play.golang.org/p/2AsZv6v55tP is a stripped down version of what's happening here.
@danawillow sorry for all the questions, but I don't seem to be able to make the tests actually run – I try to break a test be e.g. screwing with the inline config, but
|
@danawillow one more: BQ only allows making a |
For running tests, you want As for your other comments, are you trying to add apply-time logic to catch these? If so, I would probably not bother- if the API throws an error, that'll happen at the exact same spot that it would if we threw the error from inside Terraform. If the API takes a long time to return or has a confusing error message, then I'd reconsider. For plan-time though, just make everything except for description and mode as |
Thanks! This would be plan-time stuff. Will Also: adding a new field shouldn't force a new table to be created, and that's probably the most common change. |
dcac526
to
2d2e832
Compare
2d2e832
to
6ec3735
Compare
Hmm, without spending some time playing around with it I'm not sure. You may also be interested in looking at setting a custom hash function on the set. (also unrelated fyi- if you could avoid squashing your commits, that would be great just so I can see what changed in between reviews 🙂) |
I'll try that.
Sure thing! |
Hey @dasch! I just looked through this, and it's looking really good. Is this something you're still looking to get merged? As for the |
@paddycarver I'd love to have it merged, but unfortunately I won't be able to spend more time on it in the foreseeable future – feel free to merge as-is or take it over. |
@danawillow @paddycarver would you be willing to merge this as-is and complete the changes yourselves? I'm afraid I've forgotten whatever Go I learned doing this PR... |
Closing PR as stale |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
An implementation of #910.
I'm pretty new to Go, so I wanted to push this PR even if it's a bit rough.
field
togoogle_bigquery_table
resources, allowing for inline definition of table schemas.