Skip to content

Commit

Permalink
Add dataproc component gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
c2thorn committed Oct 23, 2019
1 parent bcc9801 commit 4866290
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
39 changes: 39 additions & 0 deletions third_party/terraform/resources/resource_dataproc_cluster.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,20 @@ func resourceDataprocCluster() *schema.Resource {
},
},
},
"endpoint_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enable_http_port_access": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
<% end -%>
},
},
Expand Down Expand Up @@ -562,6 +576,10 @@ func expandClusterConfig(d *schema.ResourceData, config *Config) (*dataproc.Clus
if cfg, ok := configOptions(d, "cluster_config.0.autoscaling_config"); ok {
conf.AutoscalingConfig = expandAutoscalingConfig(cfg)
}

if cfg, ok := configOptions(d, "cluster_config.0.endpoint_config"); ok {
conf.EndpointConfig = expandEndpointConfig(cfg)
}
<% end -%>

if cfg, ok := configOptions(d, "cluster_config.0.master_config"); ok {
Expand Down Expand Up @@ -674,6 +692,14 @@ func expandAutoscalingConfig(cfg map[string]interface{}) *dataproc.AutoscalingCo
}
return conf
}

func expandEndpointConfig(cfg map[string]interface{}) *dataproc.EndpointConfig {
conf := &dataproc.EndpointConfig{}
if v, ok := cfg["enable_http_port_access"]; ok {
conf.EnableHttpPortAccess = v.(bool)
}
return conf
}
<% end -%>

func expandInitializationActions(v interface{}) []*dataproc.NodeInitializationAction {
Expand Down Expand Up @@ -892,6 +918,7 @@ func flattenClusterConfig(d *schema.ResourceData, cfg *dataproc.ClusterConfig) (
"encryption_config": flattenEncryptionConfig(d, cfg.EncryptionConfig),
<% unless version == 'ga' -%>
"autoscaling_config": flattenAutoscalingConfig(d, cfg.AutoscalingConfig),
"endpoint_config": flattenEndpointConfig(d, cfg.EndpointConfig),
<% end -%>
}

Expand Down Expand Up @@ -940,6 +967,18 @@ func flattenAutoscalingConfig(d *schema.ResourceData, ec *dataproc.AutoscalingCo

return []map[string]interface{}{data}
}

func flattenEndpointConfig(d *schema.ResourceData, ec *dataproc.EndpointConfig) []map[string]interface{} {
if ec == nil {
return nil
}

data := map[string]interface{}{
"enable_http_port_access": ec.EnableHttpPortAccess,
}

return []map[string]interface{}{data}
}
<% end -%>

func flattenAccelerators(accelerators []*dataproc.AcceleratorConfig) interface{} {
Expand Down
41 changes: 41 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 @@ -582,6 +582,28 @@ func TestAccDataprocCluster_withNetworkRefs(t *testing.T) {
})
}

<% unless version == 'ga' -%>
func TestAccDataprocCluster_withEndpointConfig(t *testing.T) {
t.Parallel()

var cluster dataproc.Cluster
rnd := acctest.RandString(10)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataprocCluster_withEndpointConfig(rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataprocClusterExists("google_dataproc_cluster.with_endpoint_config", &cluster),
resource.TestCheckResourceAttr("google_dataproc_cluster.with_endpoint_config", "cluster_config.0.endpoint_config.0.enable_http_port_access", "true"),
),
},
},
})
}
<% end -%>

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

Expand Down Expand Up @@ -1148,6 +1170,25 @@ resource "google_dataproc_cluster" "with_labels" {
}`, rnd)
}

<% unless version == 'ga' -%>
func testAccDataprocCluster_withEndpointConfig(rnd string) string {
return fmt.Sprintf(`
resource "google_dataproc_cluster" "with_endpoint_config" {
name = "dproc-cluster-test-%s"
region = "us-central1"

cluster_config {
gce_cluster_config {}

endpoint_config {
enable_http_port_access = "true"
}
}
}
`, rnd)
}
<% end -%>

func testAccDataprocCluster_withImageVersion(rnd string) string {
return fmt.Sprintf(`
resource "google_dataproc_cluster" "with_image_version" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ The `cluster_config` block supports:
# You can define multiple initialization_action blocks
initialization_action { ... }
encryption_config { ... }
endpoint_config { ... }
}
```

Expand Down Expand Up @@ -183,6 +184,9 @@ The `cluster_config` block supports:

* `encryption_config` (Optional) The Customer managed encryption keys settings for the cluster.
Structure defined below.

* `endpoint_config` (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) The config settings for port access on the cluster.
Structure defined below.
- - -

The `cluster_config.gce_cluster_config` block supports:
Expand Down Expand Up @@ -462,6 +466,20 @@ The `encryption_config` block supports:
* `kms_key_name` - (Required) The Cloud KMS key name to use for PD disk encryption for
all instances in the cluster.

- - -

The `endpoint_config` block (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) supports:

```hcl
cluster_config {
endpoint_config {
enable_http_port_access = "true"
}
}
```

* `enable_http_port_access` - (Optional) The flag to enable http access to specific ports on the cluster from external sources (aka Component Gateway). Defaults to false.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are
Expand Down

0 comments on commit 4866290

Please sign in to comment.