Skip to content

Commit 53c16b1

Browse files
Public outbound ip (#11675)
[upstream:477e5c94b4011b01a7f18ccd14fbcecd6d1073eb] Signed-off-by: Modular Magician <[email protected]>
1 parent 444ef35 commit 53c16b1

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

.changelog/11675.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
alloyDB: added `enableOutboundPublicIp` field to `google_alloydb_instance` resource
3+
```

google/services/alloydb/resource_alloydb_instance.go

+39
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ true.`,
205205
},
206206
RequiredWith: []string{"network_config.0.enable_public_ip"},
207207
},
208+
"enable_outbound_public_ip": {
209+
Type: schema.TypeBool,
210+
Optional: true,
211+
Description: `Enabling outbound public ip for the instance.`,
212+
},
208213
"enable_public_ip": {
209214
Type: schema.TypeBool,
210215
Optional: true,
@@ -322,6 +327,16 @@ The name of the resource will be in the format of
322327
Computed: true,
323328
Description: `The name of the instance resource.`,
324329
},
330+
"outbound_public_ip_addresses": {
331+
Type: schema.TypeList,
332+
Computed: true,
333+
Description: `The outbound public IP addresses for the instance. This is available ONLY when
334+
networkConfig.enableOutboundPublicIp is set to true. These IP addresses are used
335+
for outbound connections.`,
336+
Elem: &schema.Schema{
337+
Type: schema.TypeString,
338+
},
339+
},
325340
"public_ip_address": {
326341
Type: schema.TypeString,
327342
Computed: true,
@@ -596,6 +611,9 @@ func resourceAlloydbInstanceRead(d *schema.ResourceData, meta interface{}) error
596611
if err := d.Set("public_ip_address", flattenAlloydbInstancePublicIpAddress(res["publicIpAddress"], d, config)); err != nil {
597612
return fmt.Errorf("Error reading Instance: %s", err)
598613
}
614+
if err := d.Set("outbound_public_ip_addresses", flattenAlloydbInstanceOutboundPublicIpAddresses(res["outboundPublicIpAddresses"], d, config)); err != nil {
615+
return fmt.Errorf("Error reading Instance: %s", err)
616+
}
599617
if err := d.Set("terraform_labels", flattenAlloydbInstanceTerraformLabels(res["labels"], d, config)); err != nil {
600618
return fmt.Errorf("Error reading Instance: %s", err)
601619
}
@@ -1154,6 +1172,8 @@ func flattenAlloydbInstanceNetworkConfig(v interface{}, d *schema.ResourceData,
11541172
flattenAlloydbInstanceNetworkConfigAuthorizedExternalNetworks(original["authorizedExternalNetworks"], d, config)
11551173
transformed["enable_public_ip"] =
11561174
flattenAlloydbInstanceNetworkConfigEnablePublicIp(original["enablePublicIp"], d, config)
1175+
transformed["enable_outbound_public_ip"] =
1176+
flattenAlloydbInstanceNetworkConfigEnableOutboundPublicIp(original["enableOutboundPublicIp"], d, config)
11571177
return []interface{}{transformed}
11581178
}
11591179
func flattenAlloydbInstanceNetworkConfigAuthorizedExternalNetworks(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -1182,10 +1202,18 @@ func flattenAlloydbInstanceNetworkConfigEnablePublicIp(v interface{}, d *schema.
11821202
return v
11831203
}
11841204

1205+
func flattenAlloydbInstanceNetworkConfigEnableOutboundPublicIp(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1206+
return v
1207+
}
1208+
11851209
func flattenAlloydbInstancePublicIpAddress(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
11861210
return v
11871211
}
11881212

1213+
func flattenAlloydbInstanceOutboundPublicIpAddresses(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1214+
return v
1215+
}
1216+
11891217
func flattenAlloydbInstanceTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
11901218
if v == nil {
11911219
return v
@@ -1459,6 +1487,13 @@ func expandAlloydbInstanceNetworkConfig(v interface{}, d tpgresource.TerraformRe
14591487
transformed["enablePublicIp"] = transformedEnablePublicIp
14601488
}
14611489

1490+
transformedEnableOutboundPublicIp, err := expandAlloydbInstanceNetworkConfigEnableOutboundPublicIp(original["enable_outbound_public_ip"], d, config)
1491+
if err != nil {
1492+
return nil, err
1493+
} else if val := reflect.ValueOf(transformedEnableOutboundPublicIp); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1494+
transformed["enableOutboundPublicIp"] = transformedEnableOutboundPublicIp
1495+
}
1496+
14621497
return transformed, nil
14631498
}
14641499

@@ -1492,6 +1527,10 @@ func expandAlloydbInstanceNetworkConfigEnablePublicIp(v interface{}, d tpgresour
14921527
return v, nil
14931528
}
14941529

1530+
func expandAlloydbInstanceNetworkConfigEnableOutboundPublicIp(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1531+
return v, nil
1532+
}
1533+
14951534
func expandAlloydbInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
14961535
if v == nil {
14971536
return map[string]string{}, nil

google/services/alloydb/resource_alloydb_instance_test.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,15 @@ func TestAccAlloydbInstance_networkConfig(t *testing.T) {
596596
"random_suffix": suffix,
597597
"network_name": networkName,
598598
"enable_public_ip": true,
599+
"enable_outbound_public_ip": true,
599600
"authorized_external_networks": "",
600601
}
602+
601603
context2 := map[string]interface{}{
602-
"random_suffix": suffix,
603-
"network_name": networkName,
604-
"enable_public_ip": true,
604+
"random_suffix": suffix,
605+
"network_name": networkName,
606+
"enable_public_ip": true,
607+
"enable_outbound_public_ip": false,
605608
"authorized_external_networks": `
606609
authorized_external_networks {
607610
cidr_range = "8.8.8.8/30"
@@ -611,11 +614,13 @@ func TestAccAlloydbInstance_networkConfig(t *testing.T) {
611614
}
612615
`,
613616
}
617+
614618
context3 := map[string]interface{}{
615-
"random_suffix": suffix,
616-
"network_name": networkName,
617-
"enable_public_ip": true,
618-
"cidr_range": "8.8.8.8/30",
619+
"random_suffix": suffix,
620+
"network_name": networkName,
621+
"enable_public_ip": true,
622+
"enable_outbound_public_ip": true,
623+
"cidr_range": "8.8.8.8/30",
619624
}
620625

621626
acctest.VcrTest(t, resource.TestCase{
@@ -627,6 +632,8 @@ func TestAccAlloydbInstance_networkConfig(t *testing.T) {
627632
Config: testAccAlloydbInstance_networkConfig(context1),
628633
Check: resource.ComposeTestCheckFunc(
629634
resource.TestCheckResourceAttr("google_alloydb_instance.default", "network_config.0.enable_public_ip", "true"),
635+
resource.TestCheckResourceAttr("google_alloydb_instance.default", "network_config.0.enable_outbound_public_ip", "true"),
636+
resource.TestCheckResourceAttrSet("google_alloydb_instance.default", "outbound_public_ip_addresses.0"), // Ensure it's set
630637
),
631638
},
632639
{
@@ -642,6 +649,8 @@ func TestAccAlloydbInstance_networkConfig(t *testing.T) {
642649
resource.TestCheckResourceAttr("google_alloydb_instance.default", "network_config.0.authorized_external_networks.0.cidr_range", "8.8.8.8/30"),
643650
resource.TestCheckResourceAttr("google_alloydb_instance.default", "network_config.0.authorized_external_networks.1.cidr_range", "8.8.4.4/30"),
644651
resource.TestCheckResourceAttr("google_alloydb_instance.default", "network_config.0.authorized_external_networks.#", "2"),
652+
resource.TestCheckResourceAttr("google_alloydb_instance.default", "network_config.0.enable_outbound_public_ip", "false"),
653+
resource.TestCheckResourceAttr("google_alloydb_instance.default", "outbound_public_ip_addresses.#", "0"),
645654
),
646655
},
647656
{
@@ -656,6 +665,8 @@ func TestAccAlloydbInstance_networkConfig(t *testing.T) {
656665
resource.TestCheckResourceAttr("google_alloydb_instance.default", "network_config.0.enable_public_ip", "true"),
657666
resource.TestCheckResourceAttr("google_alloydb_instance.default", "network_config.0.authorized_external_networks.0.cidr_range", "8.8.8.8/30"),
658667
resource.TestCheckResourceAttr("google_alloydb_instance.default", "network_config.0.authorized_external_networks.#", "1"),
668+
resource.TestCheckResourceAttr("google_alloydb_instance.default", "network_config.0.enable_outbound_public_ip", "true"),
669+
resource.TestCheckResourceAttrSet("google_alloydb_instance.default", "outbound_public_ip_addresses.0"),
659670
),
660671
},
661672
{
@@ -680,6 +691,7 @@ resource "google_alloydb_instance" "default" {
680691
681692
network_config {
682693
enable_public_ip = %{enable_public_ip}
694+
enable_outbound_public_ip = %{enable_outbound_public_ip}
683695
%{authorized_external_networks}
684696
}
685697
}
@@ -715,6 +727,7 @@ resource "google_alloydb_instance" "default" {
715727
716728
network_config {
717729
enable_public_ip = %{enable_public_ip}
730+
enable_outbound_public_ip = %{enable_outbound_public_ip}
718731
authorized_external_networks {
719732
cidr_range = "%{cidr_range}"
720733
}

website/docs/r/alloydb_instance.html.markdown

+9
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ The following arguments are supported:
380380
please also clear the list of the authorized external networks set on
381381
the same instance.
382382

383+
* `enable_outbound_public_ip` -
384+
(Optional)
385+
Enabling outbound public ip for the instance.
386+
383387

384388
<a name="nested_authorized_external_networks"></a>The `authorized_external_networks` block supports:
385389

@@ -419,6 +423,11 @@ In addition to the arguments listed above, the following computed attributes are
419423
networkConfig.enablePublicIp is set to true. This is the connection
420424
endpoint for an end-user application.
421425

426+
* `outbound_public_ip_addresses` -
427+
The outbound public IP addresses for the instance. This is available ONLY when
428+
networkConfig.enableOutboundPublicIp is set to true. These IP addresses are used
429+
for outbound connections.
430+
422431
* `terraform_labels` -
423432
The combination of labels configured directly on the resource
424433
and default labels configured on the provider.

0 commit comments

Comments
 (0)