Skip to content

Commit

Permalink
Add dataproc component gateway (#2526)
Browse files Browse the repository at this point in the history
  • Loading branch information
c2thorn authored May 5, 2020
1 parent b9d7def commit 0a74770
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
47 changes: 47 additions & 0 deletions third_party/terraform/resources/resource_dataproc_cluster.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
"cluster_config.0.autoscaling_config",
<% unless version == 'ga' -%>
"cluster_config.0.lifecycle_config",
"cluster_config.0.endpoint_config",
<% end -%>
}
)
Expand Down Expand Up @@ -547,6 +548,26 @@ by Dataproc`,
},
},
},
"endpoint_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
AtLeastOneOf: clusterConfigKeys,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enable_http_port_access": {
Type: schema.TypeBool,
Required: true,
ForceNew: true,
},
"http_ports": {
Type: schema.TypeMap,
Computed: true,
},
},
},
},
<% end -%>
},
},
Expand Down Expand Up @@ -791,6 +812,10 @@ func expandClusterConfig(d *schema.ResourceData, config *Config) (*dataproc.Clus
if cfg, ok := configOptions(d, "cluster_config.0.lifecycle_config"); ok {
conf.LifecycleConfig = expandLifecycleConfig(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 @@ -973,6 +998,14 @@ func expandLifecycleConfig(cfg map[string]interface{}) *dataproc.LifecycleConfig
}
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 @@ -1214,6 +1247,7 @@ func flattenClusterConfig(d *schema.ResourceData, cfg *dataproc.ClusterConfig) (
"autoscaling_config": flattenAutoscalingConfig(d, cfg.AutoscalingConfig),
<% unless version == 'ga' -%>
"lifecycle_config": flattenLifecycleConfig(d, cfg.LifecycleConfig),
"endpoint_config": flattenEndpointConfig(d, cfg.EndpointConfig),
<% end -%>
}

Expand Down Expand Up @@ -1308,6 +1342,19 @@ func flattenLifecycleConfig(d *schema.ResourceData, lc *dataproc.LifecycleConfig

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,
"http_ports": ec.HttpPorts,
}

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

func flattenAccelerators(accelerators []*dataproc.AcceleratorConfig) interface{} {
Expand Down
40 changes: 40 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 @@ -650,6 +650,29 @@ 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)
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDataprocClusterDestroy(t),
Steps: []resource.TestStep{
{
Config: testAccDataprocCluster_withEndpointConfig(rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataprocClusterExists(t, "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 @@ -1240,6 +1263,23 @@ 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 = "tf-test-%s"
region = "us-central1"

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 @@ -146,6 +146,7 @@ The `cluster_config` block supports:
# You can define multiple initialization_action blocks
initialization_action { ... }
encryption_config { ... }
endpoint_config { ... }
}
```

Expand Down Expand Up @@ -186,6 +187,8 @@ The `cluster_config` block supports:
* `lifecycle_config` (Optional, Beta) The settings for auto deletion cluster schedule.
Structure defined below.

* `endpoint_config` (Optional, Beta) The config settings for port access on the cluster.
Structure defined below.
- - -

The `cluster_config.gce_cluster_config` block supports:
Expand Down Expand Up @@ -583,6 +586,21 @@ cluster_config {
A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds.
Example: "2014-10-02T15:01:23.045123456Z".

- - -

The `endpoint_config` block (Optional, Computed, Beta) 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 All @@ -607,6 +625,9 @@ exported:
* `cluster_config.0.lifecycle_config.0.idle_start_time` - Time when the cluster became idle
(most recent job finished) and became eligible for deletion due to idleness.

* `cluster_config.0.endpoint_config.0.http_ports` - The map of port descriptions to URLs. Will only be populated if
`enable_http_port_access` is true.

## Timeouts

This resource provides the following
Expand Down

0 comments on commit 0a74770

Please sign in to comment.