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: include a flow_variables plan derived from the flow import JSON #308

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
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