Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
Added customizeDiff for a couple of subfields of params field in goog…
Browse files Browse the repository at this point in the history
…le_bigquery_data_transfer_config (#6784) (#1155)

* Added customize diff for params field in google_bigquery_data_transfer_config

* Added test cases for params field for google_bigquery_data_transfer_config

* Added unit tests to cover ForceNew behaviour of params field

* Added handling for customizeDiff in google_bigquery_data_transfer_config

* Added comments for parmasCustomizeDiff function in google_bigquery_data_transfer_config

* Added test case for different data_source_id in resource_bigquery_data_transfer_config

* Updated test case for different data_source_id in resource_bigquery_data_transfer_config

* Updated error message for resource_bigquery_data_transfer_config_test.go

* Updated test case for resource_bigquery_data_transfer_config_test.go

Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Nov 29, 2022
1 parent e7151ea commit 163c2c0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions converters/google/resources/bigquerydatatransfer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,40 @@ func sensitiveParamCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v
return nil
}

// This customizeDiff is to use ForceNew for params fields data_path_template and
// destination_table_name_template only if the value of "data_source_id" is "google_cloud_storage".
func paramsCustomizeDiffFunc(diff TerraformResourceDiff) error {
old, new := diff.GetChange("params")
dsId := diff.Get("data_source_id").(string)
oldParams := old.(map[string]interface{})
newParams := new.(map[string]interface{})
var err error

if dsId == "google_cloud_storage" {
if oldParams["data_path_template"] != nil && newParams["data_path_template"] != nil && oldParams["data_path_template"].(string) != newParams["data_path_template"].(string) {
err = diff.ForceNew("params")
if err != nil {
return fmt.Errorf("ForceNew failed for params, old - %v and new - %v", oldParams, newParams)
}
return nil
}

if oldParams["destination_table_name_template"] != nil && newParams["destination_table_name_template"] != nil && oldParams["destination_table_name_template"].(string) != newParams["destination_table_name_template"].(string) {
err = diff.ForceNew("params")
if err != nil {
return fmt.Errorf("ForceNew failed for params, old - %v and new - %v", oldParams, newParams)
}
return nil
}
}

return nil
}

func paramsCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
return paramsCustomizeDiffFunc(diff)
}

const BigqueryDataTransferConfigAssetType string = "bigquerydatatransfer.googleapis.com/Config"

func resourceConverterBigqueryDataTransferConfig() ResourceConverter {
Expand Down

0 comments on commit 163c2c0

Please sign in to comment.