Skip to content

Commit ad6016f

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

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-beta/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,
@@ -373,6 +378,16 @@ The name of the resource will be in the format of
373378
Computed: true,
374379
Description: `The name of the instance resource.`,
375380
},
381+
"outbound_public_ip_addresses": {
382+
Type: schema.TypeList,
383+
Computed: true,
384+
Description: `The outbound public IP addresses for the instance. This is available ONLY when
385+
networkConfig.enableOutboundPublicIp is set to true. These IP addresses are used
386+
for outbound connections.`,
387+
Elem: &schema.Schema{
388+
Type: schema.TypeString,
389+
},
390+
},
376391
"public_ip_address": {
377392
Type: schema.TypeString,
378393
Computed: true,
@@ -656,6 +671,9 @@ func resourceAlloydbInstanceRead(d *schema.ResourceData, meta interface{}) error
656671
if err := d.Set("public_ip_address", flattenAlloydbInstancePublicIpAddress(res["publicIpAddress"], d, config)); err != nil {
657672
return fmt.Errorf("Error reading Instance: %s", err)
658673
}
674+
if err := d.Set("outbound_public_ip_addresses", flattenAlloydbInstanceOutboundPublicIpAddresses(res["outboundPublicIpAddresses"], d, config)); err != nil {
675+
return fmt.Errorf("Error reading Instance: %s", err)
676+
}
659677
if err := d.Set("terraform_labels", flattenAlloydbInstanceTerraformLabels(res["labels"], d, config)); err != nil {
660678
return fmt.Errorf("Error reading Instance: %s", err)
661679
}
@@ -1309,6 +1327,8 @@ func flattenAlloydbInstanceNetworkConfig(v interface{}, d *schema.ResourceData,
13091327
flattenAlloydbInstanceNetworkConfigAuthorizedExternalNetworks(original["authorizedExternalNetworks"], d, config)
13101328
transformed["enable_public_ip"] =
13111329
flattenAlloydbInstanceNetworkConfigEnablePublicIp(original["enablePublicIp"], d, config)
1330+
transformed["enable_outbound_public_ip"] =
1331+
flattenAlloydbInstanceNetworkConfigEnableOutboundPublicIp(original["enableOutboundPublicIp"], d, config)
13121332
return []interface{}{transformed}
13131333
}
13141334
func flattenAlloydbInstanceNetworkConfigAuthorizedExternalNetworks(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -1337,10 +1357,18 @@ func flattenAlloydbInstanceNetworkConfigEnablePublicIp(v interface{}, d *schema.
13371357
return v
13381358
}
13391359

1360+
func flattenAlloydbInstanceNetworkConfigEnableOutboundPublicIp(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1361+
return v
1362+
}
1363+
13401364
func flattenAlloydbInstancePublicIpAddress(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
13411365
return v
13421366
}
13431367

1368+
func flattenAlloydbInstanceOutboundPublicIpAddresses(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1369+
return v
1370+
}
1371+
13441372
func flattenAlloydbInstanceTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
13451373
if v == nil {
13461374
return v
@@ -1714,6 +1742,13 @@ func expandAlloydbInstanceNetworkConfig(v interface{}, d tpgresource.TerraformRe
17141742
transformed["enablePublicIp"] = transformedEnablePublicIp
17151743
}
17161744

1745+
transformedEnableOutboundPublicIp, err := expandAlloydbInstanceNetworkConfigEnableOutboundPublicIp(original["enable_outbound_public_ip"], d, config)
1746+
if err != nil {
1747+
return nil, err
1748+
} else if val := reflect.ValueOf(transformedEnableOutboundPublicIp); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1749+
transformed["enableOutboundPublicIp"] = transformedEnableOutboundPublicIp
1750+
}
1751+
17171752
return transformed, nil
17181753
}
17191754

@@ -1747,6 +1782,10 @@ func expandAlloydbInstanceNetworkConfigEnablePublicIp(v interface{}, d tpgresour
17471782
return v, nil
17481783
}
17491784

1785+
func expandAlloydbInstanceNetworkConfigEnableOutboundPublicIp(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1786+
return v, nil
1787+
}
1788+
17501789
func expandAlloydbInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
17511790
if v == nil {
17521791
return map[string]string{}, nil

google-beta/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)