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 4, 2024
1 parent 183b0d5 commit d9e36b3
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,15 @@ func expandGceClusterConfig(d *schema.ResourceData, config *transport_tpg.Config
}
if v, ok := cfg["internal_ip_only"]; ok {
conf.InternalIpOnly = v.(bool)
if isInternalIpOnlySpecified(d) {
// 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 @@ -2217,6 +2225,43 @@ func expandGceClusterConfig(d *schema.ResourceData, config *transport_tpg.Config
return conf, nil
}

// isInternalIpOnlySpecified returns true if the original configuration specified by
// the user sets 'cluster_config.0.gce_cluster_config.0.internal_ip_only' to
// any non-nil value (true or false).
func isInternalIpOnlySpecified(d *schema.ResourceData) bool {
rawConfig := d.GetRawConfig()
if !rawConfig.Type().IsObjectType() {
return false
}
if _, ok := rawConfig.Type().AttributeTypes()["cluster_config"]; !ok {
return false
}
clusterConfig := rawConfig.GetAttr("cluster_config")
if !clusterConfig.Type().IsListType() || len(clusterConfig.AsValueSlice()) == 0 {
return false
}
clusterConfig0 := clusterConfig.AsValueSlice()[0]
if !clusterConfig0.Type().IsObjectType() {
return false
}
if _, ok := clusterConfig0.Type().AttributeTypes()["gce_cluster_config"]; !ok {
return false
}
gceClusterConfig := clusterConfig0.GetAttr("gce_cluster_config")
if !gceClusterConfig.Type().IsListType() || len(gceClusterConfig.AsValueSlice()) == 0 {
return false
}
gceClusterConfig0 := gceClusterConfig.AsValueSlice()[0]
if !gceClusterConfig0.Type().IsObjectType() {
return false
}
if _, ok := gceClusterConfig0.Type().AttributeTypes()["internal_ip_only"]; !ok {
return false
}
internalIpOnly := gceClusterConfig0.GetAttr("internal_ip_only")
return !internalIpOnly.IsNull()
}

func expandSecurityConfig(cfg map[string]interface{}) *dataproc.SecurityConfig {
conf := &dataproc.SecurityConfig{}
if kfg, ok := cfg["kerberos_config"]; ok {
Expand Down

0 comments on commit d9e36b3

Please sign in to comment.