Enable use of URI for snapshot name
This commit is contained in:
parent
3df593315f
commit
e510289d2b
|
@ -3,6 +3,7 @@ package google
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"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 {
|
||||
snapshotName := v.(string)
|
||||
log.Printf("[DEBUG] Loading snapshot: %s", snapshotName)
|
||||
snapshotData, err := config.clientCompute.Snapshots.Get(
|
||||
project, snapshotName).Do()
|
||||
match, _ := regexp.MatchString("^http", snapshotName)
|
||||
if match {
|
||||
disk.SourceSnapshot = snapshotName
|
||||
} else {
|
||||
log.Printf("[DEBUG] Loading snapshot: %s", snapshotName)
|
||||
snapshotData, err := config.clientCompute.Snapshots.Get(
|
||||
project, snapshotName).Do()
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error loading snapshot '%s': %s",
|
||||
snapshotName, err)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error loading snapshot '%s': %s",
|
||||
snapshotName, err)
|
||||
}
|
||||
disk.SourceSnapshot = snapshotData.SelfLink
|
||||
}
|
||||
|
||||
disk.SourceSnapshot = snapshotData.SelfLink
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("disk_encryption_key_raw"); ok {
|
||||
|
|
Loading…
Reference in New Issue