-
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
New datasource: google_container_cluster #740
Conversation
Hi @danawillow - any chance we could get this reviewed before it gets stale? Thanks! |
Hey @sl1pm4t, thanks for the PR! I've been drowning in code reviews lately but I'll try to get to this before the Thanksgiving break (and of course don't let that stop you from continuing to contribute!) Right now I think keeping the data source name consistent with the resource name is probably the way to go though. |
No worries @danawillow, I felt bad asking because I know you're swamped. I really appreciate your massive effort! |
Hi @danawillow - I've renamed the datasource and fixed a couple other issues I spotted in the tests, and missing reference to the docs page in |
|
||
"cluster_ipv4_cidr": { | ||
Type: schema.TypeString, | ||
Optional: 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.
Except for name
, zone
, and project
, we probably shouldn't allow setting fields since they don't get used to make the request
"master_auth": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
ForceNew: 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.
Likewise, I don't think ForceNew
really has meaning for data sources
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.
Good point. Will fix this.
} | ||
} | ||
|
||
func datasourceContainerClusterRead(d *schema.ResourceData, meta interface{}) error { |
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 curious why you decided to have only a subset of the resource schema fields in the data source schema. If you had the same set of fields, then you would be able to reuse the read function (https://github.com/terraform-providers/terraform-provider-google/blob/master/google/data_source_google_compute_instance_group.go is a good example of this). If there is a reason why certain schema elements are excluded, I'd love to see a comment explaining why.
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.
Great idea, I hadn't considered using the resources Read func, but that makes a lot of sense.
I stripped down the schema to a subset that I thought would be useful in a datasource, based on the notion if it wasn't going to be useful, remove it so there's less to maintain in the read func. Now that you've pointed out we can re-use the read func from the resource it makes sense to keep the whole schema.
Hi @danawillow - sorry for the delay fixing this up. As per your suggestion, the datasource now uses the existing Thanks! |
Add documentation for google_kubernetes_cluster datasource Rename datasource to google_container_cluster To be consistent with the equivalent resource. Rename datasource in docs. google_kubernetes_cluster -> google_container_cluster. Also add reference in google.erb file. WIP Datasource read needs to set an ID, then call resource read func Add additional cluster attributes to datasource schema
Datasource documentation also updated.
I rebased on master branch to resolve conflicts. |
google/utils_test.go
Outdated
} | ||
} | ||
|
||
func dummyCustomSetFunc(v interface{}) int { |
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.
Looks like this is unused
google/utils.go
Outdated
fallthrough | ||
case schema.TypeList: | ||
// List & Set types are generally used for 2 cases: | ||
// - a list/set of simple primative values (e.g. list of strings) |
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.
nit: s/primative/primitive
google/utils.go
Outdated
Schema: datasourceSchemaFromResourceSchema(elem.Schema), | ||
} | ||
} else { | ||
// handle simple primative case |
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.
and here :)
google/utils.go
Outdated
// example) and therefore the attribute flags were not set appropriately when | ||
// first added to the schema definition. Currently only supports top-level | ||
// schema elements. | ||
func fixDatasourceSchemaFlags(schema map[string]*schema.Schema, required bool, keys ...string) { |
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.
Optional idea: it might be a bit more readable in the resources themselves to have two additional fns: addRequiredFieldsToSchema and addOptionalFieldsToSchema (or something along those lines), that just call into this one with the appropriate bool value.
|
||
# google\_container\_cluster | ||
|
||
Get info about a cluster within GCE from its name and zone. |
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.
s/GCE/GKE
google/utils.go
Outdated
// - all attributes have Computed = true | ||
// - all attributes have ForceNew, Required = false | ||
// - Validation funcs and attributes (e.g. MaxItems) are not copied | ||
func datasourceSchemaFromResourceSchema(rs map[string]*schema.Schema) map[string]*schema.Schema { |
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.
Great idea, thanks so much for adding this! For a bit more visibility within the provider, it might make more sense to move these helper fns into their own file (datasource_helpers.go or something like that)
@danawillow - thanks for the review. The requested changes have been implemented. 👨💻 |
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.
Looks great, thanks so much @sl1pm4t!
* Add google_kubernetes_cluster datasource Add documentation for google_kubernetes_cluster datasource Rename datasource to google_container_cluster To be consistent with the equivalent resource. Rename datasource in docs. google_kubernetes_cluster -> google_container_cluster. Also add reference in google.erb file. WIP Datasource read needs to set an ID, then call resource read func Add additional cluster attributes to datasource schema * Generate datasource schema from resource Datasource documentation also updated. * add test for datasourceSchemaFromResourceSchema * Code review changes
…rp#740) Signed-off-by: Modular Magician <[email protected]>
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! |
Adds the
google_kubernetes_cluster
datasource.This is useful for retrieving the cluster credentials and feeding into the Terraform Kubernetes provider, but has other use cases (e.g. feed cluster CIDR range into firewall/VPC route resources).
I've named the datasource
google_kubernetes_cluster
rather thangoogle_container_cluster
to match the new Google product name, but this means the datasource naming is not consistent with the equivalent resource. Let me know if this is acceptable.Fixes #732