Skip to content

Commit

Permalink
add optional components to dataproc_cluster (GoogleCloudPlatform#2079)
Browse files Browse the repository at this point in the history
  • Loading branch information
megan07 authored and modular-magician committed Jul 29, 2019
1 parent 83b9fd5 commit bb4c89a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
19 changes: 19 additions & 0 deletions third_party/terraform/resources/resource_dataproc_cluster.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,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),
},
},
},
},
},
Expand Down Expand Up @@ -616,6 +626,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
}

Expand Down Expand Up @@ -856,6 +874,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{}),
}
Expand Down
45 changes: 45 additions & 0 deletions third_party/terraform/tests/resource_dataproc_cluster_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,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()

Expand Down Expand Up @@ -660,7 +681,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 {
Expand Down Expand Up @@ -1131,6 +1162,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" {
Expand Down

0 comments on commit bb4c89a

Please sign in to comment.