From 033c98109a8fbf4751402cced49c461eb6046277 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Wed, 6 Nov 2019 16:34:12 -0800 Subject: [PATCH] Test fixes based on integration tests, id formats + other easy fixes (#2605) * Test fixes based on integration tests, id formats + other easy fixes * Compute network id test update * Fix region disk test id --- .../terraform/post_create/cloudbuild_trigger_id.go.erb | 2 +- .../terraform/resources/resource_bigtable_instance.go | 10 ++++++---- .../data_source_google_cloudfunctions_function_test.go | 1 + .../tests/data_source_google_organization_test.go | 4 ++-- .../terraform/tests/resource_compute_disk_test.go.erb | 4 ++-- .../tests/resource_compute_http_health_check_test.go | 8 ++++---- .../terraform/tests/resource_compute_image_test.go | 8 ++++---- .../resource_compute_instance_from_template_test.go | 3 +++ .../terraform/tests/resource_compute_network_test.go | 6 +++--- .../tests/resource_compute_region_disk_test.go | 6 +++--- 10 files changed, 29 insertions(+), 23 deletions(-) diff --git a/templates/terraform/post_create/cloudbuild_trigger_id.go.erb b/templates/terraform/post_create/cloudbuild_trigger_id.go.erb index d57e2c82073e..27f881281051 100644 --- a/templates/terraform/post_create/cloudbuild_trigger_id.go.erb +++ b/templates/terraform/post_create/cloudbuild_trigger_id.go.erb @@ -7,7 +7,7 @@ d.Set("trigger_id", triggerId.(string)) // Store the ID now. We tried to set it before and it failed because // trigger_id didn't exist yet. -id, err = replaceVars(d, config, "{{project}}/{{trigger_id}}") +id, err = replaceVars(d, config, "projects/{{project}}/triggers/{{trigger_id}}") if err != nil { return fmt.Errorf("Error constructing id: %s", err) } diff --git a/third_party/terraform/resources/resource_bigtable_instance.go b/third_party/terraform/resources/resource_bigtable_instance.go index 7c4b28ee31e5..5b22f30c832e 100644 --- a/third_party/terraform/resources/resource_bigtable_instance.go +++ b/third_party/terraform/resources/resource_bigtable_instance.go @@ -156,11 +156,13 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro defer c.Close() - instance, err := c.InstanceInfo(ctx, d.Id()) + instanceName := d.Get("name").(string) + + instance, err := c.InstanceInfo(ctx, instanceName) if err != nil { - log.Printf("[WARN] Removing %s because it's gone", d.Id()) + log.Printf("[WARN] Removing %s because it's gone", instanceName) d.SetId("") - return fmt.Errorf("Error retrieving instance. Could not find %s. %s", d.Id(), err) + return fmt.Errorf("Error retrieving instance. Could not find %s. %s", instanceName, err) } d.Set("project", project) @@ -252,7 +254,7 @@ func resourceBigtableInstanceDestroy(d *schema.ResourceData, meta interface{}) e defer c.Close() - name := d.Id() + name := d.Get("name").(string) err = c.DeleteInstance(ctx, name) if err != nil { return fmt.Errorf("Error deleting instance. %s", err) diff --git a/third_party/terraform/tests/data_source_google_cloudfunctions_function_test.go b/third_party/terraform/tests/data_source_google_cloudfunctions_function_test.go index b569742c48b5..e4b689d8606a 100644 --- a/third_party/terraform/tests/data_source_google_cloudfunctions_function_test.go +++ b/third_party/terraform/tests/data_source_google_cloudfunctions_function_test.go @@ -49,6 +49,7 @@ resource "google_storage_bucket_object" "archive" { resource "google_cloudfunctions_function" "function_http" { name = "%s-http" + runtime = "nodejs8" description = "test function" available_memory_mb = 128 source_archive_bucket = "${google_storage_bucket.bucket.name}" diff --git a/third_party/terraform/tests/data_source_google_organization_test.go b/third_party/terraform/tests/data_source_google_organization_test.go index 4f055dd5720f..319104e490fc 100644 --- a/third_party/terraform/tests/data_source_google_organization_test.go +++ b/third_party/terraform/tests/data_source_google_organization_test.go @@ -20,7 +20,7 @@ func TestAccDataSourceGoogleOrganization_byFullName(t *testing.T) { { Config: testAccCheckGoogleOrganization_byName(name), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.google_organization.org", "id", orgId), + resource.TestCheckResourceAttr("data.google_organization.org", "id", name), resource.TestCheckResourceAttr("data.google_organization.org", "name", name), ), }, @@ -39,7 +39,7 @@ func TestAccDataSourceGoogleOrganization_byShortName(t *testing.T) { { Config: testAccCheckGoogleOrganization_byName(orgId), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.google_organization.org", "id", orgId), + resource.TestCheckResourceAttr("data.google_organization.org", "id", name), resource.TestCheckResourceAttr("data.google_organization.org", "name", name), ), }, diff --git a/third_party/terraform/tests/resource_compute_disk_test.go.erb b/third_party/terraform/tests/resource_compute_disk_test.go.erb index 3d54d6d653be..2c9f446f8be2 100644 --- a/third_party/terraform/tests/resource_compute_disk_test.go.erb +++ b/third_party/terraform/tests/resource_compute_disk_test.go.erb @@ -468,12 +468,12 @@ func testAccCheckComputeDiskExists(n, p string, disk *compute.Disk) resource.Tes config := testAccProvider.Meta().(*Config) found, err := config.clientCompute.Disks.Get( - p, rs.Primary.Attributes["zone"], rs.Primary.ID).Do() + p, rs.Primary.Attributes["zone"], rs.Primary.Attributes["name"]).Do() if err != nil { return err } - if found.Name != rs.Primary.ID { + if found.Name != rs.Primary.Attributes["name"] { return fmt.Errorf("Disk not found") } diff --git a/third_party/terraform/tests/resource_compute_http_health_check_test.go b/third_party/terraform/tests/resource_compute_http_health_check_test.go index d1af7d14c7c7..cd18b78846c4 100644 --- a/third_party/terraform/tests/resource_compute_http_health_check_test.go +++ b/third_party/terraform/tests/resource_compute_http_health_check_test.go @@ -55,19 +55,19 @@ func testAccCheckComputeHttpHealthCheckExists(n string, healthCheck *compute.Htt return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") + if rs.Primary.Attributes["name"] == "" { + return fmt.Errorf("No name is set") } config := testAccProvider.Meta().(*Config) found, err := config.clientCompute.HttpHealthChecks.Get( - config.Project, rs.Primary.ID).Do() + config.Project, rs.Primary.Attributes["name"]).Do() if err != nil { return err } - if found.Name != rs.Primary.ID { + if found.Name != rs.Primary.Attributes["name"] { return fmt.Errorf("HttpHealthCheck not found") } diff --git a/third_party/terraform/tests/resource_compute_image_test.go b/third_party/terraform/tests/resource_compute_image_test.go index 59a956375e19..336a6eb931b9 100644 --- a/third_party/terraform/tests/resource_compute_image_test.go +++ b/third_party/terraform/tests/resource_compute_image_test.go @@ -107,19 +107,19 @@ func testAccCheckComputeImageExists(n string, image *compute.Image) resource.Tes return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") + if rs.Primary.Attributes["name"] == "" { + return fmt.Errorf("No name is set") } config := testAccProvider.Meta().(*Config) found, err := config.clientCompute.Images.Get( - config.Project, rs.Primary.ID).Do() + config.Project, rs.Primary.Attributes["name"]).Do() if err != nil { return err } - if found.Name != rs.Primary.ID { + if found.Name != rs.Primary.Attributes["name"] { return fmt.Errorf("Image not found") } diff --git a/third_party/terraform/tests/resource_compute_instance_from_template_test.go b/third_party/terraform/tests/resource_compute_instance_from_template_test.go index 84d5d77d064b..283fa38e367c 100644 --- a/third_party/terraform/tests/resource_compute_instance_from_template_test.go +++ b/third_party/terraform/tests/resource_compute_instance_from_template_test.go @@ -246,6 +246,7 @@ resource "google_compute_instance_template" "foobar" { disk_type = "local-ssd" type = "SCRATCH" interface = "NVME" + disk_size_gb = 375 } network_interface { @@ -447,6 +448,8 @@ resource "google_compute_instance_template" "template" { disk { type = "SCRATCH" + disk_type = "local-ssd" + disk_size_gb = 375 interface = "SCSI" auto_delete = true boot = false diff --git a/third_party/terraform/tests/resource_compute_network_test.go b/third_party/terraform/tests/resource_compute_network_test.go index 9652cf4f08a4..ffea9c27cdae 100644 --- a/third_party/terraform/tests/resource_compute_network_test.go +++ b/third_party/terraform/tests/resource_compute_network_test.go @@ -147,19 +147,19 @@ func testAccCheckComputeNetworkExists(n string, network *compute.Network) resour return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { + if rs.Primary.Attributes["name"] == "" { return fmt.Errorf("No ID is set") } config := testAccProvider.Meta().(*Config) found, err := config.clientCompute.Networks.Get( - config.Project, rs.Primary.ID).Do() + config.Project, rs.Primary.Attributes["name"]).Do() if err != nil { return err } - if found.Name != rs.Primary.ID { + if found.Name != rs.Primary.Attributes["name"] { return fmt.Errorf("Network not found") } diff --git a/third_party/terraform/tests/resource_compute_region_disk_test.go b/third_party/terraform/tests/resource_compute_region_disk_test.go index cb1b2c498ef9..9f7e737affd5 100644 --- a/third_party/terraform/tests/resource_compute_region_disk_test.go +++ b/third_party/terraform/tests/resource_compute_region_disk_test.go @@ -183,19 +183,19 @@ func testAccCheckComputeRegionDiskExists(n string, disk *computeBeta.Disk) resou return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { + if rs.Primary.Attributes["name"] == "" { return fmt.Errorf("No ID is set") } config := testAccProvider.Meta().(*Config) found, err := config.clientComputeBeta.RegionDisks.Get( - p, rs.Primary.Attributes["region"], rs.Primary.ID).Do() + p, rs.Primary.Attributes["region"], rs.Primary.Attributes["name"]).Do() if err != nil { return err } - if found.Name != rs.Primary.ID { + if found.Name != rs.Primary.Attributes["name"] { return fmt.Errorf("RegionDisk not found") }