Skip to content

Commit

Permalink
schema
Browse files Browse the repository at this point in the history
  • Loading branch information
louisheath committed Apr 23, 2024
1 parent e8faaaf commit 420ad67
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 25 deletions.
2 changes: 1 addition & 1 deletion internal/provider/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type IncidentEngineExpression struct {
ElseBranch *IncidentEngineElseBranch `tfsdk:"else_branch"`
ID types.String `tfsdk:"id"` // rmv?
Label types.String `tfsdk:"label"`
Operations []IncidentEngineExpressionOperation `tfsdk:"operation"`
Operations []IncidentEngineExpressionOperation `tfsdk:"operations"`
Reference types.String `tfsdk:"reference"`
RootReference types.String `tfsdk:"root_reference"`
}
Expand Down
137 changes: 114 additions & 23 deletions internal/provider/incident_workflow_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,53 @@ func (r *IncidentWorkflowResource) Schema(ctx context.Context, req resource.Sche
},
}

paramBindingAttributes := map[string]schema.Attribute{
"array_value": schema.SetNestedAttribute{
Optional: true,
NestedObject: schema.NestedAttributeObject{
Attributes: paramBindingValueAttributes,
},
},
"value": schema.SingleNestedAttribute{
Optional: true,
Attributes: paramBindingValueAttributes,
},
}

paramBindingsAttribute := schema.ListNestedAttribute{
Required: true,
NestedObject: schema.NestedAttributeObject{
Attributes: paramBindingAttributes,
},
}

conditionsAttribute := schema.SetNestedAttribute{
Required: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"array_value": schema.SetNestedAttribute{
Optional: true,
NestedObject: schema.NestedAttributeObject{
Attributes: paramBindingValueAttributes,
},
"operation": schema.StringAttribute{
Required: true,
},
"value": schema.SingleNestedAttribute{
Optional: true,
Attributes: paramBindingValueAttributes,
"param_bindings": paramBindingsAttribute,
"subject": schema.StringAttribute{
Required: true,
},
},
},
}

returnsAttribute := schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
"array": schema.BoolAttribute{
Required: true,
},
"type": schema.StringAttribute{
Required: true,
},
},
}

resp.Schema = schema.Schema{
MarkdownDescription: apischema.TagDocstring("Workflows V2"),
Attributes: map[string]schema.Attribute{
Expand All @@ -103,20 +132,7 @@ func (r *IncidentWorkflowResource) Schema(ctx context.Context, req resource.Sche
Required: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"conditions": schema.SetNestedAttribute{
Required: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"operation": schema.StringAttribute{
Required: true,
},
"param_bindings": paramBindingsAttribute,
"subject": schema.StringAttribute{
Required: true,
},
},
},
},
"conditions": conditionsAttribute,
},
},
},
Expand All @@ -137,7 +153,82 @@ func (r *IncidentWorkflowResource) Schema(ctx context.Context, req resource.Sche
},
},
},
// TODO add expressions to schema, test locally, unit test
"expressions": schema.ListNestedAttribute{
Required: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"else_branch": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
"result": schema.SingleNestedAttribute{
Required: true,
Attributes: paramBindingAttributes,
},
},
},
"id": schema.StringAttribute{
Computed: true,
},
"label": schema.StringAttribute{
Required: true,
},
"operations": schema.ListNestedAttribute{
Required: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"branches": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
"branches": schema.ListNestedAttribute{
Required: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"conditions": conditionsAttribute,
"result": paramBindingsAttribute,
},
},
},
"returns": returnsAttribute,
},
},
"filter": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
"conditions": conditionsAttribute,
},
},
"navigate": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
"reference": schema.StringAttribute{
Required: true,
},
},
},
"operation_type": schema.StringAttribute{
Required: true,
},
"parse": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
"returns": returnsAttribute,
"source": schema.StringAttribute{
Required: true,
},
},
},
},
},
},
"reference": schema.StringAttribute{
Required: true,
},
"root_reference": schema.StringAttribute{
Required: true,
},
},
},
},
},
}
}
Expand Down
10 changes: 9 additions & 1 deletion internal/provider/incident_workflow_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,16 @@ resource "incident_workflow" "example" {
]
}
]
expressions = [
{
"label" = "My Expression"
operations = []
reference = "status"
root_reference = "incident"
}
]
}
`))
`)) // TODO test locally and UT

func incidentWorkflowDefault() workflowTemplateOverrides {
return workflowTemplateOverrides{
Expand Down

0 comments on commit 420ad67

Please sign in to comment.