Skip to content

Commit 967d4d5

Browse files
Support for service owned project number (#13345) (#21863)
[upstream:1283b0fd9357aa2012fe49188a61441ab106976d] Signed-off-by: Modular Magician <[email protected]>
1 parent d2e4999 commit 967d4d5

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

.changelog/13345.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 `psc_config` field to ``google_alloydb_cluster` resource
3+
```

google/services/alloydb/resource_alloydb_cluster.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,12 @@ It is specified in the form: "projects/{projectNumber}/global/networks/{network_
423423
Optional: true,
424424
Description: `Create an instance that allows connections from Private Service Connect endpoints to the instance.`,
425425
},
426+
"service_owned_project_number": {
427+
Type: schema.TypeInt,
428+
Computed: true,
429+
Description: `The project number that needs to be allowlisted on the network attachment to enable outbound connectivity, if the network attachment is configured to ACCEPT_MANUAL connections.
430+
In case the network attachment is configured to ACCEPT_AUTOMATIC, this project number does not need to be allowlisted explicitly.`,
431+
},
426432
},
427433
},
428434
},
@@ -1679,12 +1685,31 @@ func flattenAlloydbClusterPscConfig(v interface{}, d *schema.ResourceData, confi
16791685
transformed := make(map[string]interface{})
16801686
transformed["psc_enabled"] =
16811687
flattenAlloydbClusterPscConfigPscEnabled(original["pscEnabled"], d, config)
1688+
transformed["service_owned_project_number"] =
1689+
flattenAlloydbClusterPscConfigServiceOwnedProjectNumber(original["serviceOwnedProjectNumber"], d, config)
16821690
return []interface{}{transformed}
16831691
}
16841692
func flattenAlloydbClusterPscConfigPscEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
16851693
return v
16861694
}
16871695

1696+
func flattenAlloydbClusterPscConfigServiceOwnedProjectNumber(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1697+
// Handles the string fixed64 format
1698+
if strVal, ok := v.(string); ok {
1699+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
1700+
return intVal
1701+
}
1702+
}
1703+
1704+
// number values are represented as float64
1705+
if floatVal, ok := v.(float64); ok {
1706+
intVal := int(floatVal)
1707+
return intVal
1708+
}
1709+
1710+
return v // let terraform core handle it otherwise
1711+
}
1712+
16881713
func flattenAlloydbClusterContinuousBackupConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
16891714
if v == nil {
16901715
return nil
@@ -2293,13 +2318,24 @@ func expandAlloydbClusterPscConfig(v interface{}, d tpgresource.TerraformResourc
22932318
transformed["pscEnabled"] = transformedPscEnabled
22942319
}
22952320

2321+
transformedServiceOwnedProjectNumber, err := expandAlloydbClusterPscConfigServiceOwnedProjectNumber(original["service_owned_project_number"], d, config)
2322+
if err != nil {
2323+
return nil, err
2324+
} else if val := reflect.ValueOf(transformedServiceOwnedProjectNumber); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2325+
transformed["serviceOwnedProjectNumber"] = transformedServiceOwnedProjectNumber
2326+
}
2327+
22962328
return transformed, nil
22972329
}
22982330

22992331
func expandAlloydbClusterPscConfigPscEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
23002332
return v, nil
23012333
}
23022334

2335+
func expandAlloydbClusterPscConfigServiceOwnedProjectNumber(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2336+
return v, nil
2337+
}
2338+
23032339
func expandAlloydbClusterInitialUser(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
23042340
l := v.([]interface{})
23052341
if len(l) == 0 || l[0] == nil {

google/services/alloydb/resource_alloydb_cluster_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ fields:
5959
- field: 'network_config.allocated_ip_range'
6060
- field: 'network_config.network'
6161
- field: 'psc_config.psc_enabled'
62+
- field: 'psc_config.service_owned_project_number'
6263
- field: 'reconciling'
6364
- field: 'restore_backup_source.backup_name'
6465
- field: 'restore_continuous_backup_source.cluster'

google/services/alloydb/resource_alloydb_cluster_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,7 @@ func TestAccAlloydbCluster_withPrivateServiceConnect(t *testing.T) {
14741474
Config: testAccAlloydbCluster_withPrivateServiceConnect(context),
14751475
Check: resource.ComposeTestCheckFunc(
14761476
resource.TestCheckResourceAttr("google_alloydb_cluster.default", "psc_config.0.psc_enabled", "true"),
1477+
resource.TestMatchResourceAttr("google_alloydb_cluster.default", "psc_config.0.service_owned_project_number", regexp.MustCompile("^[1-9]\\d*$")),
14771478
),
14781479
},
14791480
},

website/docs/r/alloydb_cluster.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ Default value: "true"
523523
(Optional)
524524
Create an instance that allows connections from Private Service Connect endpoints to the instance.
525525

526+
* `service_owned_project_number` -
527+
(Output)
528+
The project number that needs to be allowlisted on the network attachment to enable outbound connectivity, if the network attachment is configured to ACCEPT_MANUAL connections.
529+
In case the network attachment is configured to ACCEPT_AUTOMATIC, this project number does not need to be allowlisted explicitly.
530+
526531
<a name="nested_initial_user"></a>The `initial_user` block supports:
527532

528533
* `user` -

0 commit comments

Comments
 (0)