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 a datasource for google_compute_instance #1906

Merged

Conversation

rileykarson
Copy link
Collaborator

Add a datasource for GCE VM Instances (google_compute_instance).


As many deprecated/useless fields are removed as possible; a few are remaining with the "Removed" tag and are undocumented; they required editing the google_compute_instance resource (unless we wanted to copy a lot of almost identical read code) & would have bloated the PR which is already fairly large. If we want to remove them for, it should probably be done as a separate refactor.

The test covers a slight modified _basic config, and has attribute tests to smoke test a few nested fields as well as coverage of all the top-level ones. It's not much, but most of the code is shared with google_compute_instance anyways & no other data sources had that many tests. I can gladly add more, just let me know what you'd like more test coverage on!

@ghost ghost added the size/xl label Sep 5, 2018
@rileykarson rileykarson force-pushed the data-source-compute-instance branch from e7ce2f4 to c0bb4b4 Compare September 5, 2018 21:21
@ghost ghost added the size/xl label Sep 5, 2018
@rileykarson rileykarson force-pushed the data-source-compute-instance branch from c0bb4b4 to b705cbf Compare September 5, 2018 21:32
@ghost ghost added size/l and removed size/xl labels Sep 5, 2018
@rileykarson
Copy link
Collaborator Author

rileykarson commented Sep 5, 2018

Travis will maybe fail because of make fmt, ignore that failure. Sending a PR to fix right after this.

Updated google_compute_instance datasource to use the resources' schema. I kept the custom read and corresponding docs - we can't read in the state so a lot of deprecated fields just plain won't work. Some fields will "exist" to Terraform but are undocumented and have no value as a result.

Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

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

I'm not wild about the tight coupling to the resource, but I also don't see any good alternative. I think you've made the best of an unfortunate situation, honestly. Could we add a comment above the resource schema, just documenting that the data source schema relies on it, so there's at least a higher chance of people remembering the data source when modifying the resource schema?

Other than that, I had a few minor comments. The big one is just one on design--I feel a lot of users will want to be able to retrieve the instance using the self_link, not just the name, and if we can make that straightforward, that's probably worthwhile to do.

google/data_source_google_compute_instance.go Outdated Show resolved Hide resolved
google/data_source_google_compute_instance.go Outdated Show resolved Hide resolved

The following arguments are supported:

* `name` - (Required) The name of the instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we allow retrieval by self_link, as well? I think that'll be a highly requested use case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure!

To do this I took the logic from google_compute_region_instance_group's data source and parameterised it for consistency between the two. The test for that data source will fail but it was failing before and fails in the same way. Sorry for the scope of changes as a result of touching both resources here in this already large PR!

@rileykarson rileykarson force-pushed the data-source-compute-instance branch from b705cbf to d0fdebc Compare September 6, 2018 16:21
@ghost ghost added size/xl and removed size/l labels Sep 6, 2018
@rileykarson rileykarson merged commit d656e91 into hashicorp:master Sep 18, 2018
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
* Add a compute datasource.

* Add provider changes.

* Add self_link support to google_compute_instance datasource.

* Error check complex d.Set calls.
@ghost
Copy link

ghost commented Nov 16, 2018

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 Nov 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants