From c4b92411411b94322b83ce9a5386077d87f101c4 Mon Sep 17 00:00:00 2001 From: Nick Travers Date: Tue, 11 May 2021 09:28:58 -0700 Subject: [PATCH] upup: gcetasks: force send AutoCreateSubnetworks field when set to false When a struct contains a default value, it is not present in the serialized output attached to request bodies sent to GCP. In the case that a user wishes to explicitly set the `AutoCreateSubnetworks` field to `false`, the request sent to GCP does not contain this directive, and the network is provisioned with the default of `true`. Explicitly specify that the `false` value should be present on the request sent to the GCP API, making use of the `ForceSendFields` field in the requset struct. Signed-off-by: Nick Travers --- upup/pkg/fi/cloudup/gcetasks/network.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/upup/pkg/fi/cloudup/gcetasks/network.go b/upup/pkg/fi/cloudup/gcetasks/network.go index d10d936784..0bcc2a7766 100644 --- a/upup/pkg/fi/cloudup/gcetasks/network.go +++ b/upup/pkg/fi/cloudup/gcetasks/network.go @@ -133,6 +133,11 @@ func (_ *Network) RenderGCE(t *gce.GCEAPITarget, a, e, changes *Network) error { case "custom": network.AutoCreateSubnetworks = false + // The boolean default value of "false" is omitted when the struct + // is serialized, which results in the network being created with + // the auto-create subnetworks default of "true". Explicitly send + // the default value. + network.ForceSendFields = []string{"AutoCreateSubnetworks"} } _, err := t.Cloud.Compute().Networks().Insert(t.Cloud.Project(), network) if err != nil {