Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#108 from modular-magician/code…
Browse files Browse the repository at this point in the history
…gen-pr-882

Fix ci tests
  • Loading branch information
chrisst authored Nov 8, 2018
2 parents e830c3c + 13a627e commit 03cba95
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
8 changes: 5 additions & 3 deletions google-beta/resource_composer_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"fmt"
"testing"

"log"
"strings"
"time"

"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"google.golang.org/api/composer/v1"
"google.golang.org/api/storage/v1"
"log"
"strings"
"time"
)

const testComposerEnvironmentPrefix = "tf-cc-testenv"
Expand Down Expand Up @@ -274,6 +275,7 @@ resource "google_composer_environment" "test" {
node_config {
network = "${google_compute_network.test.self_link}"
subnetwork = "${google_compute_subnetwork.test.self_link}"
zone = "us-central1-a"
service_account = "${google_service_account.test.name}"
}
Expand Down
17 changes: 12 additions & 5 deletions google-beta/resource_compute_project_metadata_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package google
import (
"fmt"
"log"
"time"

"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/compute/v1"
Expand Down Expand Up @@ -35,6 +36,12 @@ func resourceComputeProjectMetadataItem() *schema.Resource {
ForceNew: true,
},
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
},
}
}

Expand All @@ -49,7 +56,7 @@ func resourceComputeProjectMetadataItemCreate(d *schema.ResourceData, meta inter
key := d.Get("key").(string)
val := d.Get("value").(string)

err = updateComputeCommonInstanceMetadata(config, projectID, key, &val)
err = updateComputeCommonInstanceMetadata(config, projectID, key, &val, int(d.Timeout(schema.TimeoutCreate).Minutes()))
if err != nil {
return err
}
Expand Down Expand Up @@ -101,7 +108,7 @@ func resourceComputeProjectMetadataItemUpdate(d *schema.ResourceData, meta inter
_, n := d.GetChange("value")
new := n.(string)

err = updateComputeCommonInstanceMetadata(config, projectID, key, &new)
err = updateComputeCommonInstanceMetadata(config, projectID, key, &new, int(d.Timeout(schema.TimeoutUpdate).Minutes()))
if err != nil {
return err
}
Expand All @@ -119,7 +126,7 @@ func resourceComputeProjectMetadataItemDelete(d *schema.ResourceData, meta inter

key := d.Get("key").(string)

err = updateComputeCommonInstanceMetadata(config, projectID, key, nil)
err = updateComputeCommonInstanceMetadata(config, projectID, key, nil, int(d.Timeout(schema.TimeoutDelete).Minutes()))
if err != nil {
return err
}
Expand All @@ -128,7 +135,7 @@ func resourceComputeProjectMetadataItemDelete(d *schema.ResourceData, meta inter
return nil
}

func updateComputeCommonInstanceMetadata(config *Config, projectID string, key string, afterVal *string) error {
func updateComputeCommonInstanceMetadata(config *Config, projectID string, key string, afterVal *string, timeout int) error {
updateMD := func() error {
log.Printf("[DEBUG] Loading project metadata: %s", projectID)
project, err := config.clientCompute.Projects.Get(projectID).Do()
Expand Down Expand Up @@ -173,7 +180,7 @@ func updateComputeCommonInstanceMetadata(config *Config, projectID string, key s

log.Printf("[DEBUG] SetCommonInstanceMetadata: %d (%s)", op.Id, op.SelfLink)

return computeOperationWait(config.clientCompute, op, project.Name, "SetCommonInstanceMetadata")
return computeOperationWaitTime(config.clientCompute, op, project.Name, "SetCommonInstanceMetadata", timeout)
}

return MetadataRetryWrapper(updateMD)
Expand Down
6 changes: 3 additions & 3 deletions google-beta/resource_compute_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func resourceComputeSnapshot() *schema.Resource {
},
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(4 * time.Minute),
Update: schema.DefaultTimeout(4 * time.Minute),
Delete: schema.DefaultTimeout(4 * time.Minute),
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
},
}
}
Expand Down
7 changes: 7 additions & 0 deletions google-beta/resource_dataproc_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ func resourceDataprocJobCreate(d *schema.ResourceData, meta interface{}) error {
}
d.SetId(job.Reference.JobId)

timeoutInMinutes := int(d.Timeout(schema.TimeoutCreate).Minutes())
waitErr := dataprocJobOperationWait(config, region, project, job.Reference.JobId,
"Creating Dataproc job", timeoutInMinutes, 1)
if waitErr != nil {
return waitErr
}

log.Printf("[INFO] Dataproc job %s has been submitted", job.Reference.JobId)
return resourceDataprocJobRead(d, meta)
}
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/compute_project_metadata_item.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ Project metadata items can be imported using the `key`, e.g.
```
$ terraform import google_compute_project_metadata_item.default my_metadata
```

## Timeouts

This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - Default is 5 minutes.
- `update` - Default is 5 minutes.
- `delete` - Default is 5 minutes.
9 changes: 9 additions & 0 deletions website/docs/r/compute_snapshot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,12 @@ exported:
* `self_link` - The URI of the created resource.

* `label_fingerprint` - The unique fingerprint of the labels.

## Timeouts

This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - Default is 5 minutes.
- `update` - Default is 5 minutes.
- `delete` - Default is 5 minutes.

0 comments on commit 03cba95

Please sign in to comment.