Skip to content

Commit 707b4da

Browse files
Enable deletion for statefulIps. (#7075) (#13428)
* compute: Enabled deletion for `statefulIps` fields in `instance_group_manager` and `region_instance_group_manager`. Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 5d96319 commit 707b4da

5 files changed

+191
-0
lines changed

.changelog/7075.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: Enabled deletion for `statefulIps` fields in `instance_group_manager` and `region_instance_group_manager`.
3+
```

google/resource_compute_instance_group_manager_test.go

+82
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,15 @@ func TestAccInstanceGroupManager_stateful(t *testing.T) {
392392
ImportStateVerify: true,
393393
ImportStateVerifyIgnore: []string{"status"},
394394
},
395+
{
396+
Config: testAccInstanceGroupManager_statefulRemoved(network, template, target, igm),
397+
},
398+
{
399+
ResourceName: "google_compute_instance_group_manager.igm-basic",
400+
ImportState: true,
401+
ImportStateVerify: true,
402+
ImportStateVerifyIgnore: []string{"status"},
403+
},
395404
},
396405
})
397406
}
@@ -1494,6 +1503,79 @@ resource "google_compute_http_health_check" "zero" {
14941503
`, network, template, target, igm, hck)
14951504
}
14961505

1506+
func testAccInstanceGroupManager_statefulRemoved(network, template, target, igm string) string {
1507+
return fmt.Sprintf(`
1508+
data "google_compute_image" "my_image" {
1509+
family = "debian-11"
1510+
project = "debian-cloud"
1511+
}
1512+
1513+
resource "google_compute_network" "igm-basic" {
1514+
name = "%s"
1515+
}
1516+
1517+
resource "google_compute_instance_template" "igm-basic" {
1518+
name = "%s"
1519+
machine_type = "e2-medium"
1520+
can_ip_forward = false
1521+
tags = ["foo", "bar"]
1522+
disk {
1523+
source_image = data.google_compute_image.my_image.self_link
1524+
auto_delete = true
1525+
boot = true
1526+
device_name = "my-stateful-disk"
1527+
}
1528+
1529+
disk {
1530+
source_image = data.google_compute_image.my_image.self_link
1531+
auto_delete = true
1532+
device_name = "non-stateful"
1533+
}
1534+
1535+
disk {
1536+
source_image = data.google_compute_image.my_image.self_link
1537+
auto_delete = true
1538+
device_name = "my-stateful-disk2"
1539+
}
1540+
1541+
network_interface {
1542+
network = "default"
1543+
}
1544+
1545+
network_interface {
1546+
network = google_compute_network.igm-basic.self_link
1547+
}
1548+
1549+
service_account {
1550+
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
1551+
}
1552+
}
1553+
1554+
resource "google_compute_target_pool" "igm-basic" {
1555+
description = "Resource created for Terraform acceptance testing"
1556+
name = "%s"
1557+
session_affinity = "CLIENT_IP_PROTO"
1558+
}
1559+
1560+
resource "google_compute_instance_group_manager" "igm-basic" {
1561+
description = "Terraform test instance group manager"
1562+
name = "%s"
1563+
version {
1564+
instance_template = google_compute_instance_template.igm-basic.self_link
1565+
name = "prod"
1566+
}
1567+
target_pools = [google_compute_target_pool.igm-basic.self_link]
1568+
base_instance_name = "tf-test-igm-basic"
1569+
zone = "us-central1-c"
1570+
target_size = 2
1571+
stateful_disk {
1572+
device_name = "my-stateful-disk"
1573+
delete_rule = "NEVER"
1574+
}
1575+
}
1576+
`, network, template, target, igm)
1577+
}
1578+
14971579
func testAccInstanceGroupManager_waitForStatus(template, target, igm, perInstanceConfig string) string {
14981580
return fmt.Sprintf(`
14991581
data "google_compute_image" "my_image" {

google/resource_compute_region_instance_group_manager_test.go

+74
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,15 @@ func TestAccRegionInstanceGroupManager_stateful(t *testing.T) {
398398
ImportStateVerify: true,
399399
ImportStateVerifyIgnore: []string{"status"},
400400
},
401+
{
402+
Config: testAccRegionInstanceGroupManager_statefulRemoved(template, network, igm),
403+
},
404+
{
405+
ResourceName: "google_compute_region_instance_group_manager.igm-basic",
406+
ImportState: true,
407+
ImportStateVerify: true,
408+
ImportStateVerifyIgnore: []string{"status"},
409+
},
401410
},
402411
})
403412
}
@@ -1440,3 +1449,68 @@ resource "google_compute_region_instance_group_manager" "igm-basic" {
14401449
}
14411450
`, network, template, igm)
14421451
}
1452+
1453+
func testAccRegionInstanceGroupManager_statefulRemoved(network, template, igm string) string {
1454+
return fmt.Sprintf(`
1455+
data "google_compute_image" "my_image" {
1456+
family = "debian-11"
1457+
project = "debian-cloud"
1458+
}
1459+
resource "google_compute_network" "igm-basic" {
1460+
name = "%s"
1461+
}
1462+
resource "google_compute_instance_template" "igm-basic" {
1463+
name = "%s"
1464+
machine_type = "e2-medium"
1465+
can_ip_forward = false
1466+
tags = ["foo", "bar"]
1467+
disk {
1468+
source_image = data.google_compute_image.my_image.self_link
1469+
auto_delete = true
1470+
boot = true
1471+
device_name = "stateful-disk"
1472+
}
1473+
disk {
1474+
source_image = data.google_compute_image.my_image.self_link
1475+
auto_delete = true
1476+
device_name = "stateful-disk2"
1477+
}
1478+
network_interface {
1479+
network = "default"
1480+
}
1481+
network_interface {
1482+
network = google_compute_network.igm-basic.self_link
1483+
}
1484+
}
1485+
1486+
resource "google_compute_region_instance_group_manager" "igm-basic" {
1487+
description = "Terraform test instance group manager"
1488+
name = "%s"
1489+
1490+
version {
1491+
instance_template = google_compute_instance_template.igm-basic.self_link
1492+
name = "primary"
1493+
}
1494+
1495+
base_instance_name = "tf-test-igm-basic"
1496+
region = "us-central1"
1497+
target_size = 2
1498+
1499+
update_policy {
1500+
instance_redistribution_type = "NONE"
1501+
type = "OPPORTUNISTIC"
1502+
minimal_action = "REPLACE"
1503+
max_surge_fixed = 0
1504+
max_unavailable_fixed = 6
1505+
}
1506+
stateful_disk {
1507+
device_name = "stateful-disk"
1508+
delete_rule = "NEVER"
1509+
}
1510+
stateful_disk {
1511+
device_name = "stateful-disk2"
1512+
delete_rule = "ON_PERMANENT_INSTANCE_DELETION"
1513+
}
1514+
}
1515+
`, network, template, igm)
1516+
}

website/docs/r/compute_instance_group_manager.html.markdown

+16
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ group. You can specify only one value. Structure is [documented below](#nested_a
160160

161161
* `stateful_disk` - (Optional) Disks created on the instances that will be preserved on instance delete, update, etc. Structure is [documented below](#nested_stateful_disk). For more information see the [official documentation](https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-disks-in-migs).
162162

163+
* `stateful_internal_ip` - (Optional, [Beta](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_versions.html)) Internal network IPs assigned to the instances that will be preserved on instance delete, update, etc. This map is keyed with the network interface name. Structure is [documented below](#nested_stateful_internal_ip).
164+
165+
* `stateful_external_ip` - (Optional, [Beta](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_versions.html)) External network IPs assigned to the instances that will be preserved on instance delete, update, etc. This map is keyed with the network interface name. Structure is [documented below](#nested_stateful_external_ip).
166+
163167
* `update_policy` - (Optional) The update policy for this managed instance group. Structure is [documented below](#nested_update_policy). For more information, see the [official documentation](https://cloud.google.com/compute/docs/instance-groups/updating-managed-instance-groups) and [API](https://cloud.google.com/compute/docs/reference/rest/v1/instanceGroupManagers/patch)
164168

165169
- - -
@@ -277,6 +281,18 @@ one of which has a `target_size.percent` of `60` will create 2 instances of that
277281

278282
* `delete_rule` - (Optional), A value that prescribes what should happen to the stateful disk when the VM instance is deleted. The available options are `NEVER` and `ON_PERMANENT_INSTANCE_DELETION`. `NEVER` - detach the disk when the VM is deleted, but do not delete the disk. `ON_PERMANENT_INSTANCE_DELETION` will delete the stateful disk when the VM is permanently deleted from the instance group. The default is `NEVER`.
279283

284+
<a name="nested_stateful_internal_ip"></a>The `stateful_internal_ip` block supports:
285+
286+
* `network_interface_name` - (Required), The network interface name of the internal Ip.
287+
288+
* `delete_rule` - (Optional), A value that prescribes what should happen to the internal ip when the VM instance is deleted. The available options are `NEVER` and `ON_PERMANENT_INSTANCE_DELETION`. `NEVER` - detach the ip when the VM is deleted, but do not delete the ip. `ON_PERMANENT_INSTANCE_DELETION` will delete the internal ip when the VM is permanently deleted from the instance group.
289+
290+
<a name="nested_stateful_external_ip"></a>The `stateful_external_ip` block supports:
291+
292+
* `network_interface_name` - (Required), The network interface name of the external Ip.
293+
294+
* `delete_rule` - (Optional), A value that prescribes what should happen to the external ip when the VM instance is deleted. The available options are `NEVER` and `ON_PERMANENT_INSTANCE_DELETION`. `NEVER` - detach the ip when the VM is deleted, but do not delete the ip. `ON_PERMANENT_INSTANCE_DELETION` will delete the external ip when the VM is permanently deleted from the instance group.
295+
280296
## Attributes Reference
281297

282298
In addition to the arguments listed above, the following computed attributes are

website/docs/r/compute_region_instance_group_manager.html.markdown

+16
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ group. You can specify one or more values. For more information, see the [offici
169169

170170
* `stateful_disk` - (Optional) Disks created on the instances that will be preserved on instance delete, update, etc. Structure is [documented below](#nested_stateful_disk). For more information see the [official documentation](https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-disks-in-migs). Proactive cross zone instance redistribution must be disabled before you can update stateful disks on existing instance group managers. This can be controlled via the `update_policy`.
171171

172+
* `stateful_internal_ip` - (Optional, [Beta](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_versions.html)) Internal network IPs assigned to the instances that will be preserved on instance delete, update, etc. This map is keyed with the network interface name. Structure is [documented below](#nested_stateful_internal_ip).
173+
174+
* `stateful_external_ip` - (Optional, [Beta](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_versions.html)) External network IPs assigned to the instances that will be preserved on instance delete, update, etc. This map is keyed with the network interface name. Structure is [documented below](#nested_stateful_external_ip).
175+
172176
- - -
173177

174178
<a name="nested_update_policy"></a>The `update_policy` block supports:
@@ -287,6 +291,18 @@ one of which has a `target_size.percent` of `60` will create 2 instances of that
287291

288292
* `delete_rule` - (Optional), A value that prescribes what should happen to the stateful disk when the VM instance is deleted. The available options are `NEVER` and `ON_PERMANENT_INSTANCE_DELETION`. `NEVER` - detach the disk when the VM is deleted, but do not delete the disk. `ON_PERMANENT_INSTANCE_DELETION` will delete the stateful disk when the VM is permanently deleted from the instance group. The default is `NEVER`.
289293

294+
<a name="nested_stateful_internal_ip"></a>The `stateful_internal_ip` block supports:
295+
296+
* `network_interface_name` - (Required), The network interface name of the internal Ip.
297+
298+
* `delete_rule` - (Optional), A value that prescribes what should happen to the internal ip when the VM instance is deleted. The available options are `NEVER` and `ON_PERMANENT_INSTANCE_DELETION`. `NEVER` - detach the ip when the VM is deleted, but do not delete the ip. `ON_PERMANENT_INSTANCE_DELETION` will delete the internal ip when the VM is permanently deleted from the instance group.
299+
300+
<a name="nested_stateful_external_ip"></a>The `stateful_external_ip` block supports:
301+
302+
* `network_interface_name` - (Required), The network interface name of the external Ip.
303+
304+
* `delete_rule` - (Optional), A value that prescribes what should happen to the external ip when the VM instance is deleted. The available options are `NEVER` and `ON_PERMANENT_INSTANCE_DELETION`. `NEVER` - detach the ip when the VM is deleted, but do not delete the ip. `ON_PERMANENT_INSTANCE_DELETION` will delete the external ip when the VM is permanently deleted from the instance group.
305+
290306
## Attributes Reference
291307

292308
In addition to the arguments listed above, the following computed attributes are

0 commit comments

Comments
 (0)