From 62d685d8efee7584087ee1276befa4bfcdded4fe Mon Sep 17 00:00:00 2001 From: Patrick Cowland Date: Fri, 24 May 2024 12:34:25 +0100 Subject: [PATCH] `resource/davinci_flow`: include a `flow_variables` plan derived from the flow import JSON --- internal/service/davinci/resource_flow.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/service/davinci/resource_flow.go b/internal/service/davinci/resource_flow.go index b74de12d..49d2619d 100644 --- a/internal/service/davinci/resource_flow.go +++ b/internal/service/davinci/resource_flow.go @@ -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 @@ -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) } } @@ -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(