Skip to content

Commit

Permalink
support SPOT for secondary worker. (#7000) (#13335)
Browse files Browse the repository at this point in the history
* support SPOT for secondary worker.

* remove version guard for SPOT

* rerun

* remove trailing space

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Dec 22, 2022
1 parent b52f2ba commit d4b7016
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/7000.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dataproc: added support for `SPOT` option for `preemptibility` in `google_dataproc_cluster`
```
2 changes: 1 addition & 1 deletion google/resource_dataproc_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func resourceDataprocCluster() *schema.Resource {
"cluster_config.0.preemptible_worker_config.0.disk_config",
},
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"PREEMPTIBILITY_UNSPECIFIED", "NON_PREEMPTIBLE", "PREEMPTIBLE"}, false),
ValidateFunc: validation.StringInSlice([]string{"PREEMPTIBILITY_UNSPECIFIED", "NON_PREEMPTIBLE", "PREEMPTIBLE", "SPOT"}, false),
Default: "PREEMPTIBLE",
},

Expand Down
56 changes: 56 additions & 0 deletions google/resource_dataproc_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,27 @@ func TestAccDataprocCluster_nonPreemptibleSecondary(t *testing.T) {
})
}

func TestAccDataprocCluster_spotSecondary(t *testing.T) {
t.Parallel()

rnd := randString(t, 10)
var cluster dataproc.Cluster
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDataprocClusterDestroy(t),
Steps: []resource.TestStep{
{
Config: testAccDataprocCluster_spotSecondary(rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataprocClusterExists(t, "google_dataproc_cluster.spot_secondary", &cluster),
resource.TestCheckResourceAttr("google_dataproc_cluster.spot_secondary", "cluster_config.0.preemptible_worker_config.0.preemptibility", "SPOT"),
),
},
},
})
}

func TestAccDataprocCluster_withStagingBucket(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1498,6 +1519,41 @@ resource "google_dataproc_cluster" "non_preemptible_secondary" {
`, rnd)
}

func testAccDataprocCluster_spotSecondary(rnd string) string {
return fmt.Sprintf(`
resource "google_dataproc_cluster" "spot_secondary" {
name = "tf-test-dproc-%s"
region = "us-central1"
cluster_config {
master_config {
num_instances = "1"
machine_type = "e2-medium"
disk_config {
boot_disk_size_gb = 35
}
}
worker_config {
num_instances = "2"
machine_type = "e2-medium"
disk_config {
boot_disk_size_gb = 35
}
}
preemptible_worker_config {
num_instances = "1"
preemptibility = "SPOT"
disk_config {
boot_disk_size_gb = 35
}
}
}
}
`, rnd)
}

func testAccDataprocCluster_withStagingBucketOnly(bucketName string) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "bucket" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/dataproc_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ will be set for you based on whatever was set for the `worker_config.machine_typ
* PREEMPTIBILITY_UNSPECIFIED
* NON_PREEMPTIBLE
* PREEMPTIBLE
* SPOT

* `disk_config` (Optional) Disk Config

Expand Down

0 comments on commit d4b7016

Please sign in to comment.