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
  • Loading branch information
patrickcping committed May 24, 2024
1 parent 32ea8fe commit 62d685d
Showing 1 changed file with 19 additions and 0 deletions.
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 62d685d

Please sign in to comment.