Skip to content

Commit

Permalink
Revert the promotion of Port Mapping NEGs from GA to Beta (hashicorp#…
Browse files Browse the repository at this point in the history
…11854) (hashicorp#19684)

[upstream:2d34af8bcf47b390ede98ace828c98e80cb3acd0]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and ScottSuarez committed Sep 30, 2024
1 parent d615f66 commit 5976eb5
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 221 deletions.
3 changes: 3 additions & 0 deletions .changelog/11854.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: promoted `client_destination_port` and `instance` fields in `google_compute_region_network_endpoint` resource to GA (revert)
```
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ func ResourceComputeRegionNetworkEndpoint() *schema.Resource {
DiffSuppressFunc: tpgresource.CompareResourceNames,
Description: `The network endpoint group this endpoint is part of.`,
},
"client_destination_port": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: `Client destination port for the 'GCE_VM_IP_PORTMAP' NEG.`,
},
"fqdn": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -82,14 +76,6 @@ func ResourceComputeRegionNetworkEndpoint() *schema.Resource {
This can only be specified when network_endpoint_type of the NEG is INTERNET_FQDN_PORT.`,
AtLeastOneOf: []string{"fqdn", "ip_address"},
},
"instance": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `The name for a specific VM instance that the IP address belongs to.
This is required for network endpoints of type GCE_VM_IP_PORTMAP.`,
},
"ip_address": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -143,18 +129,6 @@ func resourceComputeRegionNetworkEndpointCreate(d *schema.ResourceData, meta int
} else if v, ok := d.GetOkExists("fqdn"); !tpgresource.IsEmptyValue(reflect.ValueOf(fqdnProp)) && (ok || !reflect.DeepEqual(v, fqdnProp)) {
obj["fqdn"] = fqdnProp
}
clientDestinationPortProp, err := expandNestedComputeRegionNetworkEndpointClientDestinationPort(d.Get("client_destination_port"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("client_destination_port"); !tpgresource.IsEmptyValue(reflect.ValueOf(clientDestinationPortProp)) && (ok || !reflect.DeepEqual(v, clientDestinationPortProp)) {
obj["clientDestinationPort"] = clientDestinationPortProp
}
instanceProp, err := expandNestedComputeRegionNetworkEndpointInstance(d.Get("instance"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("instance"); !tpgresource.IsEmptyValue(reflect.ValueOf(instanceProp)) && (ok || !reflect.DeepEqual(v, instanceProp)) {
obj["instance"] = instanceProp
}

obj, err = resourceComputeRegionNetworkEndpointEncoder(d, meta, obj)
if err != nil {
Expand Down Expand Up @@ -307,12 +281,6 @@ func resourceComputeRegionNetworkEndpointRead(d *schema.ResourceData, meta inter
if err := d.Set("fqdn", flattenNestedComputeRegionNetworkEndpointFqdn(res["fqdn"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionNetworkEndpoint: %s", err)
}
if err := d.Set("client_destination_port", flattenNestedComputeRegionNetworkEndpointClientDestinationPort(res["clientDestinationPort"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionNetworkEndpoint: %s", err)
}
if err := d.Set("instance", flattenNestedComputeRegionNetworkEndpointInstance(res["instance"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionNetworkEndpoint: %s", err)
}

return nil
}
Expand Down Expand Up @@ -381,24 +349,6 @@ func resourceComputeRegionNetworkEndpointDelete(d *schema.ResourceData, meta int
toDelete["fqdn"] = fqdnProp
}

// Instance
instanceProp, err := expandNestedComputeRegionNetworkEndpointInstance(d.Get("instance"), d, config)
if err != nil {
return err
}
if instanceProp != "" {
toDelete["instance"] = instanceProp
}

// Client Destination Port
clientDestinationPortProp, err := expandNestedComputeRegionNetworkEndpointClientDestinationPort(d.Get("client_destination_port"), d, config)
if err != nil {
return err
}
if clientDestinationPortProp != "" && d.Get("client_destination_port").(int) > 0 {
toDelete["clientDestinationPort"] = clientDestinationPortProp
}

obj = map[string]interface{}{
"networkEndpoints": []map[string]interface{}{toDelete},
}
Expand Down Expand Up @@ -468,21 +418,6 @@ func flattenNestedComputeRegionNetworkEndpointFqdn(v interface{}, d *schema.Reso
return v
}

func flattenNestedComputeRegionNetworkEndpointClientDestinationPort(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles int given in float64 format
if floatVal, ok := v.(float64); ok {
return int(floatVal)
}
return v
}

func flattenNestedComputeRegionNetworkEndpointInstance(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
}
return tpgresource.ConvertSelfLinkToV1(v.(string))
}

func expandNestedComputeRegionNetworkEndpointPort(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand All @@ -495,14 +430,6 @@ func expandNestedComputeRegionNetworkEndpointFqdn(v interface{}, d tpgresource.T
return v, nil
}

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

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

func resourceComputeRegionNetworkEndpointEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
// Network Endpoint Group is a URL parameter only, so replace self-link/path with resource name only.
if err := d.Set("region_network_endpoint_group", tpgresource.GetResourceNameFromSelfLink(d.Get("region_network_endpoint_group").(string))); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestAccComputeRegionNetworkEndpoint_regionNetworkEndpointInternetIpPortExam
ResourceName: "google_compute_region_network_endpoint.region-internet-ip-port-endpoint",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance", "region", "region_network_endpoint_group"},
ImportStateVerifyIgnore: []string{"region", "region_network_endpoint_group"},
},
},
})
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestAccComputeRegionNetworkEndpoint_regionNetworkEndpointInternetFqdnPortEx
ResourceName: "google_compute_region_network_endpoint.region-internet-fqdn-port-endpoint",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance", "region", "region_network_endpoint_group"},
ImportStateVerifyIgnore: []string{"region", "region_network_endpoint_group"},
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,55 +509,6 @@ resource "google_compute_network" "default" {
`, context)
}

func TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupPortmapExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeRegionNetworkEndpointGroupDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupPortmapExample(context),
},
{
ResourceName: "google_compute_region_network_endpoint_group.region_network_endpoint_group_portmap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region", "subnetwork"},
},
},
})
}

func testAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupPortmapExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_region_network_endpoint_group" "region_network_endpoint_group_portmap" {
name = "tf-test-portmap-neg%{random_suffix}"
region = "us-central1"
network = google_compute_network.default.id
subnetwork = google_compute_subnetwork.default.id
network_endpoint_type = "GCE_VM_IP_PORTMAP"
}
resource "google_compute_network" "default" {
name = "network%{random_suffix}"
}
resource "google_compute_subnetwork" "default" {
name = "subnetwork%{random_suffix}"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.default.id
}
`, context)
}

func testAccCheckComputeRegionNetworkEndpointGroupDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,101 +146,6 @@ resource "google_compute_region_network_endpoint" "add2" {
`, context) + testAccComputeRegionNetworkEndpoint_noRegionNetworkEndpoints(context)
}

func TestAccComputeRegionNetworkEndpoint_regionNetworkEndpointPortmapExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

negId := fmt.Sprintf("projects/%s/regions/%s/networkEndpointGroups/tf-test-portmap-neg%s",
envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), context["random_suffix"])

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRegionNetworkEndpoint_regionNetworkEndpointPortmapExample(context),
},
{
ResourceName: "google_compute_region_network_endpoint.region_network_endpoint_portmap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance", "region", "region_network_endpoint_group"},
},
{
// Delete all endpoints
Config: testAccComputeRegionNetworkEndpoint_regionNetworkEndpointPortmapNoEndpointExample(context),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeRegionNetworkEndpointWithPortsDestroyed(t, negId, "80"),
),
},
},
})
}

func testAccComputeRegionNetworkEndpoint_regionNetworkEndpointPortmapNoEndpointExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_network" "default" {
name = "network%{random_suffix}"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "default" {
name = "subnetwork%{random_suffix}"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.default.id
}
resource "google_compute_region_network_endpoint_group" default {
name = "tf-test-portmap-neg%{random_suffix}"
region = "us-central1"
network = google_compute_network.default.id
subnetwork = google_compute_subnetwork.default.id
network_endpoint_type = "GCE_VM_IP_PORTMAP"
}
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_instance" "default" {
name = "instance%{random_suffix}"
machine_type = "e2-medium"
zone = "us-central1-a"
boot_disk {
initialize_params {
image = data.google_compute_image.my_image.self_link
}
}
network_interface {
subnetwork = google_compute_subnetwork.default.id
access_config {
}
}
}
`, context)
}

func testAccComputeRegionNetworkEndpoint_regionNetworkEndpointPortmapExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_region_network_endpoint" "region_network_endpoint_portmap" {
region_network_endpoint_group = google_compute_region_network_endpoint_group.default.name
region = "us-central1"
instance = google_compute_instance.default.self_link
port = 80
ip_address = google_compute_instance.default.network_interface[0].network_ip
client_destination_port = 8080
}
`, context) + testAccComputeRegionNetworkEndpoint_regionNetworkEndpointPortmapNoEndpointExample(context)
}

func testAccComputeRegionNetworkEndpoint_noRegionNetworkEndpoints(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_region_network_endpoint_group" "neg" {
Expand Down
10 changes: 8 additions & 2 deletions website/docs/r/compute_region_network_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ resource "google_compute_network" "default" {
resource "google_compute_network" "default" {
name = "network"
auto_create_subnetworks = false
provider = google-beta
}
resource "google_compute_subnetwork" "default" {
name = "subnetwork"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.default.id
provider = google-beta
}
resource "google_compute_region_network_endpoint_group" default {
Expand All @@ -118,6 +120,7 @@ resource "google_compute_region_network_endpoint_group" default {
subnetwork = google_compute_subnetwork.default.id
network_endpoint_type = "GCE_VM_IP_PORTMAP"
provider = google-beta
}
resource "google_compute_region_network_endpoint" "region_network_endpoint_portmap" {
Expand All @@ -127,11 +130,13 @@ resource "google_compute_region_network_endpoint" "region_network_endpoint_portm
port = 80
ip_address = google_compute_instance.default.network_interface[0].network_ip
client_destination_port = 8080
provider = google-beta
}
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
provider = google-beta
}
resource "google_compute_instance" "default" {
Expand All @@ -150,6 +155,7 @@ resource "google_compute_instance" "default" {
access_config {
}
}
provider = google-beta
}
```

Expand Down Expand Up @@ -181,11 +187,11 @@ The following arguments are supported:
This can only be specified when network_endpoint_type of the NEG is INTERNET_FQDN_PORT.

* `client_destination_port` -
(Optional)
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Client destination port for the `GCE_VM_IP_PORTMAP` NEG.

* `instance` -
(Optional)
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
The name for a specific VM instance that the IP address belongs to.
This is required for network endpoints of type GCE_VM_IP_PORTMAP.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,20 @@ resource "google_compute_region_network_endpoint_group" "region_network_endpoint
subnetwork = google_compute_subnetwork.default.id
network_endpoint_type = "GCE_VM_IP_PORTMAP"
provider = google-beta
}
resource "google_compute_network" "default" {
name = "network"
provider = google-beta
}
resource "google_compute_subnetwork" "default" {
name = "subnetwork"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.default.id
provider = google-beta
}
```

Expand Down

0 comments on commit 5976eb5

Please sign in to comment.