Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dataflow flextemplate job labels #4748

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6559.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dataflow : added support of `labels` to resource `google_dataflow_flextemplate_job` (beta)
```
17 changes: 14 additions & 3 deletions google-beta/resource_dataflow_flex_template_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ func resourceDataflowFlexTemplateJob() *schema.Resource {
Type: schema.TypeMap,
Optional: true,
DiffSuppressFunc: resourceDataflowJobLabelDiffSuppress,
// TODO add support for labels when the API supports it
Deprecated: "Deprecated until the API supports this field",
},

"parameters": {
Expand Down Expand Up @@ -117,6 +115,9 @@ func resourceDataflowFlexTemplateJobCreate(d *schema.ResourceData, meta interfac
ContainerSpecGcsPath: d.Get("container_spec_gcs_path").(string),
JobName: d.Get("name").(string),
Parameters: expandStringMap(d, "parameters"),
Environment: &dataflow.FlexTemplateRuntimeEnvironment{
AdditionalUserLabels: expandStringMap(d, "labels"),
},
},
}

Expand All @@ -126,6 +127,13 @@ func resourceDataflowFlexTemplateJobCreate(d *schema.ResourceData, meta interfac
}

job := response.Job

//adding wait time for setting all the parameters into state file
err = waitForDataflowJobState(d, config, job.Id, userAgent, d.Timeout(schema.TimeoutUpdate), "JOB_STATE_RUNNING")
if err != nil {
return fmt.Errorf("Error waiting for job with job ID %q to be running: %s", job.Id, err)
}

d.SetId(job.Id)
if err := d.Set("job_id", job.Id); err != nil {
return fmt.Errorf("Error setting job_id: %s", err)
Expand Down Expand Up @@ -253,7 +261,10 @@ func resourceDataflowFlexTemplateJobUpdate(d *schema.ResourceData, meta interfac
ContainerSpecGcsPath: d.Get("container_spec_gcs_path").(string),
JobName: d.Get("name").(string),
Parameters: expandStringMap(d, "parameters"),
Update: true,
Environment: &dataflow.FlexTemplateRuntimeEnvironment{
AdditionalUserLabels: expandStringMap(d, "labels"),
},
Update: true,
},
}

Expand Down
6 changes: 6 additions & 0 deletions google-beta/resource_dataflow_flex_template_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ resource "google_dataflow_flex_template_job" "job" {
qps = "1"
%s
}
labels = {
"my_labels" = "value"
}
}
`, job, topicField)
}
Expand Down Expand Up @@ -237,6 +240,9 @@ resource "google_dataflow_flex_template_job" "job" {
serviceAccount = google_service_account.dataflow-sa.email
zone = "%s"
}
labels = {
"my_labels" = "value"
}
}
`, accountId, job, zone)
}
Expand Down
3 changes: 1 addition & 2 deletions website/docs/r/dataflow_flex_template_job.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ such as `serviceAccount`, `workerMachineType`, etc can be specified here.

* `labels` - (Optional) User labels to be specified for the job. Keys and values
should follow the restrictions specified in the [labeling restrictions](https://cloud.google.com/compute/docs/labeling-resources#restrictions)
page. **Note**: This field is marked as deprecated in Terraform as the API does not currently
support adding labels.
page.
**NOTE**: Google-provided Dataflow templates often provide default labels
that begin with `goog-dataflow-provided`. Unless explicitly set in config, these
labels will be ignored to prevent diffs on re-apply.
Expand Down