Skip to content

Commit

Permalink
Always send internal_ip_only, if it is set by the user.
Browse files Browse the repository at this point in the history
This is required because the autogenerated Dataproc API client has `omitempty` on the field. So if the user specifies `internal_ip_only: false`, then it would not get sent to Dataproc. Thus Dataproc uses server-side defaulting. We don't want that. If the user specifies the value, we want to ensure that value is used.
  • Loading branch information
Harwayne committed Oct 2, 2024
1 parent 183b0d5 commit fc08f11
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"regexp"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -2177,7 +2178,13 @@ func expandGceClusterConfig(d *schema.ResourceData, config *transport_tpg.Config
}
if v, ok := cfg["internal_ip_only"]; ok {
conf.InternalIpOnly = v.(bool)
// Normally default values are omitted. Concretely this means that if v is
// false, then it would not get sent on the request to Dataproc. However,
// the user has explicitly set internal_ip_only, therefore we need to send
// it on the wire to ensure Dataproc does not use server-side defaulting.
conf.ForceSendFields = append(conf.ForceSendFields, "InternalIpOnly")
}

if v, ok := cfg["metadata"]; ok {
conf.Metadata = tpgresource.ConvertStringMap(v.(map[string]interface{}))
}
Expand Down Expand Up @@ -3106,11 +3113,18 @@ func flattenGceClusterConfig(d *schema.ResourceData, gcc *dataproc.GceClusterCon
}

gceConfig := map[string]interface{}{
"tags": schema.NewSet(schema.HashString, tpgresource.ConvertStringArrToInterface(gcc.Tags)),
"service_account": gcc.ServiceAccount,
"zone": tpgresource.GetResourceNameFromSelfLink(gcc.ZoneUri),
"internal_ip_only": gcc.InternalIpOnly,
"metadata": gcc.Metadata,
"tags": schema.NewSet(schema.HashString, tpgresource.ConvertStringArrToInterface(gcc.Tags)),
"service_account": gcc.ServiceAccount,
"zone": tpgresource.GetResourceNameFromSelfLink(gcc.ZoneUri),
"metadata": gcc.Metadata,
}

// InternalIpOnly needs to differentiate between false and unspecified, because
// unspecified means server-side defaulting. expandGceClusterConfig will add
// "InternalIpOnly" to gcc.ForceSendFields if the value is specified. So use
// that to distinguish between the cases.
if gcc.InternalIpOnly || slices.Contains(gcc.ForceSendFields, "InternalIpOnly") {
gceConfig["internal_ip_only"] = gcc.InternalIpOnly
}

if gcc.NetworkUri != "" {
Expand Down

0 comments on commit fc08f11

Please sign in to comment.