diff --git a/google/resource_bigtable_instance.go b/google/resource_bigtable_instance.go index aa020815b57..0a09c1728ed 100644 --- a/google/resource_bigtable_instance.go +++ b/google/resource_bigtable_instance.go @@ -34,20 +34,24 @@ func resourceBigtableInstance() *schema.Resource { "cluster_id": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "zone": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "num_nodes": { Type: schema.TypeInt, Optional: true, + ForceNew: true, ValidateFunc: validation.IntAtLeast(3), }, "storage_type": { Type: schema.TypeString, Optional: true, Default: "SSD", + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{"SSD", "HDD"}, false), }, }, diff --git a/google/resource_bigtable_instance_test.go b/google/resource_bigtable_instance_test.go index a00189d3af7..cf878307a33 100644 --- a/google/resource_bigtable_instance_test.go +++ b/google/resource_bigtable_instance_test.go @@ -21,7 +21,14 @@ func TestAccBigtableInstance_basic(t *testing.T) { CheckDestroy: testAccCheckBigtableInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccBigtableInstance(instanceName), + Config: testAccBigtableInstance(instanceName, 3), + Check: resource.ComposeTestCheckFunc( + testAccBigtableInstanceExists( + "google_bigtable_instance.instance"), + ), + }, + { + Config: testAccBigtableInstance(instanceName, 4), Check: resource.ComposeTestCheckFunc( testAccBigtableInstanceExists( "google_bigtable_instance.instance"), @@ -125,18 +132,18 @@ func testAccBigtableInstanceExists(n string) resource.TestCheckFunc { } } -func testAccBigtableInstance(instanceName string) string { +func testAccBigtableInstance(instanceName string, numNodes int) string { return fmt.Sprintf(` resource "google_bigtable_instance" "instance" { name = "%s" cluster { cluster_id = "%s" zone = "us-central1-b" - num_nodes = 3 + num_nodes = %d storage_type = "HDD" } } -`, instanceName, instanceName) +`, instanceName, instanceName, numNodes) } func testAccBigtableInstance_cluster(instanceName string) string { diff --git a/google/resource_compute_attached_disk.go b/google/resource_compute_attached_disk.go index 829ab484f0f..46817fc7fd6 100644 --- a/google/resource_compute_attached_disk.go +++ b/google/resource_compute_attached_disk.go @@ -76,10 +76,21 @@ func resourceAttachedDiskCreate(d *schema.ResourceData, meta interface{}) error return err } - diskName := GetResourceNameFromSelfLink(d.Get("disk").(string)) + disk := d.Get("disk").(string) + diskName := GetResourceNameFromSelfLink(disk) + diskSrc := fmt.Sprintf("projects/%s/zones/%s/disks/%s", zv.Project, zv.Zone, diskName) + + // Check if the disk is a regional disk + if strings.Contains(disk, "regions") { + rv, err := ParseRegionDiskFieldValue(disk, d, config) + if err != nil { + return err + } + diskSrc = fmt.Sprintf("projects/%s/regions/%s/disks/%s", rv.Project, rv.Region, diskName) + } attachedDisk := compute.AttachedDisk{ - Source: fmt.Sprintf("projects/%s/zones/%s/disks/%s", zv.Project, zv.Zone, diskName), + Source: diskSrc, Mode: d.Get("mode").(string), DeviceName: d.Get("device_name").(string), } diff --git a/google/resource_compute_attached_disk_test.go b/google/resource_compute_attached_disk_test.go index 9d9cef7087f..089b9d84a72 100644 --- a/google/resource_compute_attached_disk_test.go +++ b/google/resource_compute_attached_disk_test.go @@ -68,6 +68,33 @@ func TestAccComputeAttachedDisk_full(t *testing.T) { } +func TestAccComputeAttachedDisk_region(t *testing.T) { + t.Parallel() + + diskName := acctest.RandomWithPrefix("tf-test") + instanceName := acctest.RandomWithPrefix("tf-test") + importID := fmt.Sprintf("%s/us-central1-a/%s:%s", getTestProjectFromEnv(), instanceName, diskName) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + // Check destroy isn't a good test here, see comment on testCheckAttachedDiskIsNowDetached + CheckDestroy: nil, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAttachedDiskResource_region(diskName, instanceName), + }, + resource.TestStep{ + ResourceName: "google_compute_attached_disk.test", + ImportStateId: importID, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) + +} + func TestAccComputeAttachedDisk_count(t *testing.T) { t.Parallel() @@ -152,6 +179,43 @@ resource "google_compute_attached_disk" "test" { }`) } +func testAttachedDiskResource_region(diskName, instanceName string) string { + return fmt.Sprintf(` +resource "google_compute_attached_disk" "test" { + disk = "${google_compute_region_disk.region.self_link}" + instance = "${google_compute_instance.test.self_link}" +} + +resource "google_compute_region_disk" "region" { + name = "%s" + region = "us-central1" + size = 10 + replica_zones = ["us-central1-b", "us-central1-a"] +} + +resource "google_compute_instance" "test" { + name = "%s" + machine_type = "f1-micro" + zone = "us-central1-a" + + lifecycle { + ignore_changes = [ + "attached_disk", + ] + } + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + } + } + + network_interface { + network = "default" + } +}`, diskName, instanceName) +} + func testAttachedDiskResource(diskName, instanceName string) string { return fmt.Sprintf(` resource "google_compute_disk" "test1" {