From 6ecc629a80d004a032286defb027b5fd873861af Mon Sep 17 00:00:00 2001 From: megan07 Date: Mon, 22 Jul 2019 19:20:26 +0000 Subject: [PATCH] add optional components to dataproc_cluster Signed-off-by: Modular Magician --- google/resource_dataproc_cluster.go | 19 ++++++++++ google/resource_dataproc_cluster_test.go | 45 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/google/resource_dataproc_cluster.go b/google/resource_dataproc_cluster.go index f36ff1ca6d3..7a2f4659dde 100644 --- a/google/resource_dataproc_cluster.go +++ b/google/resource_dataproc_cluster.go @@ -284,6 +284,16 @@ func resourceDataprocCluster() *schema.Resource { // values (including overrides) for all properties, whilst override_properties // is only for properties the user specifically wants to override. If nothing // is overridden, this will be empty. + + "optional_components": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"COMPONENT_UNSPECIFIED", "ANACONDA", "DRUID", "HIVE_WEBHCAT", + "JUPYTER", "KERBEROS", "PRESTO", "ZEPPELIN", "ZOOKEEPER"}, false), + }, + }, }, }, }, @@ -601,6 +611,14 @@ func expandSoftwareConfig(cfg map[string]interface{}) *dataproc.SoftwareConfig { if v, ok := cfg["image_version"]; ok { conf.ImageVersion = v.(string) } + if components, ok := cfg["optional_components"]; ok { + compSet := components.(*schema.Set) + components := make([]string, compSet.Len()) + for i, component := range compSet.List() { + components[i] = component.(string) + } + conf.OptionalComponents = components + } return conf } @@ -836,6 +854,7 @@ func flattenClusterConfig(d *schema.ResourceData, cfg *dataproc.ClusterConfig) ( func flattenSoftwareConfig(d *schema.ResourceData, sc *dataproc.SoftwareConfig) []map[string]interface{} { data := map[string]interface{}{ "image_version": sc.ImageVersion, + "optional_components": sc.OptionalComponents, "properties": sc.Properties, "override_properties": d.Get("cluster_config.0.software_config.0.override_properties").(map[string]interface{}), } diff --git a/google/resource_dataproc_cluster_test.go b/google/resource_dataproc_cluster_test.go index 7cbcbbbd243..706f1ee8a7b 100644 --- a/google/resource_dataproc_cluster_test.go +++ b/google/resource_dataproc_cluster_test.go @@ -428,6 +428,27 @@ func TestAccDataprocCluster_withImageVersion(t *testing.T) { }) } +func TestAccDataprocCluster_withOptionalComponents(t *testing.T) { + t.Parallel() + + rnd := acctest.RandString(10) + var cluster dataproc.Cluster + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDataprocClusterDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccDataprocCluster_withOptionalComponents(rnd), + Check: resource.ComposeTestCheckFunc( + testAccCheckDataprocClusterExists("google_dataproc_cluster.with_opt_components", &cluster), + testAccCheckDataprocClusterHasOptionalComponents(&cluster, "ANACONDA", "ZOOKEEPER"), + ), + }, + }, + }) +} + func TestAccDataprocCluster_withLabels(t *testing.T) { t.Parallel() @@ -580,7 +601,17 @@ func testAccCheckDataprocStagingBucketExists(bucketName string) resource.TestChe } return nil } +} + +func testAccCheckDataprocClusterHasOptionalComponents(cluster *dataproc.Cluster, components ...string) func(s *terraform.State) error { + return func(s *terraform.State) error { + if !reflect.DeepEqual(components, cluster.Config.SoftwareConfig.OptionalComponents) { + return fmt.Errorf("Cluster does not contain expected optional components : %v : instead %v", + components, cluster.Config.SoftwareConfig.OptionalComponents) + } + return nil + } } func testAccCheckDataprocClusterInitActionSucceeded(bucket, object string) resource.TestCheckFunc { @@ -1039,6 +1070,20 @@ resource "google_dataproc_cluster" "with_image_version" { }`, rnd) } +func testAccDataprocCluster_withOptionalComponents(rnd string) string { + return fmt.Sprintf(` +resource "google_dataproc_cluster" "with_opt_components" { + name = "dproc-cluster-test-%s" + region = "us-central1" + + cluster_config { + software_config { + optional_components = ["ANACONDA", "ZOOKEEPER"] + } + } +}`, rnd) +} + func testAccDataprocCluster_withServiceAcc(sa string, rnd string) string { return fmt.Sprintf(` resource "google_service_account" "service_account" {