Skip to content

Commit 389da44

Browse files
committed
Added testing to workflow and workflow job template
1 parent 873574c commit 389da44

File tree

3 files changed

+618
-0
lines changed

3 files changed

+618
-0
lines changed

internal/provider/workflow_job_resource.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"github.com/hashicorp/terraform-plugin-framework/diag"
1414
"github.com/hashicorp/terraform-plugin-framework/resource"
1515
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
16+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
17+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1618

1719
// "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
1820
// "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
@@ -22,6 +24,7 @@ import (
2224
// WorkflowJob AAP API model
2325
type WorkflowJobAPIModel struct {
2426
TemplateID int64 `json:"workflow_job_template,omitempty"`
27+
Inventory int64 `json:"inventory,omitempty"`
2528
Type string `json:"job_type,omitempty"`
2629
URL string `json:"url,omitempty"`
2730
Status string `json:"status,omitempty"`
@@ -32,6 +35,7 @@ type WorkflowJobAPIModel struct {
3235
// WorkflowJobResourceModel maps the resource schema data.
3336
type WorkflowJobResourceModel struct {
3437
TemplateID types.Int64 `tfsdk:"workflow_job_template_id"`
38+
InventoryID types.Int64 `tfsdk:"inventory_id"`
3539
Type types.String `tfsdk:"job_type"`
3640
URL types.String `tfsdk:"url"`
3741
Status types.String `tfsdk:"status"`
@@ -85,6 +89,15 @@ func (r *WorkflowJobResource) Configure(_ context.Context, req resource.Configur
8589
func (r *WorkflowJobResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
8690
resp.Schema = schema.Schema{
8791
Attributes: map[string]schema.Attribute{
92+
"inventory_id": schema.Int64Attribute{
93+
Optional: true,
94+
Computed: true,
95+
PlanModifiers: []planmodifier.Int64{
96+
int64planmodifier.UseStateForUnknown(),
97+
},
98+
Description: "Identifier for the inventory where job should be created in. " +
99+
"If not provided, the job will be created in the default inventory.",
100+
},
88101
"workflow_job_template_id": schema.Int64Attribute{
89102
Required: true,
90103
Description: "Id of the workflow job template.",
@@ -209,10 +222,19 @@ func (r WorkflowJobResource) Delete(_ context.Context, _ resource.DeleteRequest,
209222
// CreateRequestBody creates a JSON encoded request body from the workflow job resource data
210223
func (r *WorkflowJobResourceModel) CreateRequestBody() ([]byte, diag.Diagnostics) {
211224
var diags diag.Diagnostics
225+
var inventoryID int64
226+
227+
// Use default inventory if not provided
228+
if r.InventoryID.ValueInt64() == 0 {
229+
inventoryID = 1
230+
} else {
231+
inventoryID = r.InventoryID.ValueInt64()
232+
}
212233

213234
// Convert workflow job resource data to API data model
214235
workflowJob := WorkflowJobAPIModel{
215236
ExtraVars: r.ExtraVars.ValueString(),
237+
Inventory: inventoryID,
216238
}
217239

218240
// Create JSON encoded request body
@@ -244,6 +266,7 @@ func (r *WorkflowJobResourceModel) ParseHttpResponse(body []byte) diag.Diagnosti
244266
r.URL = types.StringValue(resultApiWorkflowJob.URL)
245267
r.Status = types.StringValue(resultApiWorkflowJob.Status)
246268
r.TemplateID = types.Int64Value(resultApiWorkflowJob.TemplateID)
269+
r.InventoryID = types.Int64Value(resultApiWorkflowJob.Inventory)
247270
diags = r.ParseIgnoredFields(resultApiWorkflowJob.IgnoredFields)
248271
return diags
249272
}

0 commit comments

Comments
 (0)