Skip to content
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

Make Network Endpoint Port optional #12267

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/6373.txt
Original file line number Diff line number Diff line change
@@ -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
```
16 changes: 9 additions & 7 deletions google/resource_compute_network_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
75 changes: 75 additions & 0 deletions google/resource_compute_network_endpoint_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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)
}
8 changes: 4 additions & 4 deletions website/docs/r/compute_network_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down