Skip to content

Commit 123481a

Browse files
Add support for dataproc cluster_tier (#14595) (#10453)
[upstream:d69d1e450e8b72f29303dbdb26015122440048ea] Signed-off-by: Modular Magician <[email protected]>
1 parent f6c5c12 commit 123481a

File tree

5 files changed

+94
-3
lines changed

5 files changed

+94
-3
lines changed

.changelog/14595.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
dataproc: added `cluster_config.cluster_tier` field to `google_dataproc_cluster` resource
3+
```

google-beta/services/dataproc/resource_dataproc_cluster.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ var (
118118
}
119119

120120
clusterConfigKeys = []string{
121+
"cluster_config.0.cluster_tier",
121122
"cluster_config.0.staging_bucket",
122123
"cluster_config.0.temp_bucket",
123124
"cluster_config.0.gce_cluster_config",
@@ -568,7 +569,15 @@ func ResourceDataprocCluster() *schema.Resource {
568569
Description: `Allows you to configure various aspects of the cluster.`,
569570
Elem: &schema.Resource{
570571
Schema: map[string]*schema.Schema{
571-
572+
"cluster_tier": {
573+
Type: schema.TypeString,
574+
Optional: true,
575+
Computed: true,
576+
Description: `Specifies the tier of the cluster created.`,
577+
AtLeastOneOf: clusterConfigKeys,
578+
ForceNew: true,
579+
ValidateFunc: validation.StringInSlice([]string{"CLUSTER_TIER_UNSPECIFIED", "CLUSTER_TIER_STANDARD", "CLUSTER_TIER_PREMIUM"}, false),
580+
},
572581
"staging_bucket": {
573582
Type: schema.TypeString,
574583
Optional: true,
@@ -2089,6 +2098,10 @@ func expandClusterConfig(d *schema.ResourceData, config *transport_tpg.Config) (
20892098
conf.TempBucket = v.(string)
20902099
}
20912100

2101+
if v, ok := d.GetOk("cluster_config.0.cluster_tier"); ok {
2102+
conf.ClusterTier = v.(string)
2103+
}
2104+
20922105
c, err := expandGceClusterConfig(d, config)
20932106
if err != nil {
20942107
return nil, err
@@ -2985,8 +2998,8 @@ func flattenClusterConfig(d *schema.ResourceData, cfg *dataproc.ClusterConfig) (
29852998
}
29862999

29873000
data := map[string]interface{}{
2988-
"staging_bucket": d.Get("cluster_config.0.staging_bucket").(string),
2989-
3001+
"staging_bucket": d.Get("cluster_config.0.staging_bucket").(string),
3002+
"cluster_tier": d.Get("cluster_config.0.cluster_tier").(string),
29903003
"bucket": cfg.ConfigBucket,
29913004
"temp_bucket": cfg.TempBucket,
29923005
"gce_cluster_config": flattenGceClusterConfig(d, cfg.GceClusterConfig),

google-beta/services/dataproc/resource_dataproc_cluster_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ fields:
9292
- field: 'cluster_config.software_config.properties'
9393
- field: 'cluster_config.staging_bucket'
9494
- field: 'cluster_config.temp_bucket'
95+
- field: 'cluster_config.cluster_tier'
9596
- field: 'cluster_config.worker_config.accelerators.accelerator_count'
9697
- field: 'cluster_config.worker_config.accelerators.accelerator_type'
9798
- field: 'cluster_config.worker_config.disk_config.boot_disk_size_gb'

google-beta/services/dataproc/resource_dataproc_cluster_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,76 @@ func TestAccDataprocCluster_withMetastoreConfig(t *testing.T) {
12401240
})
12411241
}
12421242

1243+
func TestAccDataprocCluster_withClusterTier(t *testing.T) {
1244+
t.Parallel()
1245+
1246+
var cluster dataproc.Cluster
1247+
rnd := acctest.RandString(t, 10)
1248+
networkName := acctest.BootstrapSharedTestNetwork(t, "dataproc-cluster")
1249+
subnetworkName := acctest.BootstrapSubnet(t, "dataproc-cluster", networkName)
1250+
acctest.BootstrapFirewallForDataprocSharedNetwork(t, "dataproc-cluster", networkName)
1251+
1252+
acctest.VcrTest(t, resource.TestCase{
1253+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1254+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1255+
CheckDestroy: testAccCheckDataprocClusterDestroy(t),
1256+
Steps: []resource.TestStep{
1257+
{
1258+
// Set tier to CLUSTER_TIER_STANDARD
1259+
Config: testAccDataprocCluster_withClusterTier(rnd, subnetworkName, "CLUSTER_TIER_STANDARD"),
1260+
Check: resource.ComposeTestCheckFunc(
1261+
testAccCheckDataprocClusterExists(t, "google_dataproc_cluster.tier_cluster", &cluster),
1262+
resource.TestCheckResourceAttr("google_dataproc_cluster.tier_cluster", "cluster_config.0.cluster_tier", "CLUSTER_TIER_STANDARD"),
1263+
),
1264+
},
1265+
{
1266+
// Set tier to CLUSTER_TIER_PREMIUM
1267+
Config: testAccDataprocCluster_withClusterTier(rnd, subnetworkName, "CLUSTER_TIER_PREMIUM"),
1268+
Check: resource.ComposeTestCheckFunc(
1269+
testAccCheckDataprocClusterExists(t, "google_dataproc_cluster.tier_cluster", &cluster),
1270+
resource.TestCheckResourceAttr("google_dataproc_cluster.tier_cluster", "cluster_config.0.cluster_tier", "CLUSTER_TIER_PREMIUM"),
1271+
),
1272+
},
1273+
},
1274+
})
1275+
}
1276+
1277+
func testAccDataprocCluster_withClusterTier(rnd, subnetworkName, tier string) string {
1278+
tierConfig := ""
1279+
if tier != "" {
1280+
tierConfig = fmt.Sprintf(`cluster_tier = "%s"`, tier)
1281+
}
1282+
clusterName := fmt.Sprintf("tf-test-dproc-tier-%s", rnd)
1283+
bucketName := clusterName + "-temp-bucket"
1284+
1285+
return fmt.Sprintf(`
1286+
resource "google_storage_bucket" "bucket" {
1287+
name = "%s"
1288+
location = "US"
1289+
force_destroy = "true"
1290+
}
1291+
1292+
resource "google_dataproc_cluster" "tier_cluster" {
1293+
name = "%s"
1294+
region = "us-central1"
1295+
1296+
cluster_config {
1297+
%s
1298+
staging_bucket = google_storage_bucket.bucket.name
1299+
temp_bucket = google_storage_bucket.bucket.name
1300+
1301+
software_config {
1302+
image_version = "2.3.4-debian12"
1303+
}
1304+
1305+
gce_cluster_config {
1306+
subnetwork = "%s"
1307+
}
1308+
}
1309+
}
1310+
`, bucketName, clusterName, tierConfig, subnetworkName)
1311+
}
1312+
12431313
func testAccCheckDataprocClusterDestroy(t *testing.T) resource.TestCheckFunc {
12441314
return func(s *terraform.State) error {
12451315
config := acctest.GoogleProviderConfig(t)

website/docs/r/dataproc_cluster.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ resource "google_dataproc_cluster" "mycluster" {
5959
cluster_config {
6060
staging_bucket = "dataproc-staging-bucket"
6161
62+
cluster_tier = "CLUSTER_TIER_STANDARD"
63+
6264
master_config {
6365
num_instances = 1
6466
machine_type = "e2-medium"
@@ -355,6 +357,8 @@ resource "google_dataproc_cluster" "accelerated_cluster" {
355357
and jobs data, such as Spark and MapReduce history files.
356358
Note: If you don't explicitly specify a `temp_bucket` then GCP will auto create / assign one for you.
357359

360+
* `cluster_tier` - (Optional) The tier of the cluster.
361+
358362
* `gce_cluster_config` (Optional) Common config settings for resources of Google Compute Engine cluster
359363
instances, applicable to all instances in the cluster. Structure [defined below](#nested_gce_cluster_config).
360364

0 commit comments

Comments
 (0)