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

Enable Patching Workflows #9018

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/4733.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
workflows: marked `source_contents` and `service_account` as updatable on `google_workflows_workflow`
```
22 changes: 20 additions & 2 deletions google/resource_workflows_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func resourceWorkflowsWorkflow() *schema.Resource {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
Description: `Name of the service account associated with the latest workflow version. This service
account represents the identity of the workflow and determines what permissions the workflow has.
Expand All @@ -88,7 +87,6 @@ Format: projects/{project}/serviceAccounts/{account}.`,
"source_contents": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `Workflow code to be executed. The size limit is 32KB.`,
},
"create_time": {
Expand Down Expand Up @@ -325,6 +323,18 @@ func resourceWorkflowsWorkflowUpdate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
serviceAccountProp, err := expandWorkflowsWorkflowServiceAccount(d.Get("service_account"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("service_account"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, serviceAccountProp)) {
obj["serviceAccount"] = serviceAccountProp
}
sourceContentsProp, err := expandWorkflowsWorkflowSourceContents(d.Get("source_contents"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("source_contents"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sourceContentsProp)) {
obj["sourceContents"] = sourceContentsProp
}

obj, err = resourceWorkflowsWorkflowEncoder(d, meta, obj)
if err != nil {
Expand All @@ -346,6 +356,14 @@ func resourceWorkflowsWorkflowUpdate(d *schema.ResourceData, meta interface{}) e
if d.HasChange("labels") {
updateMask = append(updateMask, "labels")
}

if d.HasChange("service_account") {
updateMask = append(updateMask, "serviceAccount")
}

if d.HasChange("source_contents") {
updateMask = append(updateMask, "sourceContents")
}
// updateMask is a URL parameter but not present in the schema, so replaceVars
// won't set it
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down
20 changes: 8 additions & 12 deletions google/resource_workflows_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccWorkflowsWorkflow_basic(t *testing.T) {
func TestAccWorkflowsWorkflow_Update(t *testing.T) {
// Custom test written to test diffs
t.Parallel()

bucketName := fmt.Sprintf("tf-test-acc-bucket-%d", randInt(t))
workflowName := fmt.Sprintf("tf-test-acc-workflow-%d", randInt(t))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckWorkflowsWorkflowDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccWorkflowsWorkflow_basic(bucketName),
Config: testAccWorkflowsWorkflow_Update(workflowName),
},
{
Config: testAccWorkflowsWorkflow_newBucket(bucketName),
Config: testAccWorkflowsWorkflow_Updated(workflowName),
},
},
})
}

func testAccWorkflowsWorkflow_basic(name string) string {
func testAccWorkflowsWorkflow_Update(name string) string {
return fmt.Sprintf(`
resource "google_workflows_workflow" "example" {
name = "%s"
Expand Down Expand Up @@ -66,12 +66,8 @@ EOF
`, name)
}

func testAccWorkflowsWorkflow_newBucket(name string) string {
func testAccWorkflowsWorkflow_Updated(name string) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "bucket" {
name = "%s"
}

resource "google_workflows_workflow" "example" {
name = "%s"
region = "us-central1"
Expand All @@ -95,7 +91,7 @@ resource "google_workflows_workflow" "example" {
- readWikipedia:
call: http.get
args:
url: https://en.wikipedia.org/w/api.php
url: https:/fi.wikipedia.org/w/api.php
query:
action: opensearch
search: $${CurrentDateTime.body.dayOfTheWeek}
Expand All @@ -104,7 +100,7 @@ resource "google_workflows_workflow" "example" {
return: $${WikiResult.body[1]}
EOF
}
`, name, name)
`, name)
}

func TestWorkflowsWorkflowStateUpgradeV0(t *testing.T) {
Expand Down