Skip to content

Commit

Permalink
Don't error out if dataflow api fails to return sdk pipeline options (#…
Browse files Browse the repository at this point in the history
…8902) (#15821)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 12, 2023
1 parent 68dc6cc commit 9e626fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .changelog/8902.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
pipeline: fixed issue where certain `google_dataflow_job` instances would crash the provider
```
38 changes: 20 additions & 18 deletions google/services/dataflow/resource_dataflow_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,25 +351,27 @@ func resourceDataflowJobRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error setting kms_key_name: %s", err)
}

// This map isn't provided on all responses. It's not clear why but we only want to set these fields
// if the API returns. Otherwise this execution will crash for the user.
// https://github.com/hashicorp/terraform-provider-google/issues/7449
sdkPipelineOptions, err := tpgresource.ConvertToMap(job.Environment.SdkPipelineOptions)
if err != nil {
return err
}
optionsMap := sdkPipelineOptions["options"].(map[string]interface{})
if err := d.Set("template_gcs_path", optionsMap["templateLocation"]); err != nil {
return fmt.Errorf("Error setting template_gcs_path: %s", err)
}
if err := d.Set("temp_gcs_location", optionsMap["tempLocation"]); err != nil {
return fmt.Errorf("Error setting temp_gcs_location: %s", err)
}
if err := d.Set("machine_type", optionsMap["machineType"]); err != nil {
return fmt.Errorf("Error setting machine_type: %s", err)
}
if err := d.Set("network", optionsMap["network"]); err != nil {
return fmt.Errorf("Error setting network: %s", err)
}
if err := d.Set("service_account_email", optionsMap["serviceAccountEmail"]); err != nil {
return fmt.Errorf("Error setting service_account_email: %s", err)
if err == nil {
optionsMap := sdkPipelineOptions["options"].(map[string]interface{})
if err := d.Set("template_gcs_path", optionsMap["templateLocation"]); err != nil {
return fmt.Errorf("Error setting template_gcs_path: %s", err)
}
if err := d.Set("temp_gcs_location", optionsMap["tempLocation"]); err != nil {
return fmt.Errorf("Error setting temp_gcs_location: %s", err)
}
if err := d.Set("machine_type", optionsMap["machineType"]); err != nil {
return fmt.Errorf("Error setting machine_type: %s", err)
}
if err := d.Set("network", optionsMap["network"]); err != nil {
return fmt.Errorf("Error setting network: %s", err)
}
if err := d.Set("service_account_email", optionsMap["serviceAccountEmail"]); err != nil {
return fmt.Errorf("Error setting service_account_email: %s", err)
}
}

if ok := shouldStopDataflowJobDeleteQuery(job.CurrentState, d.Get("skip_wait_on_job_termination").(bool)); ok {
Expand Down

0 comments on commit 9e626fc

Please sign in to comment.