Merge commit '96a67766bf94fdba15f607a9f620cc7df3675a9b' into paddy_fix_12278_rebase
This commit is contained in:
commit
f5ff3b987d
|
@ -78,6 +78,10 @@ func testAccPreCheck(t *testing.T) {
|
||||||
if v := os.Getenv("GOOGLE_XPN_HOST_PROJECT"); v == "" {
|
if v := os.Getenv("GOOGLE_XPN_HOST_PROJECT"); v == "" {
|
||||||
t.Fatal("GOOGLE_XPN_HOST_PROJECT must be set for acceptance tests")
|
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) {
|
func TestProvider_getRegionFromZone(t *testing.T) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package google
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"google.golang.org/api/compute/v1"
|
"google.golang.org/api/compute/v1"
|
||||||
|
@ -129,17 +130,21 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
if v, ok := d.GetOk("snapshot"); ok {
|
if v, ok := d.GetOk("snapshot"); ok {
|
||||||
snapshotName := v.(string)
|
snapshotName := v.(string)
|
||||||
log.Printf("[DEBUG] Loading snapshot: %s", snapshotName)
|
match, _ := regexp.MatchString("^https://www.googleapis.com/compute", snapshotName)
|
||||||
snapshotData, err := config.clientCompute.Snapshots.Get(
|
if match {
|
||||||
project, snapshotName).Do()
|
disk.SourceSnapshot = snapshotName
|
||||||
|
} else {
|
||||||
|
log.Printf("[DEBUG] Loading snapshot: %s", snapshotName)
|
||||||
|
snapshotData, err := config.clientCompute.Snapshots.Get(
|
||||||
|
project, snapshotName).Do()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Error loading snapshot '%s': %s",
|
"Error loading snapshot '%s': %s",
|
||||||
snapshotName, err)
|
snapshotName, err)
|
||||||
|
}
|
||||||
|
disk.SourceSnapshot = snapshotData.SelfLink
|
||||||
}
|
}
|
||||||
|
|
||||||
disk.SourceSnapshot = snapshotData.SelfLink
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("disk_encryption_key_raw"); ok {
|
if v, ok := d.GetOk("disk_encryption_key_raw"); ok {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
|
@ -30,6 +31,30 @@ func TestAccComputeDisk_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeDisk_from_snapshot_uri(t *testing.T) {
|
||||||
|
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")
|
||||||
|
|
||||||
|
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(firstDiskName, snapshotName, diskName, xpn_host),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeDiskExists(
|
||||||
|
"google_compute_disk.seconddisk", &disk),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccComputeDisk_encryption(t *testing.T) {
|
func TestAccComputeDisk_encryption(t *testing.T) {
|
||||||
diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
||||||
var disk compute.Disk
|
var disk compute.Disk
|
||||||
|
@ -130,6 +155,31 @@ resource "google_compute_disk" "foobar" {
|
||||||
}`, diskName)
|
}`, diskName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccComputeDisk_from_snapshot_uri(firstDiskName string, snapshotName string, diskName string, xpn_host string) string {
|
||||||
|
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_compute_snapshot" "snapdisk" {
|
||||||
|
name = "%s"
|
||||||
|
source_disk = "${google_compute_disk.foobar.name}"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
project = "%s"
|
||||||
|
}
|
||||||
|
resource "google_compute_disk" "seconddisk" {
|
||||||
|
name = "%s"
|
||||||
|
snapshot = "${google_compute_snapshot.snapdisk.self_link}"
|
||||||
|
type = "pd-ssd"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
}`, firstDiskName, xpn_host, snapshotName, xpn_host, diskName)
|
||||||
|
}
|
||||||
|
|
||||||
func testAccComputeDisk_encryption(diskName string) string {
|
func testAccComputeDisk_encryption(diskName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_disk" "foobar" {
|
resource "google_compute_disk" "foobar" {
|
||||||
|
|
Loading…
Reference in New Issue