Skip to content

Commit

Permalink
Dataproc Cluster: Preserve preemptible config fields when preee… (Goo…
Browse files Browse the repository at this point in the history
  • Loading branch information
rileykarson authored and Nathan Klish committed May 18, 2020
1 parent 18c232e commit e619dbd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions third_party/terraform/resources/resource_dataproc_cluster.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,22 @@ func flattenGceClusterConfig(d *schema.ResourceData, gcc *dataproc.GceClusterCon
}

func flattenPreemptibleInstanceGroupConfig(d *schema.ResourceData, icg *dataproc.InstanceGroupConfig) []map[string]interface{} {
// if num_instances is 0, icg will always be returned nil. This means the
// server has discarded diskconfig etc. However, the only way to remove the
// preemptible group is to set the size to 0, because it's O+C. Many users
// won't remove the rest of the config (eg disk config). Therefore, we need to
// preserve the other set fields by using the old state to stop users from
// getting a diff.
if icg == nil {
icgSchema := d.Get("cluster_config.0.preemptible_worker_config")
log.Printf("[DEBUG] state of preemptible is %#v", icgSchema)
if v, ok := icgSchema.([]interface{}); ok && len(v) > 0 {
if m, ok := v[0].(map[string]interface{}); ok {
return []map[string]interface{}{m}
}
}
}

disk := map[string]interface{}{}
data := map[string]interface{}{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ func TestAccDataprocCluster_updatable(t *testing.T) {
resource.TestCheckResourceAttr("google_dataproc_cluster.updatable", "cluster_config.0.worker_config.0.num_instances", "2"),
resource.TestCheckResourceAttr("google_dataproc_cluster.updatable", "cluster_config.0.preemptible_worker_config.0.num_instances", "1")),
},
{
Config: testAccDataprocCluster_updatable(rnd, 2, 0),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataprocClusterExists("google_dataproc_cluster.updatable", &cluster),
resource.TestCheckResourceAttr("google_dataproc_cluster.updatable", "cluster_config.0.master_config.0.num_instances", "1"),
resource.TestCheckResourceAttr("google_dataproc_cluster.updatable", "cluster_config.0.worker_config.0.num_instances", "2"),
resource.TestCheckResourceAttr("google_dataproc_cluster.updatable", "cluster_config.0.preemptible_worker_config.0.num_instances", "0")),
},
{
Config: testAccDataprocCluster_updatable(rnd, 3, 2),
Check: resource.ComposeTestCheckFunc(
Expand Down

0 comments on commit e619dbd

Please sign in to comment.