Added a test acceptance for the new functionality.
GOOGLE_COMPUTE_DISK_SNAPSHOT_URI must be set to a valid snapshot's uri like one of the output of gcloud compute snapshots list --uri GOOGLE_COMPUTE_DISK_SNAPSHOT_URI should be replaced by a proper snapshot made by TF (#11690)
This commit is contained in:
parent
674d635926
commit
4df07f2ed9
|
@ -78,6 +78,10 @@ func testAccPreCheck(t *testing.T) {
|
|||
if v := os.Getenv("GOOGLE_XPN_HOST_PROJECT"); v == "" {
|
||||
t.Fatal("GOOGLE_XPN_HOST_PROJECT must be set for acceptance tests")
|
||||
}
|
||||
|
||||
if v := os.Getenv("GOOGLE_COMPUTE_DISK_SNAPSHOT_URI"); v == "" {
|
||||
t.Fatal("GOOGLE_COMPUTE_DISK_SNAPSHOT_URI must be set for acceptance tests")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvider_getRegionFromZone(t *testing.T) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package google
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
|
@ -30,6 +31,26 @@ func TestAccComputeDisk_basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccComputeDisk_from_snapshot_uri(t *testing.T) {
|
||||
diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
||||
var disk compute.Disk
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckComputeDiskDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeDisk_from_snapshot_uri(diskName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeDiskExists(
|
||||
"google_compute_disk.foobar", &disk),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccComputeDisk_encryption(t *testing.T) {
|
||||
diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
||||
var disk compute.Disk
|
||||
|
@ -130,6 +151,17 @@ resource "google_compute_disk" "foobar" {
|
|||
}`, diskName)
|
||||
}
|
||||
|
||||
func testAccComputeDisk_from_snapshot_uri(diskName string) string {
|
||||
uri := os.Getenv("GOOGLE_COMPUTE_DISK_SNAPSHOT_URI")
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_disk" "foobar" {
|
||||
name = "%s"
|
||||
snapshot = "%s"
|
||||
type = "pd-ssd"
|
||||
zone = "us-central1-a"
|
||||
}`, diskName, uri)
|
||||
}
|
||||
|
||||
func testAccComputeDisk_encryption(diskName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_disk" "foobar" {
|
||||
|
|
Loading…
Reference in New Issue