2017-03-07 09:49:02 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
)
|
|
|
|
|
2018-12-14 17:50:01 +00:00
|
|
|
func TestAccComputeSnapshot_encryption(t *testing.T) {
|
2018-12-05 20:41:08 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
snapshotName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeSnapshotDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2018-12-14 17:50:01 +00:00
|
|
|
{
|
2018-12-05 20:41:08 +00:00
|
|
|
Config: testAccComputeSnapshot_encryption(snapshotName, diskName),
|
|
|
|
},
|
2018-12-14 17:50:01 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_compute_snapshot.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"zone", "snapshot_encryption_key", "source_disk_encryption_key"},
|
2018-12-05 20:41:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-07 09:49:02 +00:00
|
|
|
func testAccComputeSnapshot_encryption(snapshotName string, diskName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2018-07-10 12:31:34 +00:00
|
|
|
data "google_compute_image" "my_image" {
|
2018-08-14 18:18:39 +00:00
|
|
|
family = "debian-9"
|
2018-07-10 12:31:34 +00:00
|
|
|
project = "debian-cloud"
|
|
|
|
}
|
|
|
|
|
2018-08-15 20:26:02 +00:00
|
|
|
resource "google_compute_disk" "foobar" {
|
2017-03-07 09:49:02 +00:00
|
|
|
name = "%s"
|
2018-07-10 12:31:34 +00:00
|
|
|
image = "${data.google_compute_image.my_image.self_link}"
|
2017-03-13 11:27:22 +00:00
|
|
|
size = 10
|
2017-03-07 09:49:02 +00:00
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
2018-10-10 18:34:36 +00:00
|
|
|
disk_encryption_key {
|
|
|
|
raw_key = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0="
|
|
|
|
}
|
2017-03-07 09:49:02 +00:00
|
|
|
}
|
2018-12-05 20:41:08 +00:00
|
|
|
|
|
|
|
resource "google_compute_snapshot" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
source_disk = "${google_compute_disk.foobar.name}"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
snapshot_encryption_key {
|
|
|
|
raw_key = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0="
|
|
|
|
}
|
|
|
|
|
|
|
|
source_disk_encryption_key {
|
|
|
|
raw_key = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0="
|
|
|
|
}
|
|
|
|
}`, diskName, snapshotName)
|
|
|
|
}
|