Skip to content

Commit 2ae4cf2

Browse files
Added field network_config to resource google_dataproc_metastore_service (#6893) (#13184)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 785235c commit 2ae4cf2

File tree

4 files changed

+255
-0
lines changed

4 files changed

+255
-0
lines changed

.changelog/6893.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
metastore: added general field `network_config` to `google_dataproc_metastore_service`
3+
```

google/resource_dataproc_metastore_service.go

+139
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,40 @@ Maintenance window is not needed for services with the 'SPANNER' database type.`
184184
185185
"projects/{projectNumber}/global/networks/{network_id}".`,
186186
},
187+
"network_config": {
188+
Type: schema.TypeList,
189+
Optional: true,
190+
ForceNew: true,
191+
Description: `The configuration specifying the network settings for the Dataproc Metastore service.`,
192+
MaxItems: 1,
193+
Elem: &schema.Resource{
194+
Schema: map[string]*schema.Schema{
195+
"consumers": {
196+
Type: schema.TypeList,
197+
Required: true,
198+
ForceNew: true,
199+
Description: `The consumer-side network configuration for the Dataproc Metastore instance.`,
200+
Elem: &schema.Resource{
201+
Schema: map[string]*schema.Schema{
202+
"subnetwork": {
203+
Type: schema.TypeString,
204+
Required: true,
205+
Description: `The subnetwork of the customer project from which an IP address is reserved and used as the Dataproc Metastore service's endpoint.
206+
It is accessible to hosts in the subnet and to all hosts in a subnet in the same region and same network.
207+
There must be at least one IP address available in the subnet's primary range. The subnet is specified in the following form:
208+
'projects/{projectNumber}/regions/{region_id}/subnetworks/{subnetwork_id}`,
209+
},
210+
"endpoint_uri": {
211+
Type: schema.TypeString,
212+
Computed: true,
213+
Description: `The URI of the endpoint used to access the metastore service.`,
214+
},
215+
},
216+
},
217+
},
218+
},
219+
},
220+
},
187221
"port": {
188222
Type: schema.TypeInt,
189223
Computed: true,
@@ -296,6 +330,12 @@ func resourceDataprocMetastoreServiceCreate(d *schema.ResourceData, meta interfa
296330
} else if v, ok := d.GetOkExists("hive_metastore_config"); !isEmptyValue(reflect.ValueOf(hiveMetastoreConfigProp)) && (ok || !reflect.DeepEqual(v, hiveMetastoreConfigProp)) {
297331
obj["hiveMetastoreConfig"] = hiveMetastoreConfigProp
298332
}
333+
networkConfigProp, err := expandDataprocMetastoreServiceNetworkConfig(d.Get("network_config"), d, config)
334+
if err != nil {
335+
return err
336+
} else if v, ok := d.GetOkExists("network_config"); !isEmptyValue(reflect.ValueOf(networkConfigProp)) && (ok || !reflect.DeepEqual(v, networkConfigProp)) {
337+
obj["networkConfig"] = networkConfigProp
338+
}
299339
databaseTypeProp, err := expandDataprocMetastoreServiceDatabaseType(d.Get("database_type"), d, config)
300340
if err != nil {
301341
return err
@@ -425,6 +465,9 @@ func resourceDataprocMetastoreServiceRead(d *schema.ResourceData, meta interface
425465
if err := d.Set("hive_metastore_config", flattenDataprocMetastoreServiceHiveMetastoreConfig(res["hiveMetastoreConfig"], d, config)); err != nil {
426466
return fmt.Errorf("Error reading Service: %s", err)
427467
}
468+
if err := d.Set("network_config", flattenDataprocMetastoreServiceNetworkConfig(res["networkConfig"], d, config)); err != nil {
469+
return fmt.Errorf("Error reading Service: %s", err)
470+
}
428471
if err := d.Set("database_type", flattenDataprocMetastoreServiceDatabaseType(res["databaseType"], d, config)); err != nil {
429472
return fmt.Errorf("Error reading Service: %s", err)
430473
}
@@ -787,6 +830,46 @@ func flattenDataprocMetastoreServiceHiveMetastoreConfigKerberosConfigKrb5ConfigG
787830
return v
788831
}
789832

833+
func flattenDataprocMetastoreServiceNetworkConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
834+
if v == nil {
835+
return nil
836+
}
837+
original := v.(map[string]interface{})
838+
if len(original) == 0 {
839+
return nil
840+
}
841+
transformed := make(map[string]interface{})
842+
transformed["consumers"] =
843+
flattenDataprocMetastoreServiceNetworkConfigConsumers(original["consumers"], d, config)
844+
return []interface{}{transformed}
845+
}
846+
func flattenDataprocMetastoreServiceNetworkConfigConsumers(v interface{}, d *schema.ResourceData, config *Config) interface{} {
847+
if v == nil {
848+
return v
849+
}
850+
l := v.([]interface{})
851+
transformed := make([]interface{}, 0, len(l))
852+
for _, raw := range l {
853+
original := raw.(map[string]interface{})
854+
if len(original) < 1 {
855+
// Do not include empty json objects coming back from the api
856+
continue
857+
}
858+
transformed = append(transformed, map[string]interface{}{
859+
"endpoint_uri": flattenDataprocMetastoreServiceNetworkConfigConsumersEndpointUri(original["endpointUri"], d, config),
860+
"subnetwork": flattenDataprocMetastoreServiceNetworkConfigConsumersSubnetwork(original["subnetwork"], d, config),
861+
})
862+
}
863+
return transformed
864+
}
865+
func flattenDataprocMetastoreServiceNetworkConfigConsumersEndpointUri(v interface{}, d *schema.ResourceData, config *Config) interface{} {
866+
return v
867+
}
868+
869+
func flattenDataprocMetastoreServiceNetworkConfigConsumersSubnetwork(v interface{}, d *schema.ResourceData, config *Config) interface{} {
870+
return v
871+
}
872+
790873
func flattenDataprocMetastoreServiceDatabaseType(v interface{}, d *schema.ResourceData, config *Config) interface{} {
791874
return v
792875
}
@@ -991,6 +1074,62 @@ func expandDataprocMetastoreServiceHiveMetastoreConfigKerberosConfigKrb5ConfigGc
9911074
return v, nil
9921075
}
9931076

1077+
func expandDataprocMetastoreServiceNetworkConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1078+
l := v.([]interface{})
1079+
if len(l) == 0 || l[0] == nil {
1080+
return nil, nil
1081+
}
1082+
raw := l[0]
1083+
original := raw.(map[string]interface{})
1084+
transformed := make(map[string]interface{})
1085+
1086+
transformedConsumers, err := expandDataprocMetastoreServiceNetworkConfigConsumers(original["consumers"], d, config)
1087+
if err != nil {
1088+
return nil, err
1089+
} else if val := reflect.ValueOf(transformedConsumers); val.IsValid() && !isEmptyValue(val) {
1090+
transformed["consumers"] = transformedConsumers
1091+
}
1092+
1093+
return transformed, nil
1094+
}
1095+
1096+
func expandDataprocMetastoreServiceNetworkConfigConsumers(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1097+
l := v.([]interface{})
1098+
req := make([]interface{}, 0, len(l))
1099+
for _, raw := range l {
1100+
if raw == nil {
1101+
continue
1102+
}
1103+
original := raw.(map[string]interface{})
1104+
transformed := make(map[string]interface{})
1105+
1106+
transformedEndpointUri, err := expandDataprocMetastoreServiceNetworkConfigConsumersEndpointUri(original["endpoint_uri"], d, config)
1107+
if err != nil {
1108+
return nil, err
1109+
} else if val := reflect.ValueOf(transformedEndpointUri); val.IsValid() && !isEmptyValue(val) {
1110+
transformed["endpointUri"] = transformedEndpointUri
1111+
}
1112+
1113+
transformedSubnetwork, err := expandDataprocMetastoreServiceNetworkConfigConsumersSubnetwork(original["subnetwork"], d, config)
1114+
if err != nil {
1115+
return nil, err
1116+
} else if val := reflect.ValueOf(transformedSubnetwork); val.IsValid() && !isEmptyValue(val) {
1117+
transformed["subnetwork"] = transformedSubnetwork
1118+
}
1119+
1120+
req = append(req, transformed)
1121+
}
1122+
return req, nil
1123+
}
1124+
1125+
func expandDataprocMetastoreServiceNetworkConfigConsumersEndpointUri(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1126+
return v, nil
1127+
}
1128+
1129+
func expandDataprocMetastoreServiceNetworkConfigConsumersSubnetwork(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1130+
return v, nil
1131+
}
1132+
9941133
func expandDataprocMetastoreServiceDatabaseType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
9951134
return v, nil
9961135
}

google/resource_dataproc_metastore_service_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,54 @@ resource "google_dataproc_metastore_service" "my_metastore" {
5151
}
5252
`, name, tier)
5353
}
54+
55+
func TestAccDataprocMetastoreService_PrivateServiceConnect(t *testing.T) {
56+
t.Parallel()
57+
58+
context := map[string]interface{}{
59+
"random_suffix": randString(t, 10),
60+
}
61+
62+
vcrTest(t, resource.TestCase{
63+
PreCheck: func() { testAccPreCheck(t) },
64+
Providers: testAccProviders,
65+
CheckDestroy: testAccCheckDataprocMetastoreServiceDestroyProducer(t),
66+
Steps: []resource.TestStep{
67+
{
68+
Config: testAccDataprocMetastoreService_PrivateServiceConnect(context),
69+
},
70+
{
71+
ResourceName: "google_dataproc_metastore_service.default",
72+
ImportState: true,
73+
ImportStateVerify: true,
74+
ImportStateVerifyIgnore: []string{"service_id", "location"},
75+
},
76+
},
77+
})
78+
}
79+
80+
func testAccDataprocMetastoreService_PrivateServiceConnect(context map[string]interface{}) string {
81+
return Nprintf(`
82+
// Use data source instead of creating a subnetwork due to a bug on API side.
83+
// With the bug, the new created subnetwork cannot be deleted when deleting the dataproc metastore service.
84+
data "google_compute_subnetwork" "subnet" {
85+
name = "default"
86+
region = "us-central1"
87+
}
88+
89+
resource "google_dataproc_metastore_service" "default" {
90+
service_id = "tf-test-metastore-srv%{random_suffix}"
91+
location = "us-central1"
92+
93+
hive_metastore_config {
94+
version = "3.1.2"
95+
}
96+
97+
network_config {
98+
consumers {
99+
subnetwork = data.google_compute_subnetwork.subnet.id
100+
}
101+
}
102+
}
103+
`, context)
104+
}

website/docs/r/dataproc_metastore_service.html.markdown

+62
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ description: |-
2323
A managed metastore service that serves metadata queries.
2424

2525

26+
To get more information about Service, see:
27+
28+
* [API documentation](https://cloud.google.com/dataproc-metastore/docs/reference/rest/v1/projects.locations.services)
29+
* How-to Guides
30+
* [Official Documentation](https://cloud.google.com/dataproc-metastore/docs/overview)
2631

2732
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
2833
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=dataproc_metastore_service_basic&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
@@ -80,6 +85,38 @@ resource "google_kms_key_ring" "key_ring" {
8085
location = "us-central1"
8186
}
8287
```
88+
## Example Usage - Dataproc Metastore Service Private Service Connect
89+
90+
91+
```hcl
92+
resource "google_compute_network" "net" {
93+
name = "my-network"
94+
auto_create_subnetworks = false
95+
}
96+
97+
resource "google_compute_subnetwork" "subnet" {
98+
name = "my-subnetwork"
99+
region = "us-central1"
100+
network = google_compute_network.net.id
101+
ip_cidr_range = "10.0.0.0/22"
102+
private_ip_google_access = true
103+
}
104+
105+
resource "google_dataproc_metastore_service" "default" {
106+
service_id = "metastore-srv"
107+
location = "us-central1"
108+
109+
hive_metastore_config {
110+
version = "3.1.2"
111+
}
112+
113+
network_config {
114+
consumers {
115+
subnetwork = google_compute_subnetwork.subnet.id
116+
}
117+
}
118+
}
119+
```
83120

84121
## Argument Reference
85122

@@ -132,6 +169,11 @@ The following arguments are supported:
132169
Configuration information specific to running Hive metastore software as the metastore service.
133170
Structure is [documented below](#nested_hive_metastore_config).
134171

172+
* `network_config` -
173+
(Optional)
174+
The configuration specifying the network settings for the Dataproc Metastore service.
175+
Structure is [documented below](#nested_network_config).
176+
135177
* `database_type` -
136178
(Optional)
137179
The database type that the Metastore service stores its data.
@@ -244,6 +286,26 @@ The following arguments are supported:
244286
A mapping of Hive metastore configuration key-value pairs to apply to the auxiliary Hive metastore (configured in hive-site.xml) in addition to the primary version's overrides.
245287
If keys are present in both the auxiliary version's overrides and the primary version's overrides, the value from the auxiliary version's overrides takes precedence.
246288

289+
<a name="nested_network_config"></a>The `network_config` block supports:
290+
291+
* `consumers` -
292+
(Required)
293+
The consumer-side network configuration for the Dataproc Metastore instance.
294+
Structure is [documented below](#nested_consumers).
295+
296+
297+
<a name="nested_consumers"></a>The `consumers` block supports:
298+
299+
* `endpoint_uri` -
300+
The URI of the endpoint used to access the metastore service.
301+
302+
* `subnetwork` -
303+
(Required)
304+
The subnetwork of the customer project from which an IP address is reserved and used as the Dataproc Metastore service's endpoint.
305+
It is accessible to hosts in the subnet and to all hosts in a subnet in the same region and same network.
306+
There must be at least one IP address available in the subnet's primary range. The subnet is specified in the following form:
307+
`projects/{projectNumber}/regions/{region_id}/subnetworks/{subnetwork_id}
308+
247309
<a name="nested_metadata_integration"></a>The `metadata_integration` block supports:
248310

249311
* `data_catalog_config` -

0 commit comments

Comments
 (0)