Skip to content

Commit

Permalink
resource/davinci_flow: include a flow_variables plan derived from…
Browse files Browse the repository at this point in the history
… the flow import JSON (#308)

* `resource/davinci_flow`: include a `flow_variables` plan derived from the flow import JSON

* changelog
  • Loading branch information
patrickcping authored May 24, 2024
1 parent 32ea8fe commit a3e2d9c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/308.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:note
`resource/davinci_flow`: `flow_variables` now includes a plan derived from the flow import JSON.
```
19 changes: 19 additions & 0 deletions internal/service/davinci/resource_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ func (p *FlowResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRe
return
}

// Flow configuration
if !state.FlowConfigurationJSON.IsNull() {
// Compute the Flow Configuration (the drift of the import file is calculated based on this attribute)
var flowConfigStateObject davinci.FlowConfiguration
Expand All @@ -470,6 +471,21 @@ func (p *FlowResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRe
return
}
}

// Flow variables
flowVariablesPlan := make([]davinci.FlowVariable, 0)
for _, flowVariable := range flowObject.FlowMetadata.Variables {
flowVariableIDOld := *flowVariable.FlowID
flowVariable.FlowID = state.Id.ValueStringPointer()
flowVariable.Name = strings.Replace(flowVariable.Name, flowVariableIDOld, state.Id.ValueString(), -1)

flowVariablesPlan = append(flowVariablesPlan, flowVariable)
}

var d diag.Diagnostics
flowVariables, d := flowVariablesToTF(flowVariablesPlan)
resp.Diagnostics.Append(d...)
resp.Plan.SetAttribute(ctx, path.Root("flow_variables"), flowVariables)
}
}

Expand All @@ -479,8 +495,11 @@ func (p *FlowResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRe

flowConfigurationJSON = types.StringUnknown()

resp.Plan.SetAttribute(ctx, path.Root("flow_variables"), types.SetUnknown(types.ObjectType{AttrTypes: flowVariablesTFObjectTypes}))

} else {

// Flow configuration
jsonFlowConfigBytes, err := davinci.Marshal(flowConfigObject, flowExportCmpOptsConfiguration)
if err != nil {
resp.Diagnostics.AddError(
Expand Down

0 comments on commit a3e2d9c

Please sign in to comment.