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

Add custom flatten to transform json to string -> string map for params #4676

Merged
merged 1 commit into from
Oct 16, 2019
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
12 changes: 11 additions & 1 deletion google/resource_bigquery_data_transfer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,17 @@ func flattenBigqueryDataTransferConfigDisabled(v interface{}, d *schema.Resource
}

func flattenBigqueryDataTransferConfigParams(v interface{}, d *schema.ResourceData) interface{} {
return v
if v == nil {
return v
}

kv := v.(map[string]interface{})

res := make(map[string]string)
for key, value := range kv {
res[key] = fmt.Sprintf("%v", value)
}
return res
}

func expandBigqueryDataTransferConfigDisplayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
Expand Down
70 changes: 68 additions & 2 deletions google/resource_bigquery_data_transfer_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
// but it will get deleted by parallel tests, so they need to be ran serially.
func TestAccBigqueryDataTransferConfig(t *testing.T) {
testCases := map[string]func(t *testing.T){
"basic": testAccBigqueryDataTransferConfig_scheduledQuery_basic,
"update": testAccBigqueryDataTransferConfig_scheduledQuery_update,
"basic": testAccBigqueryDataTransferConfig_scheduledQuery_basic,
"update": testAccBigqueryDataTransferConfig_scheduledQuery_update,
"booleanParam": testAccBigqueryDataTransferConfig_copy_booleanParam,
}

for name, tc := range testCases {
Expand Down Expand Up @@ -75,6 +76,27 @@ func testAccBigqueryDataTransferConfig_scheduledQuery_update(t *testing.T) {
})
}

func testAccBigqueryDataTransferConfig_copy_booleanParam(t *testing.T) {
random_suffix := acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBigqueryDataTransferConfigDestroy,
Steps: []resource.TestStep{
{
Config: testAccBigqueryDataTransferConfig_booleanParam(random_suffix),
},
{
ResourceName: "google_bigquery_data_transfer_config.copy_config",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location"},
},
},
})
}

func testAccCheckBigqueryDataTransferConfigDestroy(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_bigquery_data_transfer_config" {
Expand Down Expand Up @@ -135,3 +157,47 @@ resource "google_bigquery_data_transfer_config" "query_config" {
}
`, random_suffix, random_suffix, schedule, letter)
}

func testAccBigqueryDataTransferConfig_booleanParam(random_suffix string) string {
return fmt.Sprintf(`
data "google_project" "project" {}

resource "google_project_iam_member" "permissions" {
role = "roles/iam.serviceAccountShortTermTokenMinter"
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-bigquerydatatransfer.iam.gserviceaccount.com"
}

resource "google_bigquery_dataset" "source_dataset" {
depends_on = [google_project_iam_member.permissions]

dataset_id = "source_%s"
friendly_name = "foo"
description = "bar"
location = "asia-northeast1"
}

resource "google_bigquery_dataset" "destination_dataset" {
depends_on = [google_project_iam_member.permissions]

dataset_id = "destination_%s"
friendly_name = "foo"
description = "bar"
location = "asia-northeast1"
}

resource "google_bigquery_data_transfer_config" "copy_config" {
depends_on = [google_project_iam_member.permissions]

location = "asia-northeast1"

display_name = "Copy test %s"
data_source_id = "cross_region_copy"
destination_dataset_id = google_bigquery_dataset.destination_dataset.dataset_id
params = {
overwrite_destination_table = "true"
source_dataset_id = google_bigquery_dataset.source_dataset.dataset_id
source_project_id = data.google_project.project.project_id
}
}
`, random_suffix, random_suffix, random_suffix)
}