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

Test fixes based on integration tests, id formats + other easy fixes #2605

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 6 additions & 4 deletions third_party/terraform/resources/resource_bigtable_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
},
Expand All @@ -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),
),
},
Expand Down
4 changes: 2 additions & 2 deletions third_party/terraform/tests/resource_compute_disk_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
8 changes: 4 additions & 4 deletions third_party/terraform/tests/resource_compute_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ resource "google_compute_instance_template" "foobar" {
disk_type = "local-ssd"
type = "SCRATCH"
interface = "NVME"
disk_size_gb = 375
}

network_interface {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions third_party/terraform/tests/resource_compute_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down