Skip to content

Commit

Permalink
Merge pull request #2430 from modular-magician/codegen-pr-882
Browse files Browse the repository at this point in the history
Fix ci tests
  • Loading branch information
chrisst authored Nov 8, 2018
2 parents a1c202c + 35826ff commit 5b70a02
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 88 deletions.
8 changes: 5 additions & 3 deletions google/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
77 changes: 0 additions & 77 deletions google/resource_compute_firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,48 +283,6 @@ func TestAccComputeFirewall_disabled(t *testing.T) {
})
}

func TestAccComputeFirewall_enableLogging(t *testing.T) {
t.Parallel()

var firewall computeBeta.Firewall
networkName := fmt.Sprintf("firewall-test-%s", acctest.RandString(10))
firewallName := fmt.Sprintf("firewall-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeFirewallDestroy,
Steps: []resource.TestStep{
{
Config: testAccComputeFirewall_enableLogging(networkName, firewallName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBetaFirewallExists("google_compute_firewall.foobar", &firewall),
testAccCheckComputeFirewallLoggingEnabled(&firewall, false),
),
},
{
ResourceName: "google_compute_firewall.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeFirewall_enableLogging(networkName, firewallName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBetaFirewallExists("google_compute_firewall.foobar", &firewall),
testAccCheckComputeFirewallLoggingEnabled(&firewall, true),
),
},
{
Config: testAccComputeFirewall_enableLogging(networkName, firewallName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBetaFirewallExists("google_compute_firewall.foobar", &firewall),
testAccCheckComputeFirewallLoggingEnabled(&firewall, false),
),
},
},
})
}

func testAccCheckComputeFirewallExists(n string, firewall *compute.Firewall) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -468,15 +426,6 @@ func testAccCheckComputeFirewallApiVersion(firewall *compute.Firewall) resource.
}
}

func testAccCheckComputeFirewallLoggingEnabled(firewall *computeBeta.Firewall, enabled bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
if firewall == nil || firewall.EnableLogging != enabled {
return fmt.Errorf("expected firewall enable_logging to be %t, got %t", enabled, firewall.EnableLogging)
}
return nil
}
}

func testAccComputeFirewall_basic(network, firewall string) string {
return fmt.Sprintf(`
resource "google_compute_network" "foobar" {
Expand Down Expand Up @@ -651,29 +600,3 @@ func testAccComputeFirewall_disabled(network, firewall string) string {
disabled = true
}`, network, firewall)
}

func testAccComputeFirewall_enableLogging(network, firewall string, enableLogging bool) string {
enableLoggingCfg := ""
if enableLogging {
enableLoggingCfg = "enable_logging= true"
}
return fmt.Sprintf(`
resource "google_compute_network" "foobar" {
name = "%s"
auto_create_subnetworks = false
ipv4_range = "10.0.0.0/16"
}
resource "google_compute_firewall" "foobar" {
name = "firewall-test-%s"
description = "Resource created for Terraform acceptance testing"
network = "${google_compute_network.foobar.name}"
source_tags = ["foo"]
allow {
protocol = "icmp"
}
%s
}`, network, firewall, enableLoggingCfg)
}
17 changes: 12 additions & 5 deletions google/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/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/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 5b70a02

Please sign in to comment.