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

New data source: compute region instance group #851

Merged

Conversation

nat-henderson
Copy link
Contributor

This closes #765... I think! :) This is my first data source - let me know if I've missed something, please! The timeout logic I wrote in the manager resource could use some special attention since I'm relatively new to Go.

@rosbo
Copy link
Contributor

rosbo commented Dec 13, 2017

Vet found suspicious constructs. Please check the reported constructs
and fix them if necessary before submitting the code for review.
make: *** [vet] Error 1
The command "make vet" exited with 2.

func dataSourceComputeRegionInstanceGroupRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
var project, region, name string
// add self_link parsing here.
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you've already added self_link parsing below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, true, removed.

Computed: true,
},

"items": {
Copy link
Contributor

Choose a reason for hiding this comment

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

We tend to not pluralize field names (no always followed). Would that make more sense to call it instance instead of item?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No strong feelings - I thought it would be best to stick to exactly the field names that come back from the /listInstances call. Do you prefer instance to items given that items is what's used here?
https://cloud.google.com/compute/docs/reference/latest/regionInstanceGroups/listInstances

FWIW I agree that "items" is a lousy name! It's probably the least specific you can be about what's in the list.

Copy link
Contributor

Choose a reason for hiding this comment

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

instance is definitely better. I think actually the pluralized version would be better since it is read only.

people will use it for interpolation in their data source this way:

instance = "${data.google_compute_region_instance_group_manager.instances.0.self_link}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, and done.

@@ -110,6 +112,12 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource {
Optional: true,
},

"wait_for_instances": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

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

Documentation for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
}
}()
select {
Copy link
Contributor

Choose a reason for hiding this comment

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

why using goroutine if you are blocking the main thread anyway here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, because there are two goroutines - time.After() returns a channel that sends "true" after the duration specified. This serves as an (apparently) idiomatic timeout mechanism. I like it, but willing to reformulate it if you prefer. Definitely need to comment it.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could probably rely on state.WaitForState() and wait until the creating + creatingwhitoutretries is equal to 0.

It would be more consistent with the rest of the waiting logic in Terraform

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aha, yes, state.WaitForState is a much better version of what I've written here. Will do!

@nat-henderson nat-henderson changed the title Initial commit for new data source: compute region instance group New data source: compute region instance group Dec 13, 2017
@danisla
Copy link
Contributor

danisla commented Dec 13, 2017

I really like the addition of the wait_for_instances argument! Can we get that on the google_compute_instance_group_manager resource too?

@nat-henderson
Copy link
Contributor Author

I think so! I've rewritten it to be extensible. I'll do that in a followup PR.

@nat-henderson
Copy link
Contributor Author

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./google -v -run=TestAccDataSourceRegionInstanceGroup* -timeout 120m
=== RUN   TestAccDataSourceRegionInstanceGroupManager
--- PASS: TestAccDataSourceRegionInstanceGroupManager (159.80s)
PASS
ok      github.com/terraform-providers/terraform-provider-google/google 159.811s

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.

Just missing the documentation for this data source

@nat-henderson
Copy link
Contributor Author

Added docs - how can I preview them to make sure they look right?

Also,

==> Checking that code complies with gofmt requirements...                     
TF_ACC=1 go test ./google -v -run=TestAccRegionInstanceGroup* -timeout 120m    
=== RUN   TestAccRegionInstanceGroupManager_basic                              
=== RUN   TestAccRegionInstanceGroupManager_targetSizeZero                     
=== RUN   TestAccRegionInstanceGroupManager_update                             
=== RUN   TestAccRegionInstanceGroupManager_updateLifecycle                    
=== RUN   TestAccRegionInstanceGroupManager_separateRegions                    
=== RUN   TestAccRegionInstanceGroupManager_autoHealingPolicies                
--- PASS: TestAccRegionInstanceGroupManager_update (180.35s)                   
--- PASS: TestAccRegionInstanceGroupManager_autoHealingPolicies (243.64s)      
--- PASS: TestAccRegionInstanceGroupManager_basic (243.75s)                    
--- PASS: TestAccRegionInstanceGroupManager_targetSizeZero (47.80s)            
--- PASS: TestAccRegionInstanceGroupManager_separateRegions (305.04s)          
--- PASS: TestAccRegionInstanceGroupManager_updateLifecycle (156.64s)          
PASS                                   
ok      github.com/terraform-providers/terraform-provider-google/google 337.010s    

@rosbo
Copy link
Contributor

rosbo commented Dec 14, 2017

You can follow these instructions:
https://github.com/hashicorp/terraform-website#running-the-site-locally

page_title: "Google: google_compute_instance_group"
sidebar_current: "docs-google-datasource-compute-instance-group"
description: |-
Get a Compute Region Instance Group within GCE.
Copy link
Contributor

Choose a reason for hiding this comment

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

The big feature is being able to list the instances inside the instance group. We should make that clear here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Took a lot of tiny commits to test the website - sorry about the mess, of course I'll squash before I merge.

@nat-henderson nat-henderson merged commit d2611d4 into hashicorp:master Dec 14, 2017
@nat-henderson nat-henderson deleted the region_instance_data_source branch December 14, 2017 21:35
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
* Add new data source: compute region instance group manager's groups.
* Add documentation for wait_for_instances and for the timeout mechanism in resourceComputeRegionInstanceGroupManagerCreate.
modular-magician added a commit to modular-magician/terraform-provider-google that referenced this pull request Sep 27, 2019
Signed-off-by: Modular Magician <magic-modules@google.com>
@ghost
Copy link

ghost commented Mar 30, 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 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 30, 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.

Add data source for: google_compute_region_instance_group
3 participants