mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
providers/google: Don't fail deleting disks that don't exist.
Addresses #5942
This commit is contained in:
parent
a2950c76d9
commit
f075b0214d
@ -184,6 +184,12 @@ func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error {
|
|||||||
op, err := config.clientCompute.Disks.Delete(
|
op, err := config.clientCompute.Disks.Delete(
|
||||||
project, d.Get("zone").(string), d.Id()).Do()
|
project, d.Get("zone").(string), d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||||
|
log.Printf("[WARN] Removing Disk %q because it's gone", d.Get("name").(string))
|
||||||
|
// The resource doesn't exist anymore
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error deleting disk: %s", err)
|
return fmt.Errorf("Error deleting disk: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ func TestAccComputeInstance_IP(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccComputeInstance_disks(t *testing.T) {
|
func TestAccComputeInstance_disksWithoutAutodelete(t *testing.T) {
|
||||||
var instance compute.Instance
|
var instance compute.Instance
|
||||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||||
var diskName = fmt.Sprintf("instance-testd-%s", acctest.RandString(10))
|
var diskName = fmt.Sprintf("instance-testd-%s", acctest.RandString(10))
|
||||||
@ -137,7 +137,7 @@ func TestAccComputeInstance_disks(t *testing.T) {
|
|||||||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeInstance_disks(diskName, instanceName),
|
Config: testAccComputeInstance_disks(diskName, instanceName, false),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckComputeInstanceExists(
|
testAccCheckComputeInstanceExists(
|
||||||
"google_compute_instance.foobar", &instance),
|
"google_compute_instance.foobar", &instance),
|
||||||
@ -149,6 +149,29 @@ func TestAccComputeInstance_disks(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeInstance_disksWithAutodelete(t *testing.T) {
|
||||||
|
var instance compute.Instance
|
||||||
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||||
|
var diskName = fmt.Sprintf("instance-testd-%s", acctest.RandString(10))
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeInstance_disks(diskName, instanceName, true),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeInstanceExists(
|
||||||
|
"google_compute_instance.foobar", &instance),
|
||||||
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
||||||
|
testAccCheckComputeInstanceDisk(&instance, diskName, true, false),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccComputeInstance_local_ssd(t *testing.T) {
|
func TestAccComputeInstance_local_ssd(t *testing.T) {
|
||||||
var instance compute.Instance
|
var instance compute.Instance
|
||||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||||
@ -702,7 +725,7 @@ func testAccComputeInstance_ip(ip, instance string) string {
|
|||||||
}`, ip, instance)
|
}`, ip, instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccComputeInstance_disks(disk, instance string) string {
|
func testAccComputeInstance_disks(disk, instance string, autodelete bool) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_disk" "foobar" {
|
resource "google_compute_disk" "foobar" {
|
||||||
name = "%s"
|
name = "%s"
|
||||||
@ -722,7 +745,7 @@ func testAccComputeInstance_disks(disk, instance string) string {
|
|||||||
|
|
||||||
disk {
|
disk {
|
||||||
disk = "${google_compute_disk.foobar.name}"
|
disk = "${google_compute_disk.foobar.name}"
|
||||||
auto_delete = false
|
auto_delete = %v
|
||||||
}
|
}
|
||||||
|
|
||||||
network_interface {
|
network_interface {
|
||||||
@ -732,7 +755,7 @@ func testAccComputeInstance_disks(disk, instance string) string {
|
|||||||
metadata {
|
metadata {
|
||||||
foo = "bar"
|
foo = "bar"
|
||||||
}
|
}
|
||||||
}`, disk, instance)
|
}`, disk, instance, autodelete)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccComputeInstance_local_ssd(instance string) string {
|
func testAccComputeInstance_local_ssd(instance string) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user