Skip to content

Support prodcuer port in network endpoint group #8766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11820.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added the `psc_data` field to the `google_compute_region_network_endpoint_group` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,26 @@ The URL of the network to which all network endpoints in the NEG belong. Uses
Description: `Type of network endpoints in this network endpoint group. Defaults to SERVERLESS. Default value: "SERVERLESS" Possible values: ["SERVERLESS", "PRIVATE_SERVICE_CONNECT", "INTERNET_IP_PORT", "INTERNET_FQDN_PORT", "GCE_VM_IP_PORTMAP"]`,
Default: "SERVERLESS",
},
"psc_data": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `This field is only used for PSC NEGs.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"producer_port": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The PSC producer port to use when consumer PSC NEG connects to a producer. If
this flag isn't specified for a PSC NEG with endpoint type
private-service-connect, then PSC NEG will be connected to a first port in the
available PSC producer port range.`,
},
},
},
},
"psc_target_service": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -344,6 +364,12 @@ func resourceComputeRegionNetworkEndpointGroupCreate(d *schema.ResourceData, met
} else if v, ok := d.GetOkExists("subnetwork"); !tpgresource.IsEmptyValue(reflect.ValueOf(subnetworkProp)) && (ok || !reflect.DeepEqual(v, subnetworkProp)) {
obj["subnetwork"] = subnetworkProp
}
pscDataProp, err := expandComputeRegionNetworkEndpointGroupPscData(d.Get("psc_data"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("psc_data"); !tpgresource.IsEmptyValue(reflect.ValueOf(pscDataProp)) && (ok || !reflect.DeepEqual(v, pscDataProp)) {
obj["pscData"] = pscDataProp
}
cloudRunProp, err := expandComputeRegionNetworkEndpointGroupCloudRun(d.Get("cloud_run"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -491,6 +517,9 @@ func resourceComputeRegionNetworkEndpointGroupRead(d *schema.ResourceData, meta
if err := d.Set("subnetwork", flattenComputeRegionNetworkEndpointGroupSubnetwork(res["subnetwork"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionNetworkEndpointGroup: %s", err)
}
if err := d.Set("psc_data", flattenComputeRegionNetworkEndpointGroupPscData(res["pscData"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionNetworkEndpointGroup: %s", err)
}
if err := d.Set("cloud_run", flattenComputeRegionNetworkEndpointGroupCloudRun(res["cloudRun"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionNetworkEndpointGroup: %s", err)
}
Expand Down Expand Up @@ -620,6 +649,23 @@ func flattenComputeRegionNetworkEndpointGroupSubnetwork(v interface{}, d *schema
return tpgresource.ConvertSelfLinkToV1(v.(string))
}

func flattenComputeRegionNetworkEndpointGroupPscData(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["producer_port"] =
flattenComputeRegionNetworkEndpointGroupPscDataProducerPort(original["producerPort"], d, config)
return []interface{}{transformed}
}
func flattenComputeRegionNetworkEndpointGroupPscDataProducerPort(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return d.Get("psc_data.0.producer_port")
}

func flattenComputeRegionNetworkEndpointGroupCloudRun(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -769,6 +815,29 @@ func expandComputeRegionNetworkEndpointGroupSubnetwork(v interface{}, d tpgresou
return f.RelativeLink(), nil
}

func expandComputeRegionNetworkEndpointGroupPscData(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedProducerPort, err := expandComputeRegionNetworkEndpointGroupPscDataProducerPort(original["producer_port"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedProducerPort); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["producerPort"] = transformedProducerPort
}

return transformed, nil
}

func expandComputeRegionNetworkEndpointGroupPscDataProducerPort(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeRegionNetworkEndpointGroupCloudRun(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupFunction
ResourceName: "google_compute_region_network_endpoint_group.function_neg",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "subnetwork"},
ImportStateVerifyIgnore: []string{"network", "psc_data.0.producer_port", "region", "subnetwork"},
},
},
})
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupCloudrun
ResourceName: "google_compute_region_network_endpoint_group.cloudrun_neg",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "subnetwork"},
ImportStateVerifyIgnore: []string{"network", "psc_data.0.producer_port", "region", "subnetwork"},
},
},
})
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupAppengin
ResourceName: "google_compute_region_network_endpoint_group.appengine_neg",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "subnetwork"},
ImportStateVerifyIgnore: []string{"network", "psc_data.0.producer_port", "region", "subnetwork"},
},
},
})
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupAppengin
ResourceName: "google_compute_region_network_endpoint_group.appengine_neg",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "subnetwork"},
ImportStateVerifyIgnore: []string{"network", "psc_data.0.producer_port", "region", "subnetwork"},
},
},
})
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupPscExamp
ResourceName: "google_compute_region_network_endpoint_group.psc_neg",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "subnetwork"},
ImportStateVerifyIgnore: []string{"network", "psc_data.0.producer_port", "region", "subnetwork"},
},
},
})
Expand Down Expand Up @@ -350,7 +350,7 @@ func TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupPscServi
ResourceName: "google_compute_region_network_endpoint_group.psc_neg_service_attachment",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "subnetwork"},
ImportStateVerifyIgnore: []string{"network", "psc_data.0.producer_port", "region", "subnetwork"},
},
},
})
Expand Down Expand Up @@ -399,7 +399,7 @@ resource "google_compute_forwarding_rule" "default" {

load_balancing_scheme = "INTERNAL"
backend_service = google_compute_region_backend_service.default.id
all_ports = true
ports = ["80", "88", "443"]
network = google_compute_network.default.name
subnetwork = google_compute_subnetwork.default.name
}
Expand All @@ -421,7 +421,9 @@ resource "google_compute_region_network_endpoint_group" "psc_neg_service_attachm

network_endpoint_type = "PRIVATE_SERVICE_CONNECT"
psc_target_service = google_compute_service_attachment.default.self_link

psc_data {
producer_port = "88"
}
network = google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.default.self_link
}
Expand All @@ -447,7 +449,7 @@ func TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupInternet
ResourceName: "google_compute_region_network_endpoint_group.region_network_endpoint_group_internet_ip_port",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "subnetwork"},
ImportStateVerifyIgnore: []string{"network", "psc_data.0.producer_port", "region", "subnetwork"},
},
},
})
Expand Down Expand Up @@ -488,7 +490,7 @@ func TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupInternet
ResourceName: "google_compute_region_network_endpoint_group.region_network_endpoint_group_internet_fqdn_port",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "subnetwork"},
ImportStateVerifyIgnore: []string{"network", "psc_data.0.producer_port", "region", "subnetwork"},
},
},
})
Expand Down Expand Up @@ -529,7 +531,7 @@ func TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupPortmapE
ResourceName: "google_compute_region_network_endpoint_group.region_network_endpoint_group_portmap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "subnetwork"},
ImportStateVerifyIgnore: []string{"network", "psc_data.0.producer_port", "region", "subnetwork"},
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ resource "google_compute_forwarding_rule" "default" {

load_balancing_scheme = "INTERNAL"
backend_service = google_compute_region_backend_service.default.id
all_ports = true
ports = ["80", "88", "443"]
network = google_compute_network.default.name
subnetwork = google_compute_subnetwork.default.name
}
Expand All @@ -307,7 +307,9 @@ resource "google_compute_region_network_endpoint_group" "psc_neg_service_attachm

network_endpoint_type = "PRIVATE_SERVICE_CONNECT"
psc_target_service = google_compute_service_attachment.default.self_link

psc_data {
producer_port = "88"
}
network = google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.default.self_link
}
Expand Down Expand Up @@ -438,6 +440,11 @@ The following arguments are supported:
This field is only used for PSC NEGs.
Optional URL of the subnetwork to which all network endpoints in the NEG belong.

* `psc_data` -
(Optional)
This field is only used for PSC NEGs.
Structure is [documented below](#nested_psc_data).

* `cloud_run` -
(Optional)
This field is only used for SERVERLESS NEGs.
Expand Down Expand Up @@ -466,6 +473,15 @@ The following arguments are supported:
If it is not provided, the provider project is used.


<a name="nested_psc_data"></a>The `psc_data` block supports:

* `producer_port` -
(Optional)
The PSC producer port to use when consumer PSC NEG connects to a producer. If
this flag isn't specified for a PSC NEG with endpoint type
private-service-connect, then PSC NEG will be connected to a first port in the
available PSC producer port range.

<a name="nested_cloud_run"></a>The `cloud_run` block supports:

* `service` -
Expand Down