diff --git a/.changelog/308.txt b/.changelog/308.txt new file mode 100644 index 00000000..2ea4b977 --- /dev/null +++ b/.changelog/308.txt @@ -0,0 +1,3 @@ +```release-note:note +`resource/davinci_flow`: `flow_variables` now includes a plan derived from the flow import JSON. +``` 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(