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

resource/davinci_flow: Fix inconsistent state errors when importing a flow with a non-default log setting #288

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
7 changes: 7 additions & 0 deletions .changelog/288.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
`resource/davinci_flow`: Fixed inconsistent state errors when importing a flow with a non-default log setting.
```

```release-note:note
bump `github.com/samir-gandhi/davinci-client-go` 0.2.0 => 0.3.0
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/katbyte/terrafmt v0.5.3
github.com/patrickcping/pingone-go-sdk-v2/management v0.38.0
github.com/pavius/impi v0.0.3
github.com/samir-gandhi/davinci-client-go v0.2.0
github.com/samir-gandhi/davinci-client-go v0.3.0
github.com/samir-gandhi/dvgenerate v0.0.10
github.com/terraform-linters/tflint v0.50.3
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,8 @@ github.com/ryancurrah/gomodguard v1.3.0 h1:q15RT/pd6UggBXVBuLps8BXRvl5GPBcwVA7BJ
github.com/ryancurrah/gomodguard v1.3.0/go.mod h1:ggBxb3luypPEzqVtq33ee7YSN35V28XeGnid8dnni50=
github.com/ryanrolds/sqlclosecheck v0.5.1 h1:dibWW826u0P8jNLsLN+En7+RqWWTYrjCB9fJfSfdyCU=
github.com/ryanrolds/sqlclosecheck v0.5.1/go.mod h1:2g3dUjoS6AL4huFdv6wn55WpLIDjY7ZgUR4J8HOO/XQ=
github.com/samir-gandhi/davinci-client-go v0.2.0 h1:+EJb72s0gntckdCDduTHNZ+tuqS6ZtMzLOr0VKuY0sU=
github.com/samir-gandhi/davinci-client-go v0.2.0/go.mod h1:DmOPy/WsIc4e7RYOIeSGM6Qrlb1JsYuN45UaGnlDt9U=
github.com/samir-gandhi/davinci-client-go v0.3.0 h1:pwP5E0h7FcknX2hSs3TC3jAuD7/0zlzm6qypaps9Wos=
github.com/samir-gandhi/davinci-client-go v0.3.0/go.mod h1:DmOPy/WsIc4e7RYOIeSGM6Qrlb1JsYuN45UaGnlDt9U=
github.com/samir-gandhi/dvgenerate v0.0.10 h1:x60N40peUuw1J6TLAru70sK2cM/pcISaluqgxir9m0s=
github.com/samir-gandhi/dvgenerate v0.0.10/go.mod h1:PvrK6c+8SdRSWKmyXsagKeVqSGoo9P8oBbWaIzFD1mQ=
github.com/sanposhiho/wastedassign/v2 v2.0.7 h1:J+6nrY4VW+gC9xFzUc+XjPD3g3wF3je/NsJFwFK7Uxc=
Expand Down
4 changes: 3 additions & 1 deletion internal/acctest/flows/full-minimal.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"csp": "worker-src 'self' blob:; script-src 'self' https://cdn.jsdelivr.net https://code.jquery.com https://devsdk.singularkey.com http://cdnjs.cloudflare.com 'unsafe-inline' 'unsafe-eval';",
"intermediateLoadingScreenCSS": "",
"intermediateLoadingScreenHTML": "",
"flowHttpTimeoutInSeconds": 300
"flowHttpTimeoutInSeconds": 300,
"logLevel": 1,
"useCustomCSS": true
},
"timeouts": "null",
"updatedDate": 1707837221226,
Expand Down
89 changes: 53 additions & 36 deletions internal/service/davinci/resource_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,19 @@ func (r *FlowResource) Create(ctx context.Context, req resource.CreateRequest, r
return
}

// do an update for the settings
flowUpdate := davinci.FlowUpdate{
FlowUpdateConfiguration: daVinciImport.FlowInfo.FlowUpdateConfiguration,
CurrentVersion: createFlow.CurrentVersion,
Name: &createFlow.Name,
Description: createFlow.Description,
}

resp.Diagnostics.Append(r.updateFlow(ctx, environmentID, createFlow.FlowID, &flowUpdate)...)
if resp.Diagnostics.HasError() {
return
}

// Do an export for state
// Run the API call
sdkRes, err := sdk.DoRetryable(
Expand Down Expand Up @@ -725,48 +738,13 @@ func (r *FlowResource) Update(ctx context.Context, req resource.UpdateRequest, r
flowID := plan.Id.ValueString()

if !plan.FlowConfigurationJSON.Equal(state.FlowConfigurationJSON) {

daVinciUpdate, d := plan.expandUpdate(state)
resp.Diagnostics.Append(d...)
if resp.Diagnostics.HasError() {
return
}

_, err := sdk.DoRetryable(
ctx,
r.Client,
environmentID,
func() (any, *http.Response, error) {
return r.Client.UpdateFlowWithResponse(environmentID, flowID, *daVinciUpdate)
},
)
if err != nil {
resp.Diagnostics.AddError(
"Error importing flow",
fmt.Sprintf("Error updating flow: %s", err),
)
}
if resp.Diagnostics.HasError() {
return
}

_, err = sdk.DoRetryable(
ctx,
r.Client,
environmentID,
func() (any, *http.Response, error) {
return r.Client.DeployFlowWithResponse(environmentID, flowID)
},
)
if err != nil {
resp.Diagnostics.AddError(
"Error deploying flow",
fmt.Sprintf("Error deploying flow, this might indicate a misconfiguration of the flow: %s", err),
)
}
if resp.Diagnostics.HasError() {
return
}
resp.Diagnostics.Append(r.updateFlow(ctx, environmentID, flowID, daVinciUpdate)...)
}

// Do an export for state
Expand Down Expand Up @@ -804,6 +782,45 @@ func (r *FlowResource) Update(ctx context.Context, req resource.UpdateRequest, r
resp.Diagnostics.Append(resp.State.Set(ctx, state)...)
}

func (r *FlowResource) updateFlow(ctx context.Context, environmentID, flowID string, daVinciUpdate *davinci.FlowUpdate) diag.Diagnostics {
var diags diag.Diagnostics

_, err := sdk.DoRetryable(
ctx,
r.Client,
environmentID,
func() (any, *http.Response, error) {
return r.Client.UpdateFlowWithResponse(environmentID, flowID, *daVinciUpdate)
},
)
if err != nil {
diags.AddError(
"Error importing flow",
fmt.Sprintf("Error updating flow: %s", err),
)
}
if diags.HasError() {
return diags
}

_, err = sdk.DoRetryable(
ctx,
r.Client,
environmentID,
func() (any, *http.Response, error) {
return r.Client.DeployFlowWithResponse(environmentID, flowID)
},
)
if err != nil {
diags.AddError(
"Error deploying flow",
fmt.Sprintf("Error deploying flow, this might indicate a misconfiguration of the flow, or an unmapped node connection: %s", err),
)
}

return diags
}

func (r *FlowResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var data FlowResourceModel

Expand Down