Skip to content

Commit

Permalink
Add support for region boot disk to instance (#8718) (#6132)
Browse files Browse the repository at this point in the history
Remove wrong files

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Aug 22, 2023
1 parent b7a1616 commit 38f1090
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/8718.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added support for specifying regional disks for `google_compute_instance` `boot_disk.source`
```
10 changes: 9 additions & 1 deletion google-beta/services/compute/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2526,7 +2526,15 @@ func expandBootDisk(d *schema.ResourceData, config *transport_tpg.Config, projec
}

if v, ok := d.GetOk("boot_disk.0.source"); ok {
source, err := tpgresource.ParseDiskFieldValue(v.(string), d, config)
var err error
var source interface {
RelativeLink() string
}
if strings.Contains(v.(string), "regions/") {
source, err = tpgresource.ParseRegionDiskFieldValue(v.(string), d, config)
} else {
source, err = tpgresource.ParseDiskFieldValue(v.(string), d, config)
}
if err != nil {
return nil, err
}
Expand Down
74 changes: 74 additions & 0 deletions google-beta/services/compute/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,31 @@ func TestAccComputeInstance_metadataStartupScript_update(t *testing.T) {
})
}

func TestAccComputeInstance_regionBootDisk(t *testing.T) {
t.Parallel()

var instance compute.Instance
var instanceName = fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
var diskName = fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
var suffix = acctest.RandString(t, 10)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeInstance_regionBootDisk(instanceName, diskName, suffix),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(
t, "google_compute_instance.regional_vm_instance", &instance),
testAccCheckComputeInstanceBootDisk(&instance, diskName),
),
},
},
})
}

func testAccCheckComputeInstanceUpdateMachineType(t *testing.T, n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -6741,3 +6766,52 @@ resource "google_compute_instance" "foobar" {
}
`, instance, machineType, metadata)
}

func testAccComputeInstance_regionBootDisk(instance, diskName, suffix string) string {
return fmt.Sprintf(`
resource "google_compute_instance" "regional_vm_instance" {
name = "%s"
machine_type = "e2-medium"
zone = "us-central1-c"
boot_disk {
source = google_compute_region_disk.regionaldisk.self_link
}
network_interface {
network = google_compute_network.vpc_network.name
access_config {}
}
}
resource "google_compute_region_disk" "regionaldisk" {
name = "%s"
type = "pd-ssd"
region = "us-central1"
replica_zones = ["us-central1-c", "us-central1-a"]
size = 50
snapshot = google_compute_snapshot.debian.id
}
resource "google_compute_network" "vpc_network" {
name = "tf-test-%s"
}
data "google_compute_image" "debian" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_snapshot" "debian" {
name = "tf-test-%s"
source_disk = google_compute_disk.debian.id
}
resource "google_compute_disk" "debian" {
name = "tf-test-%s"
image = data.google_compute_image.debian.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-c"
}
`, instance, diskName, suffix, suffix, suffix)
}

0 comments on commit 38f1090

Please sign in to comment.