Skip to content

Commit

Permalink
Use new dataflow templates, fix labels (#2849)
Browse files Browse the repository at this point in the history
Merged PR #2849.
  • Loading branch information
emilymye authored and modular-magician committed Dec 17, 2019
1 parent 93359f5 commit df85614
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 252 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
26 changes: 22 additions & 4 deletions third_party/terraform/resources/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 df85614

Please sign in to comment.