Skip to content

Commit

Permalink
Make Network Endpoint Port optional (#6373) (#12267)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Aug 5, 2022
1 parent 766f86a commit 0920fe4
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 11 deletions.
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

0 comments on commit 0920fe4

Please sign in to comment.