Skip to content

Commit

Permalink
Use new dataflow templates, fix labels (#5206)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and emilymye committed Dec 17, 2019
1 parent b153307 commit 82c068d
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 250 deletions.
26 changes: 22 additions & 4 deletions google/resource_dataflow_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"google.golang.org/api/googleapi"
)

const resourceDataflowJobGoogleProvidedLabelPrefix = "labels.goog-dataflow-provided"

var dataflowTerminalStatesMap = map[string]struct{}{
"JOB_STATE_DONE": {},
"JOB_STATE_FAILED": {},
Expand All @@ -22,12 +24,27 @@ var dataflowTerminalStatesMap = map[string]struct{}{
"JOB_STATE_DRAINED": {},
}

func resourceDataflowJobLabelDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
// Example Diff: "labels.goog-dataflow-provided-template-version": "word_count" => ""
if strings.HasPrefix(k, resourceDataflowJobGoogleProvidedLabelPrefix) && new == "" {
// Suppress diff if field is a Google Dataflow-provided label key and has no explicitly set value in Config.
return true
}

// Let diff be determined by labels (above)
if strings.HasPrefix(k, "labels.%") {
return true
}

// For other keys, don't suppress diff.
return false
}

func resourceDataflowJob() *schema.Resource {
return &schema.Resource{
Create: resourceDataflowJobCreate,
Read: resourceDataflowJobRead,
Delete: resourceDataflowJobDelete,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -72,9 +89,10 @@ func resourceDataflowJob() *schema.Resource {
},

"labels": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
DiffSuppressFunc: resourceDataflowJobLabelDiffSuppress,
},

"on_delete": {
Expand Down
Loading

0 comments on commit 82c068d

Please sign in to comment.