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 <n.e.travers@gmail.com>
This commit is contained in:
Nick Travers 2021-05-11 09:28:58 -07:00
parent 6dd743ffd6
commit c4b9241141
1 changed files with 5 additions and 0 deletions

View File

@ -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 {