Skip to content

Commit

Permalink
Merge pull request #4676 from modular-magician/codegen-pr-2467
Browse files Browse the repository at this point in the history
Add custom flatten to transform json to string -> string map for params
  • Loading branch information
slevenick authored Oct 16, 2019
2 parents 87a05b2 + 8bd1f5d commit e7dac2b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
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)
}

0 comments on commit e7dac2b

Please sign in to comment.