Skip to content

Commit ec3fe39

Browse files
networkconnectivity: add producer_instance_location and allowed_google_producers_resource_hierarchy_level to psc_config for google_network_connectivity_service_connection_policy (#14170) (#23240)
[upstream:2c7c0b93979b2287c6f9c4b606d3eca57cf2c89e] Signed-off-by: Modular Magician <[email protected]>
1 parent 70c1e75 commit ec3fe39

5 files changed

+89
-2
lines changed

.changelog/14170.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
networkconnectivity: add `psc_config.producer_instance_location` and `psc_config.allowed_google_producers_resource_hierarchy_level` fields to `google_network_connectivity_service_connection_policy`
3+
```

google/services/networkconnectivity/resource_network_connectivity_service_connection_policies_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import (
2222

2323
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
2424
"github.com/hashicorp/terraform-provider-google/google/acctest"
25+
"github.com/hashicorp/terraform-provider-google/google/envvar"
2526
)
2627

2728
func TestAccNetworkConnectivityServiceConnectionPolicy_update(t *testing.T) {
2829
t.Parallel()
2930

3031
context := map[string]interface{}{
32+
"org_id": envvar.GetTestOrgFromEnv(t),
3133
"networkProducerName": fmt.Sprintf("tf-test-network-%s", acctest.RandString(t, 10)),
3234
"subnetworkProducerName1": fmt.Sprintf("tf-test-subnet-producer-%s", acctest.RandString(t, 10)),
3335
"subnetworkProducerName2": fmt.Sprintf("tf-test-subnet-producer-%s", acctest.RandString(t, 10)),
@@ -117,8 +119,12 @@ resource "google_network_connectivity_service_connection_policy" "default" {
117119
service_class = "gcp-memorystore-redis"
118120
network = google_compute_network.producer_net.id
119121
psc_config {
120-
subnetworks = [google_compute_subnetwork.producer_subnet1.id]
121-
limit = 4
122+
producer_instance_location = "CUSTOM_RESOURCE_HIERARCHY_LEVELS"
123+
subnetworks = [google_compute_subnetwork.producer_subnet1.id]
124+
limit = 4
125+
allowed_google_producers_resource_hierarchy_level = [
126+
"organizations/%{org_id}",
127+
]
122128
}
123129
labels = {
124130
foo = "bar"

google/services/networkconnectivity/resource_network_connectivity_service_connection_policy.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,35 @@ Please refer to the field 'effective_labels' for all of the labels present on th
113113
Type: schema.TypeString,
114114
},
115115
},
116+
"allowed_google_producers_resource_hierarchy_level": {
117+
Type: schema.TypeList,
118+
Optional: true,
119+
Description: `List of Projects, Folders, or Organizations from where the Producer instance can be within. For example,
120+
a network administrator can provide both 'organizations/foo' and 'projects/bar' as
121+
allowed_google_producers_resource_hierarchy_levels. This allowlists this network to connect with any Producer
122+
instance within the 'foo' organization or the 'bar' project. By default,
123+
allowedGoogleProducersResourceHierarchyLevel is empty. The format for each
124+
allowedGoogleProducersResourceHierarchyLevel is / where is one of 'projects', 'folders', or 'organizations'
125+
and is either the ID or the number of the resource type. Format for each
126+
allowedGoogleProducersResourceHierarchyLevel value: 'projects/' or 'folders/' or 'organizations/' Eg.
127+
[projects/my-project-id, projects/567, folders/891, organizations/123]`,
128+
Elem: &schema.Schema{
129+
Type: schema.TypeString,
130+
},
131+
},
116132
"limit": {
117133
Type: schema.TypeString,
118134
Optional: true,
119135
Description: `Max number of PSC connections for this policy.`,
120136
},
137+
"producer_instance_location": {
138+
Type: schema.TypeString,
139+
Computed: true,
140+
Optional: true,
141+
ValidateFunc: verify.ValidateEnum([]string{"PRODUCER_INSTANCE_LOCATION_UNSPECIFIED", "CUSTOM_RESOURCE_HIERARCHY_LEVELS", ""}),
142+
Description: `ProducerInstanceLocation is used to specify which authorization mechanism to use to determine which projects
143+
the Producer instance can be within. Possible values: ["PRODUCER_INSTANCE_LOCATION_UNSPECIFIED", "CUSTOM_RESOURCE_HIERARCHY_LEVELS"]`,
144+
},
121145
},
122146
},
123147
},
@@ -669,6 +693,10 @@ func flattenNetworkConnectivityServiceConnectionPolicyPscConfig(v interface{}, d
669693
transformed := make(map[string]interface{})
670694
transformed["subnetworks"] =
671695
flattenNetworkConnectivityServiceConnectionPolicyPscConfigSubnetworks(original["subnetworks"], d, config)
696+
transformed["producer_instance_location"] =
697+
flattenNetworkConnectivityServiceConnectionPolicyPscConfigProducerInstanceLocation(original["producerInstanceLocation"], d, config)
698+
transformed["allowed_google_producers_resource_hierarchy_level"] =
699+
flattenNetworkConnectivityServiceConnectionPolicyPscConfigAllowedGoogleProducersResourceHierarchyLevel(original["allowedGoogleProducersResourceHierarchyLevel"], d, config)
672700
transformed["limit"] =
673701
flattenNetworkConnectivityServiceConnectionPolicyPscConfigLimit(original["limit"], d, config)
674702
return []interface{}{transformed}
@@ -677,6 +705,14 @@ func flattenNetworkConnectivityServiceConnectionPolicyPscConfigSubnetworks(v int
677705
return v
678706
}
679707

708+
func flattenNetworkConnectivityServiceConnectionPolicyPscConfigProducerInstanceLocation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
709+
return v
710+
}
711+
712+
func flattenNetworkConnectivityServiceConnectionPolicyPscConfigAllowedGoogleProducersResourceHierarchyLevel(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
713+
return v
714+
}
715+
680716
func flattenNetworkConnectivityServiceConnectionPolicyPscConfigLimit(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
681717
return v
682718
}
@@ -876,6 +912,20 @@ func expandNetworkConnectivityServiceConnectionPolicyPscConfig(v interface{}, d
876912
transformed["subnetworks"] = transformedSubnetworks
877913
}
878914

915+
transformedProducerInstanceLocation, err := expandNetworkConnectivityServiceConnectionPolicyPscConfigProducerInstanceLocation(original["producer_instance_location"], d, config)
916+
if err != nil {
917+
return nil, err
918+
} else if val := reflect.ValueOf(transformedProducerInstanceLocation); val.IsValid() && !tpgresource.IsEmptyValue(val) {
919+
transformed["producerInstanceLocation"] = transformedProducerInstanceLocation
920+
}
921+
922+
transformedAllowedGoogleProducersResourceHierarchyLevel, err := expandNetworkConnectivityServiceConnectionPolicyPscConfigAllowedGoogleProducersResourceHierarchyLevel(original["allowed_google_producers_resource_hierarchy_level"], d, config)
923+
if err != nil {
924+
return nil, err
925+
} else if val := reflect.ValueOf(transformedAllowedGoogleProducersResourceHierarchyLevel); val.IsValid() && !tpgresource.IsEmptyValue(val) {
926+
transformed["allowedGoogleProducersResourceHierarchyLevel"] = transformedAllowedGoogleProducersResourceHierarchyLevel
927+
}
928+
879929
transformedLimit, err := expandNetworkConnectivityServiceConnectionPolicyPscConfigLimit(original["limit"], d, config)
880930
if err != nil {
881931
return nil, err
@@ -890,6 +940,14 @@ func expandNetworkConnectivityServiceConnectionPolicyPscConfigSubnetworks(v inte
890940
return v, nil
891941
}
892942

943+
func expandNetworkConnectivityServiceConnectionPolicyPscConfigProducerInstanceLocation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
944+
return v, nil
945+
}
946+
947+
func expandNetworkConnectivityServiceConnectionPolicyPscConfigAllowedGoogleProducersResourceHierarchyLevel(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
948+
return v, nil
949+
}
950+
893951
func expandNetworkConnectivityServiceConnectionPolicyPscConfigLimit(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
894952
return v, nil
895953
}

google/services/networkconnectivity/resource_network_connectivity_service_connection_policy_generated_meta.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ fields:
1717
- field: 'name'
1818
provider_only: true
1919
- field: 'network'
20+
- field: 'psc_config.allowed_google_producers_resource_hierarchy_level'
2021
- field: 'psc_config.limit'
22+
- field: 'psc_config.producer_instance_location'
2123
- field: 'psc_config.subnetworks'
2224
- field: 'psc_connections.consumer_address'
2325
- field: 'psc_connections.consumer_forwarding_rule'

website/docs/r/network_connectivity_service_connection_policy.html.markdown

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ The following arguments are supported:
117117
(Required)
118118
IDs of the subnetworks or fully qualified identifiers for the subnetworks
119119

120+
* `producer_instance_location` -
121+
(Optional)
122+
ProducerInstanceLocation is used to specify which authorization mechanism to use to determine which projects
123+
the Producer instance can be within.
124+
Possible values are: `PRODUCER_INSTANCE_LOCATION_UNSPECIFIED`, `CUSTOM_RESOURCE_HIERARCHY_LEVELS`.
125+
126+
* `allowed_google_producers_resource_hierarchy_level` -
127+
(Optional)
128+
List of Projects, Folders, or Organizations from where the Producer instance can be within. For example,
129+
a network administrator can provide both 'organizations/foo' and 'projects/bar' as
130+
allowed_google_producers_resource_hierarchy_levels. This allowlists this network to connect with any Producer
131+
instance within the 'foo' organization or the 'bar' project. By default,
132+
allowedGoogleProducersResourceHierarchyLevel is empty. The format for each
133+
allowedGoogleProducersResourceHierarchyLevel is / where is one of 'projects', 'folders', or 'organizations'
134+
and is either the ID or the number of the resource type. Format for each
135+
allowedGoogleProducersResourceHierarchyLevel value: 'projects/' or 'folders/' or 'organizations/' Eg.
136+
[projects/my-project-id, projects/567, folders/891, organizations/123]
137+
120138
* `limit` -
121139
(Optional)
122140
Max number of PSC connections for this policy.

0 commit comments

Comments
 (0)