Skip to content

Remove all instances of GOOGLE_XPN_HOST_PROJECT environment variable. #815

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

Merged
merged 6 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
76 changes: 45 additions & 31 deletions google/resource_compute_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package google

import (
"fmt"
"os"
"regexp"
"strconv"
"testing"
"time"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
Expand All @@ -28,7 +28,7 @@ func TestAccComputeDisk_basic(t *testing.T) {
Config: testAccComputeDisk_basic(diskName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
"google_compute_disk.foobar", &disk),
"google_compute_disk.foobar", getTestProjectFromEnv(), &disk),
testAccCheckComputeDiskHasLabel(&disk, "my-label", "my-label-value"),
testAccCheckComputeDiskHasLabelFingerprint(&disk, "google_compute_disk.foobar"),
),
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestAccComputeDisk_update(t *testing.T) {
Config: testAccComputeDisk_basic(diskName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
"google_compute_disk.foobar", &disk),
"google_compute_disk.foobar", getTestProjectFromEnv(), &disk),
resource.TestCheckResourceAttr("google_compute_disk.foobar", "size", "50"),
testAccCheckComputeDiskHasLabel(&disk, "my-label", "my-label-value"),
testAccCheckComputeDiskHasLabelFingerprint(&disk, "google_compute_disk.foobar"),
Expand All @@ -76,7 +76,7 @@ func TestAccComputeDisk_update(t *testing.T) {
Config: testAccComputeDisk_updated(diskName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
"google_compute_disk.foobar", &disk),
"google_compute_disk.foobar", getTestProjectFromEnv(), &disk),
resource.TestCheckResourceAttr("google_compute_disk.foobar", "size", "100"),
testAccCheckComputeDiskHasLabel(&disk, "my-label", "my-updated-label-value"),
testAccCheckComputeDiskHasLabel(&disk, "a-new-label", "a-new-label-value"),
Expand All @@ -90,12 +90,12 @@ func TestAccComputeDisk_update(t *testing.T) {
func TestAccComputeDisk_fromSnapshot(t *testing.T) {
t.Parallel()

skipIfEnvNotSet(t, "GOOGLE_XPN_HOST_PROJECT")

diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
firstDiskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
snapshotName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
var xpn_host = os.Getenv("GOOGLE_XPN_HOST_PROJECT")
org := getTestOrgFromEnv(t)
billingId := getTestBillingAccountFromEnv(t)
projectName := fmt.Sprintf("tf-disktest-%d", time.Now().Unix())

var disk compute.Disk

Expand All @@ -105,17 +105,17 @@ func TestAccComputeDisk_fromSnapshot(t *testing.T) {
CheckDestroy: testAccCheckComputeDiskDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeDisk_fromSnapshot(firstDiskName, snapshotName, diskName, xpn_host, "self_link"),
Config: testAccComputeDisk_fromSnapshot(projectName, firstDiskName, snapshotName, diskName, org, billingId, "self_link"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
"google_compute_disk.seconddisk", &disk),
"google_compute_disk.seconddisk", projectName, &disk),
),
},
resource.TestStep{
Config: testAccComputeDisk_fromSnapshot(firstDiskName, snapshotName, diskName, xpn_host, "name"),
Config: testAccComputeDisk_fromSnapshot(projectName, firstDiskName, snapshotName, diskName, org, billingId, "name"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
"google_compute_disk.seconddisk", &disk),
"google_compute_disk.seconddisk", projectName, &disk),
),
},
},
Expand All @@ -137,7 +137,7 @@ func TestAccComputeDisk_encryption(t *testing.T) {
Config: testAccComputeDisk_encryption(diskName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
"google_compute_disk.foobar", &disk),
"google_compute_disk.foobar", getTestProjectFromEnv(), &disk),
testAccCheckEncryptionKey(
"google_compute_disk.foobar", &disk),
),
Expand All @@ -162,7 +162,7 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) {
Config: testAccComputeDisk_deleteDetach(instanceName, diskName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
"google_compute_disk.foo", &disk),
"google_compute_disk.foo", getTestProjectFromEnv(), &disk),
),
},
// this needs to be a second step so we refresh and see the instance
Expand All @@ -173,7 +173,7 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) {
Config: testAccComputeDisk_deleteDetach(instanceName, diskName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
"google_compute_disk.foo", &disk),
"google_compute_disk.foo", getTestProjectFromEnv(), &disk),
testAccCheckComputeDiskInstances(
"google_compute_disk.foo", &disk),
),
Expand All @@ -200,7 +200,7 @@ func testAccCheckComputeDiskDestroy(s *terraform.State) error {
return nil
}

func testAccCheckComputeDiskExists(n string, disk *compute.Disk) resource.TestCheckFunc {
func testAccCheckComputeDiskExists(n, p string, disk *compute.Disk) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
Expand All @@ -214,7 +214,7 @@ func testAccCheckComputeDiskExists(n string, disk *compute.Disk) resource.TestCh
config := testAccProvider.Meta().(*Config)

found, err := config.clientCompute.Disks.Get(
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
p, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
if err != nil {
return err
}
Expand Down Expand Up @@ -345,29 +345,43 @@ resource "google_compute_disk" "foobar" {
}`, diskName)
}

func testAccComputeDisk_fromSnapshot(firstDiskName, snapshotName, diskName, xpn_host string, ref_selector string) string {
func testAccComputeDisk_fromSnapshot(projectName, firstDiskName, snapshotName, diskName, org, billingId, ref_selector string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this test using the XPN project in the first place instead of the regular test project?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure - I can't see any reason that it ought to be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should re-write it using the default test project to avoid having to create extra test project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and done.

return fmt.Sprintf(`
resource "google_compute_disk" "foobar" {
name = "%s"
image = "debian-8-jessie-v20160803"
size = 50
type = "pd-ssd"
zone = "us-central1-a"
project = "%s"
}
resource "google_project" "project" {
name = "Test Project"
project_id = "%s"
org_id = "%s"
billing_account = "%s"
}

resource "google_project_service" "project" {
project = "${google_project.project.project_id}"
service = "compute.googleapis.com"
}

resource "google_compute_disk" "foobar" {
name = "d1-%s"
image = "debian-8-jessie-v20160803"
size = 50
type = "pd-ssd"
zone = "us-central1-a"
project = "${google_project_service.project.project}"
}

resource "google_compute_snapshot" "snapdisk" {
name = "%s"
source_disk = "${google_compute_disk.foobar.name}"
zone = "us-central1-a"
project = "%s"
name = "%s"
source_disk = "${google_compute_disk.foobar.name}"
zone = "us-central1-a"
project = "${google_project_service.project.project}"
}

resource "google_compute_disk" "seconddisk" {
name = "%s"
name = "d2-%s"
snapshot = "${google_compute_snapshot.snapdisk.%s}"
type = "pd-ssd"
zone = "us-central1-a"
}`, firstDiskName, xpn_host, snapshotName, xpn_host, diskName, ref_selector)
project = "${google_project_service.project.project}"
}`, projectName, org, billingId, firstDiskName, snapshotName, diskName, ref_selector)
}

func testAccComputeDisk_encryption(diskName string) string {
Expand Down
Loading