diff --git a/.changelog/6373.txt b/.changelog/6373.txt new file mode 100644 index 00000000000..eee2fa1967c --- /dev/null +++ b/.changelog/6373.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: made `port` optional in `google_compute_network_endpoint` to be associated with `GCE_VM_IP` network endpoint groups +``` diff --git a/google/resource_compute_network_endpoint.go b/google/resource_compute_network_endpoint.go index e8ebd5bfd79..da00fa666e4 100644 --- a/google/resource_compute_network_endpoint.go +++ b/google/resource_compute_network_endpoint.go @@ -54,12 +54,6 @@ range).`, DiffSuppressFunc: compareResourceNames, Description: `The network endpoint group this endpoint is part of.`, }, - "port": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - Description: `Port number of network endpoint.`, - }, "instance": { Type: schema.TypeString, Optional: true, @@ -69,6 +63,12 @@ range).`, This is required for network endpoints of type GCE_VM_IP_PORT. The instance must be in the same zone of network endpoint group.`, }, + "port": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Description: `Port number of network endpoint.`, + }, "zone": { Type: schema.TypeString, Computed: true, @@ -285,7 +285,9 @@ func resourceComputeNetworkEndpointDelete(d *schema.ResourceData, meta interface if err != nil { return err } - toDelete["port"] = portProp + if portProp != 0 { + toDelete["port"] = portProp + } ipAddressProp, err := expandNestedComputeNetworkEndpointIpAddress(d.Get("ip_address"), d, config) if err != nil { diff --git a/google/resource_compute_network_endpoint_group_test.go b/google/resource_compute_network_endpoint_group_test.go index 6e1510bcdf6..bae87c9fa94 100644 --- a/google/resource_compute_network_endpoint_group_test.go +++ b/google/resource_compute_network_endpoint_group_test.go @@ -31,6 +31,31 @@ func TestAccComputeNetworkEndpointGroup_networkEndpointGroup(t *testing.T) { }) } +func TestAccComputeNetworkEndpointGroup_internalEndpoint(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeNetworkEndpointGroupDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeNetworkEndpointGroup_internalEndpoint(context), + }, + { + ResourceName: "google_compute_network_endpoint_group.neg", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"network", "subnetwork", "zone"}, + }, + }, + }) +} + func testAccComputeNetworkEndpointGroup_networkEndpointGroup(context map[string]interface{}) string { return Nprintf(` resource "google_compute_network_endpoint_group" "neg" { @@ -46,3 +71,53 @@ resource "google_compute_network" "default" { } `, context) } + +func testAccComputeNetworkEndpointGroup_internalEndpoint(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_network_endpoint_group" "neg" { + name = "tf-test-my-lb-neg%{random_suffix}" + network = google_compute_network.internal.id + subnetwork = google_compute_subnetwork.internal.id + zone = "us-central1-a" + network_endpoint_type = "GCE_VM_IP" +} + +resource "google_compute_network_endpoint" "endpoint" { + network_endpoint_group = google_compute_network_endpoint_group.neg.name + #ip_address = "127.0.0.1" + instance = google_compute_instance.default.name + ip_address = google_compute_instance.default.network_interface[0].network_ip +} + +resource "google_compute_network" "internal" { + name = "tf-test-neg-network%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "internal"{ + name = "tf-test-my-subnetwork%{random_suffix}" + network = google_compute_network.internal.id + ip_cidr_range = "10.128.0.0/20" + region = "us-central1" + private_ip_google_access= true +} + +resource "google_compute_instance" "default" { + name = "tf-test-neg-%{random_suffix}" + machine_type = "e2-medium" + + boot_disk { + initialize_params { + image = "debian-8-jessie-v20160803" + } + } + + network_interface { + subnetwork = google_compute_subnetwork.internal.self_link + access_config { + } + } +} + +`, context) +} diff --git a/website/docs/r/compute_network_endpoint.html.markdown b/website/docs/r/compute_network_endpoint.html.markdown index 43f84849fe4..ecc84994c23 100644 --- a/website/docs/r/compute_network_endpoint.html.markdown +++ b/website/docs/r/compute_network_endpoint.html.markdown @@ -94,10 +94,6 @@ resource "google_compute_subnetwork" "default" { The following arguments are supported: -* `port` - - (Required) - Port number of network endpoint. - * `ip_address` - (Required) IPv4 address of network endpoint. The IP address must belong @@ -118,6 +114,10 @@ The following arguments are supported: This is required for network endpoints of type GCE_VM_IP_PORT. The instance must be in the same zone of network endpoint group. +* `port` - + (Optional) + Port number of network endpoint. + * `zone` - (Optional) Zone where the containing network endpoint group is located.