Skip to content

Commit f40a469

Browse files
Add support for "connection_properties" for bigquery job resource (#14797) (#10554)
[upstream:d6a1df847d320ce3dfc03e2e86535c30150fe331] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent 4b316f8 commit f40a469

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

.changelog/14797.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigquery: added support for "connection_properties" for bigquery to `google_bigquery_job` (beta)
3+
```

google-beta/services/bigquery/resource_bigquery_job.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,35 @@ Creation, truncation and append actions occur as one atomic update upon job comp
666666
Requires destinationTable to be set. For standard SQL queries, this flag is ignored and large results are always allowed.
667667
However, you must still set destinationTable when result size exceeds the allowed maximum response size.`,
668668
},
669+
"connection_properties": {
670+
Type: schema.TypeList,
671+
Optional: true,
672+
ForceNew: true,
673+
Description: `Connection properties to customize query behavior. Under JDBC, these correspond
674+
directly to connection properties passed to the DriverManager. Under ODBC, these
675+
correspond to properties in the connection string.`,
676+
Elem: &schema.Resource{
677+
Schema: map[string]*schema.Schema{
678+
"key": {
679+
Type: schema.TypeString,
680+
Required: true,
681+
ForceNew: true,
682+
Description: `The key of the property to set. Currently supported connection properties:
683+
* 'dataset_project_id': represents the default project for datasets that are used in the query
684+
* 'time_zone': represents the default timezone used to run the query
685+
* 'session_id': associates the query with a given session
686+
* 'query_label': associates the query with a given job label
687+
* 'service_account': indicates the service account to use to run a continuous query`,
688+
},
689+
"value": {
690+
Type: schema.TypeString,
691+
Required: true,
692+
ForceNew: true,
693+
Description: `The value of the property to set.`,
694+
},
695+
},
696+
},
697+
},
669698
"continuous": {
670699
Type: schema.TypeBool,
671700
Optional: true,
@@ -1361,6 +1390,8 @@ func flattenBigQueryJobConfigurationQuery(v interface{}, d *schema.ResourceData,
13611390
flattenBigQueryJobConfigurationQueryScriptOptions(original["scriptOptions"], d, config)
13621391
transformed["continuous"] =
13631392
flattenBigQueryJobConfigurationQueryContinuous(original["continuous"], d, config)
1393+
transformed["connection_properties"] =
1394+
flattenBigQueryJobConfigurationQueryConnectionProperties(original["connectionProperties"], d, config)
13641395
return []interface{}{transformed}
13651396
}
13661397
func flattenBigQueryJobConfigurationQueryQuery(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -1548,6 +1579,33 @@ func flattenBigQueryJobConfigurationQueryContinuous(v interface{}, d *schema.Res
15481579
return v
15491580
}
15501581

1582+
func flattenBigQueryJobConfigurationQueryConnectionProperties(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1583+
if v == nil {
1584+
return v
1585+
}
1586+
l := v.([]interface{})
1587+
transformed := make([]interface{}, 0, len(l))
1588+
for _, raw := range l {
1589+
original := raw.(map[string]interface{})
1590+
if len(original) < 1 {
1591+
// Do not include empty json objects coming back from the api
1592+
continue
1593+
}
1594+
transformed = append(transformed, map[string]interface{}{
1595+
"key": flattenBigQueryJobConfigurationQueryConnectionPropertiesKey(original["key"], d, config),
1596+
"value": flattenBigQueryJobConfigurationQueryConnectionPropertiesValue(original["value"], d, config),
1597+
})
1598+
}
1599+
return transformed
1600+
}
1601+
func flattenBigQueryJobConfigurationQueryConnectionPropertiesKey(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1602+
return v
1603+
}
1604+
1605+
func flattenBigQueryJobConfigurationQueryConnectionPropertiesValue(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1606+
return v
1607+
}
1608+
15511609
func flattenBigQueryJobConfigurationLoad(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
15521610
if v == nil {
15531611
return nil
@@ -2315,6 +2373,13 @@ func expandBigQueryJobConfigurationQuery(v interface{}, d tpgresource.TerraformR
23152373
transformed["continuous"] = transformedContinuous
23162374
}
23172375

2376+
transformedConnectionProperties, err := expandBigQueryJobConfigurationQueryConnectionProperties(original["connection_properties"], d, config)
2377+
if err != nil {
2378+
return nil, err
2379+
} else if val := reflect.ValueOf(transformedConnectionProperties); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2380+
transformed["connectionProperties"] = transformedConnectionProperties
2381+
}
2382+
23182383
return transformed, nil
23192384
}
23202385

@@ -2560,6 +2625,43 @@ func expandBigQueryJobConfigurationQueryContinuous(v interface{}, d tpgresource.
25602625
return v, nil
25612626
}
25622627

2628+
func expandBigQueryJobConfigurationQueryConnectionProperties(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2629+
l := v.([]interface{})
2630+
req := make([]interface{}, 0, len(l))
2631+
for _, raw := range l {
2632+
if raw == nil {
2633+
continue
2634+
}
2635+
original := raw.(map[string]interface{})
2636+
transformed := make(map[string]interface{})
2637+
2638+
transformedKey, err := expandBigQueryJobConfigurationQueryConnectionPropertiesKey(original["key"], d, config)
2639+
if err != nil {
2640+
return nil, err
2641+
} else if val := reflect.ValueOf(transformedKey); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2642+
transformed["key"] = transformedKey
2643+
}
2644+
2645+
transformedValue, err := expandBigQueryJobConfigurationQueryConnectionPropertiesValue(original["value"], d, config)
2646+
if err != nil {
2647+
return nil, err
2648+
} else if val := reflect.ValueOf(transformedValue); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2649+
transformed["value"] = transformedValue
2650+
}
2651+
2652+
req = append(req, transformed)
2653+
}
2654+
return req, nil
2655+
}
2656+
2657+
func expandBigQueryJobConfigurationQueryConnectionPropertiesKey(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2658+
return v, nil
2659+
}
2660+
2661+
func expandBigQueryJobConfigurationQueryConnectionPropertiesValue(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2662+
return v, nil
2663+
}
2664+
25632665
func expandBigQueryJobConfigurationLoad(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
25642666
l := v.([]interface{})
25652667
if len(l) == 0 || l[0] == nil {

google-beta/services/bigquery/resource_bigquery_job_generated_meta.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ fields:
117117
api_field: 'job_reference.location'
118118
- field: 'query.allow_large_results'
119119
api_field: 'configuration.query.allow_large_results'
120+
- field: 'query.connection_properties.key'
121+
api_field: 'configuration.query.connection_properties.key'
122+
- field: 'query.connection_properties.value'
123+
api_field: 'configuration.query.connection_properties.value'
120124
- field: 'query.continuous'
121125
api_field: 'configuration.query.continuous'
122126
- field: 'query.create_disposition'

google-beta/services/bigquery/resource_bigquery_job_generated_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ resource "google_bigquery_job" "job" {
126126
query {
127127
query = "SELECT state FROM [lookerdata:cdc.project_tycho_reports]"
128128
continuous = true
129+
130+
connection_properties {
131+
key = "service_account"
132+
value = "bq-runner@project-query-continuous.iam.gserviceaccount.com"
133+
}
129134
}
130135
}
131136
`, context)

website/docs/r/bigquery_job.html.markdown

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,13 @@ The following arguments are supported:
654654
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
655655
Whether to run the query as continuous or a regular query.
656656

657+
* `connection_properties` -
658+
(Optional)
659+
Connection properties to customize query behavior. Under JDBC, these correspond
660+
directly to connection properties passed to the DriverManager. Under ODBC, these
661+
correspond to properties in the connection string.
662+
Structure is [documented below](#nested_configuration_query_connection_properties).
663+
657664

658665
<a name="nested_configuration_query_destination_table"></a>The `destination_table` block supports:
659666

@@ -719,6 +726,21 @@ The following arguments are supported:
719726
used to populate the schema and query results of the script job.
720727
Possible values are: `LAST`, `FIRST_SELECT`.
721728

729+
<a name="nested_configuration_query_connection_properties"></a>The `connection_properties` block supports:
730+
731+
* `key` -
732+
(Required)
733+
The key of the property to set. Currently supported connection properties:
734+
* `dataset_project_id`: represents the default project for datasets that are used in the query
735+
* `time_zone`: represents the default timezone used to run the query
736+
* `session_id`: associates the query with a given session
737+
* `query_label`: associates the query with a given job label
738+
* `service_account`: indicates the service account to use to run a continuous query
739+
740+
* `value` -
741+
(Required)
742+
The value of the property to set.
743+
722744
<a name="nested_configuration_load"></a>The `load` block supports:
723745

724746
* `source_uris` -

0 commit comments

Comments
 (0)