diff --git a/.changelog/4733.txt b/.changelog/4733.txt new file mode 100644 index 0000000000..52fd86db59 --- /dev/null +++ b/.changelog/4733.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +workflows: marked `source_contents` and `service_account` as updatable on `google_workflows_workflow` +``` diff --git a/google-beta/resource_workflows_workflow.go b/google-beta/resource_workflows_workflow.go index 68968a2f85..37ca92dc30 100644 --- a/google-beta/resource_workflows_workflow.go +++ b/google-beta/resource_workflows_workflow.go @@ -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. @@ -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": { @@ -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 { @@ -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, ",")}) diff --git a/google-beta/resource_workflows_workflow_test.go b/google-beta/resource_workflows_workflow_test.go index 499bd73d3d..ddc7eead78 100644 --- a/google-beta/resource_workflows_workflow_test.go +++ b/google-beta/resource_workflows_workflow_test.go @@ -8,11 +8,11 @@ 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) }, @@ -20,16 +20,16 @@ func TestAccWorkflowsWorkflow_basic(t *testing.T) { 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" @@ -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" @@ -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} @@ -104,7 +100,7 @@ resource "google_workflows_workflow" "example" { return: $${WikiResult.body[1]} EOF } -`, name, name) +`, name) } func TestWorkflowsWorkflowStateUpgradeV0(t *testing.T) {