Skip to content

Commit

Permalink
google_bigquery_connection - add missing output fields (#6988) (#13588)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jan 27, 2023
1 parent ffb82b9 commit dd72a2f
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changelog/6988.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
bigquery: added `cloud_sql.service_account_id` and `azure.identity` output fields
```
```release-note:enhancement
bigquery: added `cloud_spanner.use_serverless_analytics` field
```
68 changes: 67 additions & 1 deletion google/resource_bigquery_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func resourceBigqueryConnectionConnection() *schema.Resource {
Computed: true,
Description: `The client id of the Azure Active Directory Application.`,
},
"identity": {
Type: schema.TypeString,
Computed: true,
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.`,
},
"object_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -142,14 +147,19 @@ func resourceBigqueryConnectionConnection() *schema.Resource {
Optional: true,
Description: `If parallelism should be used when reading from Cloud Spanner`,
},
"use_serverless_analytics": {
Type: schema.TypeBool,
Optional: true,
Description: `If the serverless analytics service should be used to read data from Cloud Spanner. useParallelism must be set when using serverless analytics`,
},
},
},
ExactlyOneOf: []string{"cloud_sql", "aws", "azure", "cloud_spanner", "cloud_resource"},
},
"cloud_sql": {
Type: schema.TypeList,
Optional: true,
Description: `A nested object resource`,
Description: `Connection properties specific to the Cloud SQL.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -190,6 +200,11 @@ func resourceBigqueryConnectionConnection() *schema.Resource {
ValidateFunc: validateEnum([]string{"DATABASE_TYPE_UNSPECIFIED", "POSTGRES", "MYSQL"}),
Description: `Type of the Cloud SQL database. Possible values: ["DATABASE_TYPE_UNSPECIFIED", "POSTGRES", "MYSQL"]`,
},
"service_account_id": {
Type: schema.TypeString,
Computed: true,
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.`,
},
},
},
ExactlyOneOf: []string{"cloud_sql", "aws", "azure", "cloud_spanner", "cloud_resource"},
Expand Down Expand Up @@ -646,6 +661,8 @@ func flattenBigqueryConnectionConnectionCloudSql(v interface{}, d *schema.Resour
flattenBigqueryConnectionConnectionCloudSqlCredential(original["credential"], d, config)
transformed["type"] =
flattenBigqueryConnectionConnectionCloudSqlType(original["type"], d, config)
transformed["service_account_id"] =
flattenBigqueryConnectionConnectionCloudSqlServiceAccountId(original["serviceAccountId"], d, config)
return []interface{}{transformed}
}
func flattenBigqueryConnectionConnectionCloudSqlInstanceId(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand All @@ -669,6 +686,10 @@ func flattenBigqueryConnectionConnectionCloudSqlType(v interface{}, d *schema.Re
return v
}

func flattenBigqueryConnectionConnectionCloudSqlServiceAccountId(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenBigqueryConnectionConnectionAws(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -724,6 +745,8 @@ func flattenBigqueryConnectionConnectionAzure(v interface{}, d *schema.ResourceD
flattenBigqueryConnectionConnectionAzureCustomerTenantId(original["customerTenantId"], d, config)
transformed["redirect_uri"] =
flattenBigqueryConnectionConnectionAzureRedirectUri(original["redirectUri"], d, config)
transformed["identity"] =
flattenBigqueryConnectionConnectionAzureIdentity(original["identity"], d, config)
return []interface{}{transformed}
}
func flattenBigqueryConnectionConnectionAzureApplication(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand All @@ -746,6 +769,10 @@ func flattenBigqueryConnectionConnectionAzureRedirectUri(v interface{}, d *schem
return v
}

func flattenBigqueryConnectionConnectionAzureIdentity(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenBigqueryConnectionConnectionCloudSpanner(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand All @@ -759,6 +786,8 @@ func flattenBigqueryConnectionConnectionCloudSpanner(v interface{}, d *schema.Re
flattenBigqueryConnectionConnectionCloudSpannerDatabase(original["database"], d, config)
transformed["use_parallelism"] =
flattenBigqueryConnectionConnectionCloudSpannerUseParallelism(original["useParallelism"], d, config)
transformed["use_serverless_analytics"] =
flattenBigqueryConnectionConnectionCloudSpannerUseServerlessAnalytics(original["useServerlessAnalytics"], d, config)
return []interface{}{transformed}
}
func flattenBigqueryConnectionConnectionCloudSpannerDatabase(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand All @@ -769,6 +798,10 @@ func flattenBigqueryConnectionConnectionCloudSpannerUseParallelism(v interface{}
return v
}

func flattenBigqueryConnectionConnectionCloudSpannerUseServerlessAnalytics(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenBigqueryConnectionConnectionCloudResource(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -835,6 +868,13 @@ func expandBigqueryConnectionConnectionCloudSql(v interface{}, d TerraformResour
transformed["type"] = transformedType
}

transformedServiceAccountId, err := expandBigqueryConnectionConnectionCloudSqlServiceAccountId(original["service_account_id"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedServiceAccountId); val.IsValid() && !isEmptyValue(val) {
transformed["serviceAccountId"] = transformedServiceAccountId
}

return transformed, nil
}

Expand Down Expand Up @@ -884,6 +924,10 @@ func expandBigqueryConnectionConnectionCloudSqlType(v interface{}, d TerraformRe
return v, nil
}

func expandBigqueryConnectionConnectionCloudSqlServiceAccountId(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandBigqueryConnectionConnectionAws(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -981,6 +1025,13 @@ func expandBigqueryConnectionConnectionAzure(v interface{}, d TerraformResourceD
transformed["redirectUri"] = transformedRedirectUri
}

transformedIdentity, err := expandBigqueryConnectionConnectionAzureIdentity(original["identity"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedIdentity); val.IsValid() && !isEmptyValue(val) {
transformed["identity"] = transformedIdentity
}

return transformed, nil
}

Expand All @@ -1004,6 +1055,10 @@ func expandBigqueryConnectionConnectionAzureRedirectUri(v interface{}, d Terrafo
return v, nil
}

func expandBigqueryConnectionConnectionAzureIdentity(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandBigqueryConnectionConnectionCloudSpanner(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand All @@ -1027,6 +1082,13 @@ func expandBigqueryConnectionConnectionCloudSpanner(v interface{}, d TerraformRe
transformed["useParallelism"] = transformedUseParallelism
}

transformedUseServerlessAnalytics, err := expandBigqueryConnectionConnectionCloudSpannerUseServerlessAnalytics(original["use_serverless_analytics"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedUseServerlessAnalytics); val.IsValid() && !isEmptyValue(val) {
transformed["useServerlessAnalytics"] = transformedUseServerlessAnalytics
}

return transformed, nil
}

Expand All @@ -1038,6 +1100,10 @@ func expandBigqueryConnectionConnectionCloudSpannerUseParallelism(v interface{},
return v, nil
}

func expandBigqueryConnectionConnectionCloudSpannerUseServerlessAnalytics(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandBigqueryConnectionConnectionCloudResource(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
45 changes: 45 additions & 0 deletions google/resource_bigquery_connection_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,51 @@ resource "google_bigquery_connection" "connection" {
`, context)
}

func TestAccBigqueryConnectionConnection_bigqueryConnectionCloudspannerAnalyticsExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
"time": {},
},
CheckDestroy: testAccCheckBigqueryConnectionConnectionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigqueryConnectionConnection_bigqueryConnectionCloudspannerAnalyticsExample(context),
},
{
ResourceName: "google_bigquery_connection.connection",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location"},
},
},
})
}

func testAccBigqueryConnectionConnection_bigqueryConnectionCloudspannerAnalyticsExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_bigquery_connection" "connection" {
connection_id = "tf-test-my-connection%{random_suffix}"
location = "US"
friendly_name = "👋"
description = "a riveting description"
cloud_spanner {
database = "projects/project/instances/instance/databases/database%{random_suffix}"
use_serverless_analytics = true
use_parallelism = true
}
}
`, context)
}

func testAccCheckBigqueryConnectionConnectionDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
12 changes: 11 additions & 1 deletion website/docs/r/bigquery_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ The following arguments are supported:

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

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

* `service_account_id` -
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.


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

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

* `identity` -
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.

<a name="nested_cloud_spanner"></a>The `cloud_spanner` block supports:

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

* `use_serverless_analytics` -
(Optional)
If the serverless analytics service should be used to read data from Cloud Spanner. useParallelism must be set when using serverless analytics

<a name="nested_cloud_resource"></a>The `cloud_resource` block supports:

* `service_account_id` -
Expand Down

0 comments on commit dd72a2f

Please sign in to comment.