Skip to content

Commit ba5166c

Browse files
[AlloyDB] Support for PSA Allocated IP Range Override (#14247) (#23330)
[upstream:7cf7472660eebcce2b88b5f6b6db7d912f4e596c] Signed-off-by: Modular Magician <[email protected]>
1 parent 22537d6 commit ba5166c

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

.changelog/14247.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
alloydb: added `network_config.allocated_ip_range_override` field to `google_alloydb_instance` resource
3+
```

google/services/alloydb/resource_alloydb_instance.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ E.g. "n2-highmem-4", "n2-highmem-8", "c4a-highmem-4-lssd".
213213
MaxItems: 1,
214214
Elem: &schema.Resource{
215215
Schema: map[string]*schema.Schema{
216+
"allocated_ip_range_override": {
217+
Type: schema.TypeString,
218+
Optional: true,
219+
ForceNew: true,
220+
Description: `Name of the allocated IP range for the private IP AlloyDB instance, for example: "google-managed-services-default".
221+
If set, the instance IPs will be created from this allocated range and will override the IP range used by the parent cluster.
222+
The range name must comply with RFC 1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])?.`,
223+
},
216224
"authorized_external_networks": {
217225
Type: schema.TypeList,
218226
Optional: true,
@@ -1353,6 +1361,8 @@ func flattenAlloydbInstanceNetworkConfig(v interface{}, d *schema.ResourceData,
13531361
flattenAlloydbInstanceNetworkConfigEnablePublicIp(original["enablePublicIp"], d, config)
13541362
transformed["enable_outbound_public_ip"] =
13551363
flattenAlloydbInstanceNetworkConfigEnableOutboundPublicIp(original["enableOutboundPublicIp"], d, config)
1364+
transformed["allocated_ip_range_override"] =
1365+
flattenAlloydbInstanceNetworkConfigAllocatedIpRangeOverride(original["allocatedIpRangeOverride"], d, config)
13561366
return []interface{}{transformed}
13571367
}
13581368
func flattenAlloydbInstanceNetworkConfigAuthorizedExternalNetworks(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -1385,6 +1395,10 @@ func flattenAlloydbInstanceNetworkConfigEnableOutboundPublicIp(v interface{}, d
13851395
return v
13861396
}
13871397

1398+
func flattenAlloydbInstanceNetworkConfigAllocatedIpRangeOverride(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1399+
return v
1400+
}
1401+
13881402
func flattenAlloydbInstancePublicIpAddress(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
13891403
return v
13901404
}
@@ -1798,6 +1812,13 @@ func expandAlloydbInstanceNetworkConfig(v interface{}, d tpgresource.TerraformRe
17981812
transformed["enableOutboundPublicIp"] = transformedEnableOutboundPublicIp
17991813
}
18001814

1815+
transformedAllocatedIpRangeOverride, err := expandAlloydbInstanceNetworkConfigAllocatedIpRangeOverride(original["allocated_ip_range_override"], d, config)
1816+
if err != nil {
1817+
return nil, err
1818+
} else if val := reflect.ValueOf(transformedAllocatedIpRangeOverride); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1819+
transformed["allocatedIpRangeOverride"] = transformedAllocatedIpRangeOverride
1820+
}
1821+
18011822
return transformed, nil
18021823
}
18031824

@@ -1835,6 +1856,10 @@ func expandAlloydbInstanceNetworkConfigEnableOutboundPublicIp(v interface{}, d t
18351856
return v, nil
18361857
}
18371858

1859+
func expandAlloydbInstanceNetworkConfigAllocatedIpRangeOverride(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1860+
return v, nil
1861+
}
1862+
18381863
func expandAlloydbInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
18391864
if v == nil {
18401865
return map[string]string{}, nil

google/services/alloydb/resource_alloydb_instance_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fields:
2828
- field: 'machine_config.cpu_count'
2929
- field: 'machine_config.machine_type'
3030
- field: 'name'
31+
- field: 'network_config.allocated_ip_range_override'
3132
- field: 'network_config.authorized_external_networks.cidr_range'
3233
- field: 'network_config.enable_outbound_public_ip'
3334
- field: 'network_config.enable_public_ip'

google/services/alloydb/resource_alloydb_instance_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,3 +1098,66 @@ resource "google_alloydb_cluster" "default" {
10981098
data "google_project" "project" {}
10991099
`, context)
11001100
}
1101+
1102+
func TestAccAlloydbInstance_createPrimaryAndReadPoolInstanceWithAllocatedIpRangeOverride(t *testing.T) {
1103+
t.Parallel()
1104+
1105+
testId := "alloydb-1"
1106+
context := map[string]interface{}{
1107+
"random_suffix": acctest.RandString(t, 10),
1108+
"address_name": acctest.BootstrapSharedTestGlobalAddress(t, testId),
1109+
"network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, testId),
1110+
}
1111+
1112+
acctest.VcrTest(t, resource.TestCase{
1113+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1114+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1115+
CheckDestroy: testAccCheckAlloydbInstanceDestroyProducer(t),
1116+
Steps: []resource.TestStep{
1117+
{
1118+
Config: testAccAlloydbInstance_createPrimaryAndReadPoolInstanceWithAllocatedIpRangeOverride(context),
1119+
},
1120+
},
1121+
})
1122+
}
1123+
1124+
func testAccAlloydbInstance_createPrimaryAndReadPoolInstanceWithAllocatedIpRangeOverride(context map[string]interface{}) string {
1125+
return acctest.Nprintf(`
1126+
resource "google_alloydb_instance" "primary" {
1127+
cluster = google_alloydb_cluster.default.name
1128+
instance_id = "tf-test-alloydb-instance%{random_suffix}"
1129+
instance_type = "PRIMARY"
1130+
}
1131+
1132+
resource "google_alloydb_instance" "read_pool" {
1133+
cluster = google_alloydb_cluster.default.name
1134+
instance_id = "tf-test-alloydb-instance%{random_suffix}-read"
1135+
instance_type = "READ_POOL"
1136+
read_pool_config {
1137+
node_count = 4
1138+
}
1139+
network_config {
1140+
allocated_ip_range_override = data.google_compute_global_address.private_ip_alloc.name
1141+
}
1142+
depends_on = [google_alloydb_instance.primary]
1143+
}
1144+
1145+
resource "google_alloydb_cluster" "default" {
1146+
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
1147+
location = "us-central1"
1148+
network_config {
1149+
network = data.google_compute_network.default.id
1150+
}
1151+
}
1152+
1153+
data "google_project" "project" {}
1154+
1155+
data "google_compute_network" "default" {
1156+
name = "%{network_name}"
1157+
}
1158+
1159+
data "google_compute_global_address" "private_ip_alloc" {
1160+
name = "%{address_name}"
1161+
}
1162+
`, context)
1163+
}

website/docs/r/alloydb_instance.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,12 @@ The following arguments are supported:
456456
(Optional)
457457
Enabling outbound public ip for the instance.
458458

459+
* `allocated_ip_range_override` -
460+
(Optional)
461+
Name of the allocated IP range for the private IP AlloyDB instance, for example: "google-managed-services-default".
462+
If set, the instance IPs will be created from this allocated range and will override the IP range used by the parent cluster.
463+
The range name must comply with RFC 1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])?.
464+
459465

460466
<a name="nested_network_config_authorized_external_networks"></a>The `authorized_external_networks` block supports:
461467

0 commit comments

Comments
 (0)