Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional components to dataproc_cluster #4073

Merged
merged 1 commit into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions google/resource_dataproc_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
},
},
},
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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{}),
}
Expand Down
45 changes: 45 additions & 0 deletions google/resource_dataproc_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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" {
Expand Down