diff --git a/internal/acctest/flows/full-minimal.json b/internal/acctest/flows/full-minimal.json index f9c2379d..96c1c8fb 100644 --- a/internal/acctest/flows/full-minimal.json +++ b/internal/acctest/flows/full-minimal.json @@ -8,7 +8,7 @@ "currentVersion": 4, "customerId": "db5f4450b2bd8a56ce076dec0c358a9a", "deployedDate": 1707837221226, - "description": "Imported on Wed Jan 31 2024 13:29:13 GMT+0000 (Coordinated Universal Time)", + "description": "This is a fallback description", "flowStatus": "enabled", "isOutputSchemaSaved": false, "name": "simple", diff --git a/internal/service/davinci/resource_flow.go b/internal/service/davinci/resource_flow.go index 0fe29a8b..69fb5416 100644 --- a/internal/service/davinci/resource_flow.go +++ b/internal/service/davinci/resource_flow.go @@ -955,6 +955,14 @@ func (p *FlowResourceModel) expand(ctx context.Context) (*davinci.FlowImport, di return nil, diags } + if data.Name == nil { + data.Name = &data.FlowInfo.Name + } + + if data.Description == nil && data.FlowInfo.Description != nil { + data.Description = data.FlowInfo.Description + } + data.FlowNameMapping = map[string]string{ data.FlowInfo.FlowID: p.Name.ValueString(), } @@ -1038,13 +1046,11 @@ func (p *FlowResourceModel) expandUpdate(state FlowResourceModel) (*davinci.Flow } if !p.Name.IsNull() { - name := p.Name.ValueString() - data.Name = &name + data.Name = p.Name.ValueStringPointer() } if !p.Description.IsNull() { - description := p.Description.ValueString() - data.Description = &description + data.Description = p.Description.ValueStringPointer() } err = davinci.Unmarshal([]byte(state.FlowConfigurationJSON.ValueString()), &stateData, davinci.ExportCmpOpts{}) @@ -1113,8 +1119,8 @@ func (p *FlowResourceModel) toState(apiObject *davinci.Flow) diag.Diagnostics { p.Name = framework.StringToTF(apiObject.Name) - if apiObject.Description != nil { - p.Description = framework.StringToTF(*apiObject.Description) + if v := apiObject.Description; v != nil { + p.Description = framework.StringToTF(*v) } var d diag.Diagnostics diff --git a/internal/service/davinci/resource_flow_test.go b/internal/service/davinci/resource_flow_test.go index 5d929fcf..ee504cef 100644 --- a/internal/service/davinci/resource_flow_test.go +++ b/internal/service/davinci/resource_flow_test.go @@ -146,22 +146,7 @@ func testAccResourceFlow_Basic(t *testing.T, withBootstrapConfig bool) { resource.TestMatchResourceAttr(resourceFullName, "id", verify.P1DVResourceIDRegexpFullString), resource.TestMatchResourceAttr(resourceFullName, "environment_id", verify.P1ResourceIDRegexpFullString), resource.TestCheckResourceAttr(resourceFullName, "name", "simple"), - resource.TestMatchResourceAttr(resourceFullName, "description", regexp.MustCompile(`^Imported on `)), - resource.TestCheckResourceAttr(resourceFullName, "flow_json", fmt.Sprintf("%s\n", minimalStepJson)), - resource.TestCheckResourceAttr(resourceFullName, "connection_link.#", "1"), - resource.TestCheckResourceAttr(resourceFullName, "deploy", "true"), - resource.TestCheckResourceAttr(resourceFullName, "subflow_link.#", "0"), - resource.TestCheckResourceAttr(resourceFullName, "flow_variables.#", "0"), - ), - } - - updateStep := resource.TestStep{ - Config: minimalStepHcl, - Check: resource.ComposeTestCheckFunc( - resource.TestMatchResourceAttr(resourceFullName, "id", verify.P1DVResourceIDRegexpFullString), - resource.TestMatchResourceAttr(resourceFullName, "environment_id", verify.P1ResourceIDRegexpFullString), - resource.TestCheckResourceAttr(resourceFullName, "name", "simple"), - resource.TestMatchResourceAttr(resourceFullName, "description", regexp.MustCompile(`^$`)), + resource.TestCheckResourceAttr(resourceFullName, "description", "This is a fallback description"), resource.TestCheckResourceAttr(resourceFullName, "flow_json", fmt.Sprintf("%s\n", minimalStepJson)), resource.TestCheckResourceAttr(resourceFullName, "connection_link.#", "1"), resource.TestCheckResourceAttr(resourceFullName, "deploy", "true"), @@ -184,13 +169,13 @@ func testAccResourceFlow_Basic(t *testing.T, withBootstrapConfig bool) { ErrorCheck: acctest.ErrorCheck(t), CheckDestroy: davinci.Flow_CheckDestroy(), Steps: []resource.TestStep{ - // Create from scratch + // Create full from scratch fullStep, { Config: fullStepHcl, Destroy: true, }, - // Create from scratch + // Create minimal from scratch minimalStep, { Config: minimalStepHcl, @@ -198,7 +183,7 @@ func testAccResourceFlow_Basic(t *testing.T, withBootstrapConfig bool) { }, // Test updates fullStep, - updateStep, + minimalStep, fullStep, // Test importing the resource {