Skip to content

Commit dd72a2f

Browse files
google_bigquery_connection - add missing output fields (#6988) (#13588)
Signed-off-by: Modular Magician <[email protected]>
1 parent ffb82b9 commit dd72a2f

File tree

4 files changed

+129
-2
lines changed

4 files changed

+129
-2
lines changed

.changelog/6988.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
bigquery: added `cloud_sql.service_account_id` and `azure.identity` output fields
3+
```
4+
```release-note:enhancement
5+
bigquery: added `cloud_spanner.use_serverless_analytics` field
6+
```

google/resource_bigquery_connection.go

+67-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ func resourceBigqueryConnectionConnection() *schema.Resource {
9595
Computed: true,
9696
Description: `The client id of the Azure Active Directory Application.`,
9797
},
98+
"identity": {
99+
Type: schema.TypeString,
100+
Computed: true,
101+
Description: `A unique Google-owned and Google-generated identity for the Connection. This identity will be used to access the user's Azure Active Directory Application.`,
102+
},
98103
"object_id": {
99104
Type: schema.TypeString,
100105
Computed: true,
@@ -142,14 +147,19 @@ func resourceBigqueryConnectionConnection() *schema.Resource {
142147
Optional: true,
143148
Description: `If parallelism should be used when reading from Cloud Spanner`,
144149
},
150+
"use_serverless_analytics": {
151+
Type: schema.TypeBool,
152+
Optional: true,
153+
Description: `If the serverless analytics service should be used to read data from Cloud Spanner. useParallelism must be set when using serverless analytics`,
154+
},
145155
},
146156
},
147157
ExactlyOneOf: []string{"cloud_sql", "aws", "azure", "cloud_spanner", "cloud_resource"},
148158
},
149159
"cloud_sql": {
150160
Type: schema.TypeList,
151161
Optional: true,
152-
Description: `A nested object resource`,
162+
Description: `Connection properties specific to the Cloud SQL.`,
153163
MaxItems: 1,
154164
Elem: &schema.Resource{
155165
Schema: map[string]*schema.Schema{
@@ -190,6 +200,11 @@ func resourceBigqueryConnectionConnection() *schema.Resource {
190200
ValidateFunc: validateEnum([]string{"DATABASE_TYPE_UNSPECIFIED", "POSTGRES", "MYSQL"}),
191201
Description: `Type of the Cloud SQL database. Possible values: ["DATABASE_TYPE_UNSPECIFIED", "POSTGRES", "MYSQL"]`,
192202
},
203+
"service_account_id": {
204+
Type: schema.TypeString,
205+
Computed: true,
206+
Description: `When the connection is used in the context of an operation in BigQuery, this service account will serve as the identity being used for connecting to the CloudSQL instance specified in this connection.`,
207+
},
193208
},
194209
},
195210
ExactlyOneOf: []string{"cloud_sql", "aws", "azure", "cloud_spanner", "cloud_resource"},
@@ -646,6 +661,8 @@ func flattenBigqueryConnectionConnectionCloudSql(v interface{}, d *schema.Resour
646661
flattenBigqueryConnectionConnectionCloudSqlCredential(original["credential"], d, config)
647662
transformed["type"] =
648663
flattenBigqueryConnectionConnectionCloudSqlType(original["type"], d, config)
664+
transformed["service_account_id"] =
665+
flattenBigqueryConnectionConnectionCloudSqlServiceAccountId(original["serviceAccountId"], d, config)
649666
return []interface{}{transformed}
650667
}
651668
func flattenBigqueryConnectionConnectionCloudSqlInstanceId(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -669,6 +686,10 @@ func flattenBigqueryConnectionConnectionCloudSqlType(v interface{}, d *schema.Re
669686
return v
670687
}
671688

689+
func flattenBigqueryConnectionConnectionCloudSqlServiceAccountId(v interface{}, d *schema.ResourceData, config *Config) interface{} {
690+
return v
691+
}
692+
672693
func flattenBigqueryConnectionConnectionAws(v interface{}, d *schema.ResourceData, config *Config) interface{} {
673694
if v == nil {
674695
return nil
@@ -724,6 +745,8 @@ func flattenBigqueryConnectionConnectionAzure(v interface{}, d *schema.ResourceD
724745
flattenBigqueryConnectionConnectionAzureCustomerTenantId(original["customerTenantId"], d, config)
725746
transformed["redirect_uri"] =
726747
flattenBigqueryConnectionConnectionAzureRedirectUri(original["redirectUri"], d, config)
748+
transformed["identity"] =
749+
flattenBigqueryConnectionConnectionAzureIdentity(original["identity"], d, config)
727750
return []interface{}{transformed}
728751
}
729752
func flattenBigqueryConnectionConnectionAzureApplication(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -746,6 +769,10 @@ func flattenBigqueryConnectionConnectionAzureRedirectUri(v interface{}, d *schem
746769
return v
747770
}
748771

772+
func flattenBigqueryConnectionConnectionAzureIdentity(v interface{}, d *schema.ResourceData, config *Config) interface{} {
773+
return v
774+
}
775+
749776
func flattenBigqueryConnectionConnectionCloudSpanner(v interface{}, d *schema.ResourceData, config *Config) interface{} {
750777
if v == nil {
751778
return nil
@@ -759,6 +786,8 @@ func flattenBigqueryConnectionConnectionCloudSpanner(v interface{}, d *schema.Re
759786
flattenBigqueryConnectionConnectionCloudSpannerDatabase(original["database"], d, config)
760787
transformed["use_parallelism"] =
761788
flattenBigqueryConnectionConnectionCloudSpannerUseParallelism(original["useParallelism"], d, config)
789+
transformed["use_serverless_analytics"] =
790+
flattenBigqueryConnectionConnectionCloudSpannerUseServerlessAnalytics(original["useServerlessAnalytics"], d, config)
762791
return []interface{}{transformed}
763792
}
764793
func flattenBigqueryConnectionConnectionCloudSpannerDatabase(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -769,6 +798,10 @@ func flattenBigqueryConnectionConnectionCloudSpannerUseParallelism(v interface{}
769798
return v
770799
}
771800

801+
func flattenBigqueryConnectionConnectionCloudSpannerUseServerlessAnalytics(v interface{}, d *schema.ResourceData, config *Config) interface{} {
802+
return v
803+
}
804+
772805
func flattenBigqueryConnectionConnectionCloudResource(v interface{}, d *schema.ResourceData, config *Config) interface{} {
773806
if v == nil {
774807
return nil
@@ -835,6 +868,13 @@ func expandBigqueryConnectionConnectionCloudSql(v interface{}, d TerraformResour
835868
transformed["type"] = transformedType
836869
}
837870

871+
transformedServiceAccountId, err := expandBigqueryConnectionConnectionCloudSqlServiceAccountId(original["service_account_id"], d, config)
872+
if err != nil {
873+
return nil, err
874+
} else if val := reflect.ValueOf(transformedServiceAccountId); val.IsValid() && !isEmptyValue(val) {
875+
transformed["serviceAccountId"] = transformedServiceAccountId
876+
}
877+
838878
return transformed, nil
839879
}
840880

@@ -884,6 +924,10 @@ func expandBigqueryConnectionConnectionCloudSqlType(v interface{}, d TerraformRe
884924
return v, nil
885925
}
886926

927+
func expandBigqueryConnectionConnectionCloudSqlServiceAccountId(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
928+
return v, nil
929+
}
930+
887931
func expandBigqueryConnectionConnectionAws(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
888932
l := v.([]interface{})
889933
if len(l) == 0 || l[0] == nil {
@@ -981,6 +1025,13 @@ func expandBigqueryConnectionConnectionAzure(v interface{}, d TerraformResourceD
9811025
transformed["redirectUri"] = transformedRedirectUri
9821026
}
9831027

1028+
transformedIdentity, err := expandBigqueryConnectionConnectionAzureIdentity(original["identity"], d, config)
1029+
if err != nil {
1030+
return nil, err
1031+
} else if val := reflect.ValueOf(transformedIdentity); val.IsValid() && !isEmptyValue(val) {
1032+
transformed["identity"] = transformedIdentity
1033+
}
1034+
9841035
return transformed, nil
9851036
}
9861037

@@ -1004,6 +1055,10 @@ func expandBigqueryConnectionConnectionAzureRedirectUri(v interface{}, d Terrafo
10041055
return v, nil
10051056
}
10061057

1058+
func expandBigqueryConnectionConnectionAzureIdentity(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1059+
return v, nil
1060+
}
1061+
10071062
func expandBigqueryConnectionConnectionCloudSpanner(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
10081063
l := v.([]interface{})
10091064
if len(l) == 0 || l[0] == nil {
@@ -1027,6 +1082,13 @@ func expandBigqueryConnectionConnectionCloudSpanner(v interface{}, d TerraformRe
10271082
transformed["useParallelism"] = transformedUseParallelism
10281083
}
10291084

1085+
transformedUseServerlessAnalytics, err := expandBigqueryConnectionConnectionCloudSpannerUseServerlessAnalytics(original["use_serverless_analytics"], d, config)
1086+
if err != nil {
1087+
return nil, err
1088+
} else if val := reflect.ValueOf(transformedUseServerlessAnalytics); val.IsValid() && !isEmptyValue(val) {
1089+
transformed["useServerlessAnalytics"] = transformedUseServerlessAnalytics
1090+
}
1091+
10301092
return transformed, nil
10311093
}
10321094

@@ -1038,6 +1100,10 @@ func expandBigqueryConnectionConnectionCloudSpannerUseParallelism(v interface{},
10381100
return v, nil
10391101
}
10401102

1103+
func expandBigqueryConnectionConnectionCloudSpannerUseServerlessAnalytics(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1104+
return v, nil
1105+
}
1106+
10411107
func expandBigqueryConnectionConnectionCloudResource(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
10421108
l := v.([]interface{})
10431109
if len(l) == 0 || l[0] == nil {

google/resource_bigquery_connection_generated_test.go

+45
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,51 @@ resource "google_bigquery_connection" "connection" {
350350
`, context)
351351
}
352352

353+
func TestAccBigqueryConnectionConnection_bigqueryConnectionCloudspannerAnalyticsExample(t *testing.T) {
354+
t.Parallel()
355+
356+
context := map[string]interface{}{
357+
"random_suffix": randString(t, 10),
358+
}
359+
360+
vcrTest(t, resource.TestCase{
361+
PreCheck: func() { testAccPreCheck(t) },
362+
Providers: testAccProviders,
363+
ExternalProviders: map[string]resource.ExternalProvider{
364+
"random": {},
365+
"time": {},
366+
},
367+
CheckDestroy: testAccCheckBigqueryConnectionConnectionDestroyProducer(t),
368+
Steps: []resource.TestStep{
369+
{
370+
Config: testAccBigqueryConnectionConnection_bigqueryConnectionCloudspannerAnalyticsExample(context),
371+
},
372+
{
373+
ResourceName: "google_bigquery_connection.connection",
374+
ImportState: true,
375+
ImportStateVerify: true,
376+
ImportStateVerifyIgnore: []string{"location"},
377+
},
378+
},
379+
})
380+
}
381+
382+
func testAccBigqueryConnectionConnection_bigqueryConnectionCloudspannerAnalyticsExample(context map[string]interface{}) string {
383+
return Nprintf(`
384+
resource "google_bigquery_connection" "connection" {
385+
connection_id = "tf-test-my-connection%{random_suffix}"
386+
location = "US"
387+
friendly_name = "👋"
388+
description = "a riveting description"
389+
cloud_spanner {
390+
database = "projects/project/instances/instance/databases/database%{random_suffix}"
391+
use_serverless_analytics = true
392+
use_parallelism = true
393+
}
394+
}
395+
`, context)
396+
}
397+
353398
func testAccCheckBigqueryConnectionConnectionDestroyProducer(t *testing.T) func(s *terraform.State) error {
354399
return func(s *terraform.State) error {
355400
for name, rs := range s.RootModule().Resources {

website/docs/r/bigquery_connection.html.markdown

+11-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ The following arguments are supported:
244244

245245
* `cloud_sql` -
246246
(Optional)
247-
A nested object resource
247+
Connection properties specific to the Cloud SQL.
248248
Structure is [documented below](#nested_cloud_sql).
249249

250250
* `aws` -
@@ -291,6 +291,9 @@ The following arguments are supported:
291291
Type of the Cloud SQL database.
292292
Possible values are `DATABASE_TYPE_UNSPECIFIED`, `POSTGRES`, and `MYSQL`.
293293

294+
* `service_account_id` -
295+
When the connection is used in the context of an operation in BigQuery, this service account will serve as the identity being used for connecting to the CloudSQL instance specified in this connection.
296+
294297

295298
<a name="nested_credential"></a>The `credential` block supports:
296299

@@ -338,6 +341,9 @@ The following arguments are supported:
338341
* `redirect_uri` -
339342
The URL user will be redirected to after granting consent during connection setup.
340343

344+
* `identity` -
345+
A unique Google-owned and Google-generated identity for the Connection. This identity will be used to access the user's Azure Active Directory Application.
346+
341347
<a name="nested_cloud_spanner"></a>The `cloud_spanner` block supports:
342348

343349
* `database` -
@@ -348,6 +354,10 @@ The following arguments are supported:
348354
(Optional)
349355
If parallelism should be used when reading from Cloud Spanner
350356

357+
* `use_serverless_analytics` -
358+
(Optional)
359+
If the serverless analytics service should be used to read data from Cloud Spanner. useParallelism must be set when using serverless analytics
360+
351361
<a name="nested_cloud_resource"></a>The `cloud_resource` block supports:
352362

353363
* `service_account_id` -

0 commit comments

Comments
 (0)