Skip to content

Commit df33af9

Browse files
Add dataproc component gateway (#2526) (#2035)
Signed-off-by: Modular Magician <[email protected]>
1 parent 190ced4 commit df33af9

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

.changelog/2526.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
[beta-only]dataproc: added component gateway support to `google_dataproc_cluster`
3+
```

google-beta/resource_dataproc_cluster.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var (
5353
"cluster_config.0.encryption_config",
5454
"cluster_config.0.autoscaling_config",
5555
"cluster_config.0.lifecycle_config",
56+
"cluster_config.0.endpoint_config",
5657
}
5758
)
5859

@@ -543,6 +544,26 @@ by Dataproc`,
543544
},
544545
},
545546
},
547+
"endpoint_config": {
548+
Type: schema.TypeList,
549+
Optional: true,
550+
Computed: true,
551+
MaxItems: 1,
552+
AtLeastOneOf: clusterConfigKeys,
553+
Elem: &schema.Resource{
554+
Schema: map[string]*schema.Schema{
555+
"enable_http_port_access": {
556+
Type: schema.TypeBool,
557+
Required: true,
558+
ForceNew: true,
559+
},
560+
"http_ports": {
561+
Type: schema.TypeMap,
562+
Computed: true,
563+
},
564+
},
565+
},
566+
},
546567
},
547568
},
548569
},
@@ -786,6 +807,10 @@ func expandClusterConfig(d *schema.ResourceData, config *Config) (*dataproc.Clus
786807
conf.LifecycleConfig = expandLifecycleConfig(cfg)
787808
}
788809

810+
if cfg, ok := configOptions(d, "cluster_config.0.endpoint_config"); ok {
811+
conf.EndpointConfig = expandEndpointConfig(cfg)
812+
}
813+
789814
if cfg, ok := configOptions(d, "cluster_config.0.master_config"); ok {
790815
log.Println("[INFO] got master_config")
791816
conf.MasterConfig = expandInstanceGroupConfig(cfg)
@@ -966,6 +991,14 @@ func expandLifecycleConfig(cfg map[string]interface{}) *dataproc.LifecycleConfig
966991
return conf
967992
}
968993

994+
func expandEndpointConfig(cfg map[string]interface{}) *dataproc.EndpointConfig {
995+
conf := &dataproc.EndpointConfig{}
996+
if v, ok := cfg["enable_http_port_access"]; ok {
997+
conf.EnableHttpPortAccess = v.(bool)
998+
}
999+
return conf
1000+
}
1001+
9691002
func expandInitializationActions(v interface{}) []*dataproc.NodeInitializationAction {
9701003
actionList := v.([]interface{})
9711004

@@ -1202,6 +1235,7 @@ func flattenClusterConfig(d *schema.ResourceData, cfg *dataproc.ClusterConfig) (
12021235
"encryption_config": flattenEncryptionConfig(d, cfg.EncryptionConfig),
12031236
"autoscaling_config": flattenAutoscalingConfig(d, cfg.AutoscalingConfig),
12041237
"lifecycle_config": flattenLifecycleConfig(d, cfg.LifecycleConfig),
1238+
"endpoint_config": flattenEndpointConfig(d, cfg.EndpointConfig),
12051239
}
12061240

12071241
if len(cfg.InitializationActions) > 0 {
@@ -1295,6 +1329,19 @@ func flattenLifecycleConfig(d *schema.ResourceData, lc *dataproc.LifecycleConfig
12951329
return []map[string]interface{}{data}
12961330
}
12971331

1332+
func flattenEndpointConfig(d *schema.ResourceData, ec *dataproc.EndpointConfig) []map[string]interface{} {
1333+
if ec == nil {
1334+
return nil
1335+
}
1336+
1337+
data := map[string]interface{}{
1338+
"enable_http_port_access": ec.EnableHttpPortAccess,
1339+
"http_ports": ec.HttpPorts,
1340+
}
1341+
1342+
return []map[string]interface{}{data}
1343+
}
1344+
12981345
func flattenAccelerators(accelerators []*dataproc.AcceleratorConfig) interface{} {
12991346
acceleratorsTypeSet := schema.NewSet(schema.HashResource(acceleratorsSchema()), []interface{}{})
13001347
for _, accelerator := range accelerators {

google-beta/resource_dataproc_cluster_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13+
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
1314
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
1415
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1516

@@ -648,6 +649,27 @@ func TestAccDataprocCluster_withNetworkRefs(t *testing.T) {
648649
})
649650
}
650651

652+
func TestAccDataprocCluster_withEndpointConfig(t *testing.T) {
653+
t.Parallel()
654+
655+
var cluster dataproc.Cluster
656+
rnd := acctest.RandString(10)
657+
vcrTest(t, resource.TestCase{
658+
PreCheck: func() { testAccPreCheck(t) },
659+
Providers: testAccProviders,
660+
CheckDestroy: testAccCheckDataprocClusterDestroy(t),
661+
Steps: []resource.TestStep{
662+
{
663+
Config: testAccDataprocCluster_withEndpointConfig(rnd),
664+
Check: resource.ComposeTestCheckFunc(
665+
testAccCheckDataprocClusterExists(t, "google_dataproc_cluster.with_endpoint_config", &cluster),
666+
resource.TestCheckResourceAttr("google_dataproc_cluster.with_endpoint_config", "cluster_config.0.endpoint_config.0.enable_http_port_access", "true"),
667+
),
668+
},
669+
},
670+
})
671+
}
672+
651673
func TestAccDataprocCluster_KMS(t *testing.T) {
652674
t.Parallel()
653675

@@ -1238,6 +1260,21 @@ resource "google_dataproc_cluster" "with_labels" {
12381260
`, rnd)
12391261
}
12401262

1263+
func testAccDataprocCluster_withEndpointConfig(rnd string) string {
1264+
return fmt.Sprintf(`
1265+
resource "google_dataproc_cluster" "with_endpoint_config" {
1266+
name = "tf-test-%s"
1267+
region = "us-central1"
1268+
1269+
cluster_config {
1270+
endpoint_config {
1271+
enable_http_port_access = "true"
1272+
}
1273+
}
1274+
}
1275+
`, rnd)
1276+
}
1277+
12411278
func testAccDataprocCluster_withImageVersion(rnd string) string {
12421279
return fmt.Sprintf(`
12431280
resource "google_dataproc_cluster" "with_image_version" {

website/docs/r/dataproc_cluster.html.markdown

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ The `cluster_config` block supports:
146146
# You can define multiple initialization_action blocks
147147
initialization_action { ... }
148148
encryption_config { ... }
149+
endpoint_config { ... }
149150
}
150151
```
151152

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

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

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

589+
- - -
590+
591+
The `endpoint_config` block (Optional, Computed, Beta) supports:
592+
593+
```hcl
594+
cluster_config {
595+
endpoint_config {
596+
enable_http_port_access = "true"
597+
}
598+
}
599+
```
600+
601+
* `enable_http_port_access` - (Optional) The flag to enable http access to specific ports
602+
on the cluster from external sources (aka Component Gateway). Defaults to false.
603+
586604
## Attributes Reference
587605

588606
In addition to the arguments listed above, the following computed attributes are
@@ -607,6 +625,9 @@ exported:
607625
* `cluster_config.0.lifecycle_config.0.idle_start_time` - Time when the cluster became idle
608626
(most recent job finished) and became eligible for deletion due to idleness.
609627

628+
* `cluster_config.0.endpoint_config.0.http_ports` - The map of port descriptions to URLs. Will only be populated if
629+
`enable_http_port_access` is true.
630+
610631
## Timeouts
611632

612633
This resource provides the following

0 commit comments

Comments
 (0)