Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix salesforce params specification in google_bigquery_data_transfer_config #7828

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11232.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
bigquery: fixed an issue preventing certain keys in `params` from being assigned values in `google_bigquery_data_transfer_config`
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package bigquerydatatransfer

import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
Expand Down Expand Up @@ -965,8 +966,24 @@ func resourceBigqueryDataTransferConfigEncoder(d *schema.ResourceData, meta inte
paramMap = make(map[string]string)
}

var params map[string]string
params = paramMap.(map[string]string)
params := map[string]interface{}{}

for k, v := range paramMap.(map[string]string) {
var value interface{}
if err := json.Unmarshal([]byte(v), &value); err != nil {
// If the value is a string, don't convert it to anything.
params[k] = v
} else {
switch value.(type) {
case float64:
// If the value is a number, keep the string representation.
params[k] = v
default:
// If the value is another JSON type, keep the unmarshalled type as is.
params[k] = value
}
}
}

for _, sp := range sensitiveParams {
if auth, _ := d.GetOkExists("sensitive_params.0." + sp); auth != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func TestAccBigqueryDataTransferConfig(t *testing.T) {
"booleanParam": testAccBigqueryDataTransferConfig_copy_booleanParam,
"update_params": testAccBigqueryDataTransferConfig_force_new_update_params,
"update_service_account": testAccBigqueryDataTransferConfig_scheduledQuery_update_service_account,
"salesforce": testAccBigqueryDataTransferConfig_salesforce_basic,
}

for name, tc := range testCases {
Expand Down Expand Up @@ -572,6 +573,27 @@ func testAccCheckDataTransferServiceAccountNamePrefix(resourceName string, prefi
}
}

func testAccBigqueryDataTransferConfig_salesforce_basic(t *testing.T) {
randomSuffix := acctest.RandString(t, 10)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckBigqueryDataTransferConfigDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigqueryDataTransferConfig_salesforce(randomSuffix),
},
{
ResourceName: "google_bigquery_data_transfer_config.salesforce_config",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location"},
},
},
})
}

func testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, random_suffix2, schedule, start_time, end_time, letter string) string {
return fmt.Sprintf(`
data "google_project" "project" {}
Expand Down Expand Up @@ -812,3 +834,30 @@ resource "google_bigquery_data_transfer_config" "query_config" {
}
`, service_account, service_account, service_account, random_suffix, random_suffix, service_account)
}

func testAccBigqueryDataTransferConfig_salesforce(randomSuffix string) string {
return fmt.Sprintf(`
resource "google_bigquery_dataset" "dataset" {
dataset_id = "tf_test_%s"
friendly_name = "foo"
description = "bar"
location = "US"
}

resource "google_bigquery_data_transfer_config" "salesforce_config" {
display_name = "tf-test-%s"
data_source_id = "salesforce"
destination_dataset_id = google_bigquery_dataset.dataset.dataset_id
location = google_bigquery_dataset.dataset.location

params = {
"connector.authentication.oauth.clientId" = ""
"connector.authentication.oauth.clientSecret" = ""
"connector.authentication.username" = ""
"connector.authentication.password" = ""
"connector.authentication.securityToken" = ""
"assets" = "[asset-a, asset-b]"
}
}
`, randomSuffix, randomSuffix)
}
28 changes: 28 additions & 0 deletions website/docs/r/bigquery_data_transfer_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ resource "google_bigquery_dataset" "my_dataset" {
location = "asia-northeast1"
}
```
## Example Usage - Bigquerydatatransfer Config Salesforce


```hcl
data "google_project" "project" {
}

resource "google_bigquery_dataset" "my_dataset" {
dataset_id = "my_dataset"
description = "My dataset"
location = "asia-northeast1"
}
resource "google_bigquery_data_transfer_config" "salesforce_config" {
display_name = "my-salesforce-config"
location = "asia-northeast1"
data_source_id = "salesforce"
schedule = "first sunday of quarter 00:00"
destination_dataset_id = google_bigquery_dataset.my_dataset.dataset_id
params = {
"connector.authentication.oauth.clientId" = "client-id"
"connector.authentication.oauth.clientSecret" = "client-secret"
"connector.authentication.username" = "username"
"connector.authentication.password" = "password"
"connector.authentication.securityToken" = "security-token"
"assets" = "[asset-a, asset-b]"
}
}
```

## Argument Reference

Expand Down