Repository: cloudflare/cloudflare-go
Pull request #1441 (2023-11-14 23:09:22)

Add support for virtual network id in origin
<!-- 
Provide a general summary of your changes in the title above. You should
remove this overview, any sections and any section descriptions you
don't need below before submitting. There isn't a strict requirement to
use this template if you can structure your description and still cover
these points. 
-->

## Description
Add support to `virtual_network_id` listed in CloudFlare API doc here: https://developers.cloudflare.com/api/operations/account-load-balancer-pools-create-pool as the current golang client does not support this field.

<!--
Describe your changes in detail through motivation and context. Why is
this change required? What problem does it solve? If it fixes an open
issue, link to the issue using GitHub's closing issues keywords[1].
-->
## Has your change been tested?
Yes, confirmed test passed and existing functionality not affected
<!--
Explain how the change has been tested and what you ran to confirm your
change affects other parts of the code. Automated tests are generally
expected and changes without tests should explain why they aren't
required.
-->

## Screenshots (if appropriate):

## Types of changes

What sort of change does your code introduce/modify?

- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] This change is using publicly documented in [cloudflare/api-schemas](https://github.com/cloudflare/api-schemas) 
      and relies on stable APIs.

[1]: https://help.github.com/articles/closing-issues-using-keywords/



Patch:
diff --git a/.changelog/1441.txt b/.changelog/1441.txt
new file mode 100644
index 000000000..0901f1c8c
--- /dev/null
+++ b/.changelog/1441.txt
@@ -0,0 +1,3 @@
+```release-note:bug
+load_balancing: Add support for virtual network id in origins
+```
\ No newline at end of file
diff --git a/load_balancing.go b/load_balancing.go
index ad59b5c7f..bb46f8333 100644
--- a/load_balancing.go
+++ b/load_balancing.go
@@ -47,6 +47,9 @@ type LoadBalancerOrigin struct {
 	// weight is used to scale the origin's open connections.
 	Weight float64             `json:"weight"`
 	Header map[string][]string `json:"header"`
+	// The virtual network subnet ID the origin belongs in.
+	// Virtual network must also belong to the account.
+	VirtualNetworkID string `json:"virtual_network_id,omitempty"`
 }
 
 // LoadBalancerOriginSteering controls origin selection for new sessions and traffic without session affinity.


Test patch:
diff --git a/load_balancing_test.go b/load_balancing_test.go
index 2b3d3ae6c..0bc00b5f6 100644
--- a/load_balancing_test.go
+++ b/load_balancing_test.go
@@ -47,7 +47,8 @@ func TestCreateLoadBalancerPool(t *testing.T) {
                       "Host": [
                           "example.com"
                       ]
-                  }
+                  },
+			      "virtual_network_id":"a5624d4e-044a-4ff0-b3e1-e2465353d4b4"
                 }
               ],
               "notification_email": "someone@example.com",
@@ -90,7 +91,8 @@ func TestCreateLoadBalancerPool(t *testing.T) {
                       "Host": [
                           "example.com"
                       ]
-                  }
+                  },
+			      "virtual_network_id":"a5624d4e-044a-4ff0-b3e1-e2465353d4b4"
                 }
               ],
               "notification_email": "someone@example.com",
@@ -137,6 +139,7 @@ func TestCreateLoadBalancerPool(t *testing.T) {
 				Header: map[string][]string{
 					"Host": {"example.com"},
 				},
+				VirtualNetworkID: "a5624d4e-044a-4ff0-b3e1-e2465353d4b4",
 			},
 		},
 		NotificationEmail: "someone@example.com",
@@ -169,6 +172,7 @@ func TestCreateLoadBalancerPool(t *testing.T) {
 				Header: map[string][]string{
 					"Host": {"example.com"},
 				},
+				VirtualNetworkID: "a5624d4e-044a-4ff0-b3e1-e2465353d4b4",
 			},
 		},
 		NotificationEmail: "someone@example.com",
@@ -286,7 +290,8 @@ func TestListLoadBalancerPools(t *testing.T) {
                         "name": "app-server-1",
                         "address": "198.51.100.1",
                         "enabled": true,
-                        "weight": 1
+                        "weight": 1,
+					    "virtual_network_id":"a5624d4e-044a-4ff0-b3e1-e2465353d4b4"
                       }
                     ],
                     "notification_email": "someone@example.com"
@@ -318,10 +323,11 @@ func TestListLoadBalancerPools(t *testing.T) {
 			},
 			Origins: []LoadBalancerOrigin{
 				{
-					Name:    "app-server-1",
-					Address: "198.51.100.1",
-					Enabled: true,
-					Weight:  1,
+					Name:             "app-server-1",
+					Address:          "198.51.100.1",
+					Enabled:          true,
+					Weight:           1,
+					VirtualNetworkID: "a5624d4e-044a-4ff0-b3e1-e2465353d4b4",
 				},
 			},
 			NotificationEmail: "someone@example.com",
@@ -371,7 +377,8 @@ func TestGetLoadBalancerPool(t *testing.T) {
                   "name": "app-server-1",
                   "address": "198.51.100.1",
                   "enabled": true,
-                  "weight": 1
+                  "weight": 1,
+				  "virtual_network_id":"a5624d4e-044a-4ff0-b3e1-e2465353d4b4"
                 }
               ],
               "notification_email": "someone@example.com"
@@ -395,10 +402,11 @@ func TestGetLoadBalancerPool(t *testing.T) {
 		},
 		Origins: []LoadBalancerOrigin{
 			{
-				Name:    "app-server-1",
-				Address: "198.51.100.1",
-				Enabled: true,
-				Weight:  1,
+				Name:             "app-server-1",
+				Address:          "198.51.100.1",
+				Enabled:          true,
+				Weight:           1,
+				VirtualNetworkID: "a5624d4e-044a-4ff0-b3e1-e2465353d4b4",
 			},
 		},
 		NotificationEmail: "someone@example.com",
@@ -483,7 +491,8 @@ func TestUpdateLoadBalancerPool(t *testing.T) {
                       "Host": [
                           "example.com"
                       ]
-                  }
+                  },
+			      "virtual_network_id":"a5624d4e-044a-4ff0-b3e1-e2465353d4b4"
                 }
               ],
               "notification_email": "nobody@example.com",
@@ -516,7 +525,8 @@ func TestUpdateLoadBalancerPool(t *testing.T) {
                       "Host": [
                           "example.com"
                       ]
-                  }
+                  },
+			      "virtual_network_id":"a5624d4e-044a-4ff0-b3e1-e2465353d4b4"
                 }
               ],
               "notification_email": "nobody@example.com",
@@ -549,6 +559,7 @@ func TestUpdateLoadBalancerPool(t *testing.T) {
 				Header: map[string][]string{
 					"Host": {"example.com"},
 				},
+				VirtualNetworkID: "a5624d4e-044a-4ff0-b3e1-e2465353d4b4",
 			},
 		},
 		NotificationEmail: "nobody@example.com",
@@ -573,6 +584,7 @@ func TestUpdateLoadBalancerPool(t *testing.T) {
 				Header: map[string][]string{
 					"Host": {"example.com"},
 				},
+				VirtualNetworkID: "a5624d4e-044a-4ff0-b3e1-e2465353d4b4",
 			},
 		},
 		NotificationEmail: "nobody@example.com",