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

Refactor Compute Operations to work identically & introduce a scope-less API #191

Merged
merged 3 commits into from
Jul 25, 2017

Conversation

rileykarson
Copy link
Collaborator

We can use the Region and Zone properties of a compute Operation to infer it's scope; we don't need to call scope-specific methods.

  • Refactor compute_operation.go to use the same code paths for all 3 operation types
  • Introduce a universal operation type that new resources should use going forward.

We can migrate existing resources over time with a series of followup CLs, eliminating the functions for each scope type as we go.

Smoke testing this with a resource of each scope:

Global:

TF_ACC=1 go test ./google -v -run=TestAccComputeGlobalAddress -timeout 120m
=== RUN   TestAccComputeGlobalAddress_importBasic
--- PASS: TestAccComputeGlobalAddress_importBasic (22.76s)
=== RUN   TestAccComputeGlobalAddress_basic
--- PASS: TestAccComputeGlobalAddress_basic (22.31s)
PASS
ok  	github.com/terraform-providers/terraform-provider-google/google	45.236

Regional:

TF_ACC=1 go test ./google -v -run=TestAccComputeAddress -timeout 120m
=== RUN   TestAccComputeAddress_importBasic
--- PASS: TestAccComputeAddress_importBasic (22.98s)
=== RUN   TestAccComputeAddress_basic
--- PASS: TestAccComputeAddress_basic (23.04s)
PASS
ok  	github.com/terraform-providers/terraform-provider-google/google	46.226s

Zonal:

TF_ACC=1 go test ./google -v -run=TestAccComputeInstance_basic1 -timeout 120m
=== RUN   TestAccComputeInstance_basic1
--- PASS: TestAccComputeInstance_basic1 (61.90s)
PASS
ok  	github.com/terraform-providers/terraform-provider-google/google	62.100s

case Region:
op, err = w.Service.RegionOperations.Get(w.Project, scope, w.Op.Name).Do()
case Zone:
op, err = w.Service.ZoneOperations.Get(w.Project, scope, w.Op.Name).Do()
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't seem like this condition could possibly be hit. What if the op assignments were all done in the previous if/else statements?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

return waitComputeOperationWaiter(w, timeoutMin, activity)
}

func waitComputeOperationWaiter(w *ComputeOperationWaiter, timeoutMin int, activity string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a great suggestion for you but I don't like that "wait" occurs twice in this fn name. waitCompute? waitComputeOperation could work but I don't like that there's a computeOperationWait already. Or we can just leave it be since I don't think it'll need to be a separate fn once all the others are gone.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a todo to make sure that we inline the method once the others are eliminated.

@danawillow
Copy link
Contributor

Thanks! Merge at will.

@rileykarson rileykarson merged commit ec162c6 into hashicorp:master Jul 25, 2017
z1nkum pushed a commit to z1nkum/terraform-provider-google that referenced this pull request Aug 15, 2017
…ess API (hashicorp#191)

* Refactor compute_operation.go to duplicate less code.

* Determine what scope type an Operation is from it's Operation object.

* Inlined operation type switch statement into if/else methods.
negz pushed a commit to negz/terraform-provider-google that referenced this pull request Oct 17, 2017
…ess API (hashicorp#191)

* Refactor compute_operation.go to duplicate less code.

* Determine what scope type an Operation is from it's Operation object.

* Inlined operation type switch statement into if/else methods.
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this pull request May 21, 2019
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
@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 👉 hashibot-feedback@hashicorp.com. 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