Skip to content

Commit

Permalink
stop converting timeouts to/from minutes (GoogleCloudPlatform#3421)
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow authored and Nathan Klish committed May 18, 2020
1 parent 9bbc9e2 commit fa2fda7
Show file tree
Hide file tree
Showing 39 changed files with 170 additions and 179 deletions.
4 changes: 2 additions & 2 deletions templates/terraform/custom_delete/appversion_delete.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if d.Get("delete_service_on_destroy") == true {
}
err = appEngineOperationWaitTime(
config, res, project, "Deleting Service",
int(d.Timeout(schema.TimeoutDelete).Minutes()))
d.Timeout(schema.TimeoutDelete))

if err != nil {
return err
Expand All @@ -50,7 +50,7 @@ if d.Get("delete_service_on_destroy") == true {
}
err = appEngineOperationWaitTime(
config, res, project, "Deleting AppVersion",
int(d.Timeout(schema.TimeoutDelete).Minutes()))
d.Timeout(schema.TimeoutDelete))

if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions templates/terraform/operation.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ func create<%= product_name %>Waiter(config *Config, op map[string]interface{},
Might as well just nolint it so we can pass the linter checks.
-%>
// nolint: deadcode,unused
func <%= product_name.camelize(:lower) -%>OperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{},<% if has_project -%> project,<% end -%> activity string, timeoutMinutes int) error {
func <%= product_name.camelize(:lower) -%>OperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{},<% if has_project -%> project,<% end -%> activity string, timeout time.Duration) error {
w, err := create<%= product_name %>Waiter(config, op, <% if has_project -%> project, <%end-%> activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
if err := OperationWait(w, activity, timeoutMinutes, config.PollInterval); err != nil {
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}
<% end -%>

func <%= product_name.camelize(:lower) -%>OperationWaitTime(config *Config, op map[string]interface{}, <% if has_project -%> project,<% end -%> activity string, timeoutMinutes int) error {
func <%= product_name.camelize(:lower) -%>OperationWaitTime(config *Config, op map[string]interface{}, <% if has_project -%> project,<% end -%> activity string, timeout time.Duration) error {
w, err := create<%= product_name %>Waiter(config, op, <% if has_project -%> project, <%end-%> activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}
2 changes: 1 addition & 1 deletion templates/terraform/post_create/labels.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok ||

err = computeOperationWaitTime(
config, res, project, "Updating <%= resource_name -%> Labels",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
d.Timeout(schema.TimeoutUpdate))

if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions templates/terraform/resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{
var opRes map[string]interface{}
err = <%= client_name_camel -%>OperationWaitTimeWithResponse(
config, res, &opRes, <% if has_project -%> project, <% end -%> "Creating <%= object.name -%>",
int(d.Timeout(schema.TimeoutCreate).Minutes()))
d.Timeout(schema.TimeoutCreate))
if err != nil {
<% if object.custom_code.post_create_failure -%>
resource<%= resource_name -%>PostCreateFailure(d, meta)
Expand Down Expand Up @@ -298,7 +298,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{
<% else -%>
err = <%= client_name_camel -%>OperationWaitTime(
config, res, <% if has_project -%> project, <% end -%> "Creating <%= object.name -%>",
int(d.Timeout(schema.TimeoutCreate).Minutes()))
d.Timeout(schema.TimeoutCreate))

if err != nil {
<% if object.custom_code.post_create_failure -%>
Expand Down Expand Up @@ -611,7 +611,7 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' ||
<% if object.async.is_a? Api::OpAsync-%>
err = <%= client_name_camel -%>OperationWaitTime(
config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
Expand Down Expand Up @@ -710,7 +710,7 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' ||
<% if object.async.is_a? Api::OpAsync -%>
err = <%= client_name_camel -%>OperationWaitTime(
config, res, <% if has_project -%> project, <% end -%> "Updating <%= object.name -%>",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
d.Timeout(schema.TimeoutUpdate))

if err != nil {
return err
Expand Down Expand Up @@ -799,7 +799,7 @@ func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{
<% if object.async&.allow?('delete') -%>
err = <%= client_name_camel -%>OperationWaitTime(
config, res, <% if has_project -%> project, <% end -%> "Deleting <%= object.name -%>",
int(d.Timeout(schema.TimeoutDelete).Minutes()))
d.Timeout(schema.TimeoutDelete))

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion third_party/terraform/resources/common_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestOperationWait_TimeoutsShouldRetry(t *testing.T) {
testWaiter := TestWaiter{
runCount: 0,
}
err := OperationWait(&testWaiter, "my-activity", 1, 0*time.Second)
err := OperationWait(&testWaiter, "my-activity", 1*time.Minute, 0*time.Second)
if err != nil {
t.Fatalf("unexpected error waiting for operation: got '%v', want 'nil'", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro
d.SetId(cloudFuncId.cloudFunctionId())

err = cloudFunctionsOperationWait(config, op, "Creating CloudFunctions Function",
int(d.Timeout(schema.TimeoutCreate).Minutes()))
d.Timeout(schema.TimeoutCreate))
if err != nil {
return err
}
Expand Down Expand Up @@ -556,7 +556,7 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
}

err = cloudFunctionsOperationWait(config, op, "Updating CloudFunctions Function",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
Expand All @@ -579,7 +579,7 @@ func resourceCloudFunctionsDestroy(d *schema.ResourceData, meta interface{}) err
return err
}
err = cloudFunctionsOperationWait(config, op, "Deleting CloudFunctions Function",
int(d.Timeout(schema.TimeoutDelete).Minutes()))
d.Timeout(schema.TimeoutDelete))
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func resourceComposerEnvironmentCreate(d *schema.ResourceData, meta interface{})

waitErr := composerOperationWaitTime(
config, op, envName.Project, "Creating Environment",
int(d.Timeout(schema.TimeoutCreate).Minutes()))
d.Timeout(schema.TimeoutCreate))

if waitErr != nil {
// The resource didn't actually get created, remove from state.
Expand Down Expand Up @@ -567,7 +567,7 @@ func resourceComposerEnvironmentPatchField(updateMask string, env *composer.Envi

waitErr := composerOperationWaitTime(
config, op, envName.Project, "Updating newly created Environment",
int(d.Timeout(schema.TimeoutCreate).Minutes()))
d.Timeout(schema.TimeoutCreate))
if waitErr != nil {
// The resource didn't actually update.
return fmt.Errorf("Error waiting to update Environment: %s", waitErr)
Expand All @@ -593,7 +593,7 @@ func resourceComposerEnvironmentDelete(d *schema.ResourceData, meta interface{})

err = composerOperationWaitTime(
config, op, envName.Project, "Deleting Environment",
int(d.Timeout(schema.TimeoutDelete).Minutes()))
d.Timeout(schema.TimeoutDelete))
if err != nil {
return err
}
Expand Down Expand Up @@ -1051,7 +1051,7 @@ func handleComposerEnvironmentCreationOpFailure(id string, envName *composerEnvi
waitErr := composerOperationWaitTime(
config, op, envName.Project,
fmt.Sprintf("Deleting invalid created Environment with state %q", env.State),
int(d.Timeout(schema.TimeoutCreate).Minutes()))
d.Timeout(schema.TimeoutCreate))
if waitErr != nil {
return fmt.Errorf("Error waiting to delete invalid Environment with state %q: %s", env.State, waitErr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func resourceAttachedDiskCreate(d *schema.ResourceData, meta interface{}) error
d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s/%s", zv.Project, zv.Zone, zv.Name, diskName))

waitErr := computeOperationWaitTime(config, op, zv.Project,
"disk to attach", int(d.Timeout(schema.TimeoutCreate).Minutes()))
"disk to attach", d.Timeout(schema.TimeoutCreate))
if waitErr != nil {
d.SetId("")
return waitErr
Expand Down Expand Up @@ -184,7 +184,7 @@ func resourceAttachedDiskDelete(d *schema.ResourceData, meta interface{}) error
}

waitErr := computeOperationWaitTime(config, op, zv.Project,
fmt.Sprintf("Detaching disk from %s", zv.Name), int(d.Timeout(schema.TimeoutDelete).Minutes()))
fmt.Sprintf("Detaching disk from %s", zv.Name), d.Timeout(schema.TimeoutDelete))
if waitErr != nil {
return waitErr
}
Expand Down
45 changes: 21 additions & 24 deletions third_party/terraform/resources/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,6 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
return err
}

// Read create timeout
createTimeout := int(d.Timeout(schema.TimeoutCreate).Minutes())

log.Printf("[INFO] Requesting instance creation")
op, err := config.clientComputeBeta.Instances.Insert(project, zone.Name, instance).Do()
if err != nil {
Expand All @@ -827,7 +824,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, z, instance.Name))

// Wait for the operation to complete
waitErr := computeOperationWaitTime(config, op, project, "instance to create", createTimeout)
waitErr := computeOperationWaitTime(config, op, project, "instance to create", d.Timeout(schema.TimeoutCreate))
if waitErr != nil {
// The resource didn't actually create
d.SetId("")
Expand Down Expand Up @@ -1089,7 +1086,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error updating metadata: %s", err)
}

opErr := computeOperationWaitTime(config, op, project, "metadata to update", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "metadata to update", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand Down Expand Up @@ -1117,7 +1114,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error updating tags: %s", err)
}

opErr := computeOperationWaitTime(config, op, project, "tags to update", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "tags to update", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1135,7 +1132,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error updating labels: %s", err)
}

opErr := computeOperationWaitTime(config, op, project, "labels to update", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "labels to update", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1157,7 +1154,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err

opErr := computeOperationWaitTime(
config, op, project, "scheduling policy update",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand Down Expand Up @@ -1195,7 +1192,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
if err != nil {
return fmt.Errorf("Error deleting old access_config: %s", err)
}
opErr := computeOperationWaitTime(config, op, project, "old access_config to delete", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "old access_config to delete", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1220,7 +1217,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
if err != nil {
return fmt.Errorf("Error adding new access_config: %s", err)
}
opErr := computeOperationWaitTime(config, op, project, "new access_config to add", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "new access_config to add", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1240,7 +1237,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
if err != nil {
return errwrap.Wrapf("Error removing alias_ip_range: {{err}}", err)
}
opErr := computeOperationWaitTime(config, op, project, "updating alias ip ranges", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "updating alias ip ranges", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1264,7 +1261,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
if err != nil {
return errwrap.Wrapf("Error adding alias_ip_range: {{err}}", err)
}
opErr := computeOperationWaitTime(config, op, project, "updating alias ip ranges", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "updating alias ip ranges", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand Down Expand Up @@ -1342,7 +1339,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
return errwrap.Wrapf("Error detaching disk: %s", err)
}

opErr := computeOperationWaitTime(config, op, project, "detaching disk", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "detaching disk", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1357,7 +1354,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
return errwrap.Wrapf("Error attaching disk : {{err}}", err)
}

opErr := computeOperationWaitTime(config, op, project, "attaching disk", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "attaching disk", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand Down Expand Up @@ -1391,7 +1388,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error updating deletion protection flag: %s", err)
}

opErr := computeOperationWaitTime(config, op, project, "deletion protection to update", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "deletion protection to update", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand Down Expand Up @@ -1420,7 +1417,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
}
opErr := computeOperationWaitTime(
config, op, project, "updating status",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1445,7 +1442,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
return errwrap.Wrapf("Error stopping instance: {{err}}", err)
}

opErr := computeOperationWaitTime(config, op, project, "stopping instance", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "stopping instance", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1463,7 +1460,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
if err != nil {
return err
}
opErr := computeOperationWaitTime(config, op, project, "updating machinetype", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "updating machinetype", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1485,7 +1482,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
if err != nil {
return err
}
opErr := computeOperationWaitTime(config, op, project, "updating min cpu platform", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "updating min cpu platform", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1504,7 +1501,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
if err != nil {
return err
}
opErr := computeOperationWaitTime(config, op, project, "updating service account", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "updating service account", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1520,7 +1517,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
if err != nil {
return fmt.Errorf("Error updating display device: %s", err)
}
opErr := computeOperationWaitTime(config, op, project, "updating display device", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "updating display device", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1535,7 +1532,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
}

opErr := computeOperationWaitTime(config, op, project,
"starting instance", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
"starting instance", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand All @@ -1551,7 +1548,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
}

opErr := computeOperationWaitTime(config, op, project,
"shielded vm config update", int(d.Timeout(schema.TimeoutUpdate).Minutes()))
"shielded vm config update", d.Timeout(schema.TimeoutUpdate))
if opErr != nil {
return opErr
}
Expand Down Expand Up @@ -1775,7 +1772,7 @@ func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) err
}

// Wait for the operation to complete
opErr := computeOperationWaitTime(config, op, project, "instance to delete", int(d.Timeout(schema.TimeoutDelete).Minutes()))
opErr := computeOperationWaitTime(config, op, project, "instance to delete", d.Timeout(schema.TimeoutDelete))
if opErr != nil {
return opErr
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func resourceComputeInstanceFromTemplateCreate(d *schema.ResourceData, meta inte

// Wait for the operation to complete
waitErr := computeOperationWaitTime(config, op, project,
"instance to create", int(d.Timeout(schema.TimeoutCreate).Minutes()))
"instance to create", d.Timeout(schema.TimeoutCreate))
if waitErr != nil {
// The resource didn't actually create
d.SetId("")
Expand Down
Loading

0 comments on commit fa2fda7

Please sign in to comment.