Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataproc: Make internal_ip_only a computed, not defaulted, field. Always send it when specified. #11791

Closed
8 changes: 6 additions & 2 deletions mmv1/third_party/terraform/acctest/bootstrap_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ func BootstrapSubnetForDataprocBatches(t *testing.T, subnetName string, networkN
subnetOptions := map[string]interface{}{
"privateIpGoogleAccess": true,
}
return BootstrapSubnetWithOverrides(t, subnetName, networkName, subnetOptions)
return bootstrapSubnetWithOverrides(t, subnetName, networkName, subnetOptions, "10.78.0.0/20")
}

func BootstrapSubnet(t *testing.T, subnetName string, networkName string) string {
Expand All @@ -930,6 +930,10 @@ func BootstrapSubnetWithFirewallForDataprocBatches(t *testing.T, testId string,
}

func BootstrapSubnetWithOverrides(t *testing.T, subnetName string, networkName string, subnetOptions map[string]interface{}) string {
return bootstrapSubnetWithOverrides(t, subnetName, networkName, subnetOptions, "10.77.0.0/20")
}

func bootstrapSubnetWithOverrides(t *testing.T, subnetName string, networkName string, subnetOptions map[string]interface{}, ipCidrRange string) string {
projectID := envvar.GetTestProjectFromEnv()
region := envvar.GetTestRegionFromEnv()

Expand All @@ -955,7 +959,7 @@ func BootstrapSubnetWithOverrides(t *testing.T, subnetName string, networkName s
"name": subnetName,
"region ": region,
"network": networkUrl,
"ipCidrRange": "10.77.0.0/20",
"ipCidrRange": ipCidrRange,
}

if len(subnetOptions) != 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,9 @@ func ResourceDataprocCluster() *schema.Resource {
"internal_ip_only": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
AtLeastOneOf: gceClusterConfigKeys,
ForceNew: true,
Default: false,
Description: `By default, clusters are not restricted to internal IP addresses, and will have ephemeral external IP addresses assigned to each instance. If set to true, all instances in the cluster will only have internal IP addresses. Note: Private Google Access (also known as privateIpGoogleAccess) must be enabled on the subnetwork that the cluster will be launched in.`,
},

Expand Down Expand Up @@ -2177,8 +2177,15 @@ func expandGceClusterConfig(d *schema.ResourceData, config *transport_tpg.Config
}
if v, ok := cfg["internal_ip_only"]; ok {
conf.InternalIpOnly = v.(bool)
conf.ForceSendFields = append(conf.ForceSendFields, "InternalIpOnly")
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 @@ -2218,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
Loading