@@ -13,6 +13,8 @@ import (
13
13
"github.com/hashicorp/terraform-plugin-framework/diag"
14
14
"github.com/hashicorp/terraform-plugin-framework/resource"
15
15
"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"
16
18
17
19
// "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
18
20
// "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
@@ -22,6 +24,7 @@ import (
22
24
// WorkflowJob AAP API model
23
25
type WorkflowJobAPIModel struct {
24
26
TemplateID int64 `json:"workflow_job_template,omitempty"`
27
+ Inventory int64 `json:"inventory,omitempty"`
25
28
Type string `json:"job_type,omitempty"`
26
29
URL string `json:"url,omitempty"`
27
30
Status string `json:"status,omitempty"`
@@ -32,6 +35,7 @@ type WorkflowJobAPIModel struct {
32
35
// WorkflowJobResourceModel maps the resource schema data.
33
36
type WorkflowJobResourceModel struct {
34
37
TemplateID types.Int64 `tfsdk:"workflow_job_template_id"`
38
+ InventoryID types.Int64 `tfsdk:"inventory_id"`
35
39
Type types.String `tfsdk:"job_type"`
36
40
URL types.String `tfsdk:"url"`
37
41
Status types.String `tfsdk:"status"`
@@ -85,6 +89,15 @@ func (r *WorkflowJobResource) Configure(_ context.Context, req resource.Configur
85
89
func (r * WorkflowJobResource ) Schema (_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ) {
86
90
resp .Schema = schema.Schema {
87
91
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
+ },
88
101
"workflow_job_template_id" : schema.Int64Attribute {
89
102
Required : true ,
90
103
Description : "Id of the workflow job template." ,
@@ -209,10 +222,19 @@ func (r WorkflowJobResource) Delete(_ context.Context, _ resource.DeleteRequest,
209
222
// CreateRequestBody creates a JSON encoded request body from the workflow job resource data
210
223
func (r * WorkflowJobResourceModel ) CreateRequestBody () ([]byte , diag.Diagnostics ) {
211
224
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
+ }
212
233
213
234
// Convert workflow job resource data to API data model
214
235
workflowJob := WorkflowJobAPIModel {
215
236
ExtraVars : r .ExtraVars .ValueString (),
237
+ Inventory : inventoryID ,
216
238
}
217
239
218
240
// Create JSON encoded request body
@@ -244,6 +266,7 @@ func (r *WorkflowJobResourceModel) ParseHttpResponse(body []byte) diag.Diagnosti
244
266
r .URL = types .StringValue (resultApiWorkflowJob .URL )
245
267
r .Status = types .StringValue (resultApiWorkflowJob .Status )
246
268
r .TemplateID = types .Int64Value (resultApiWorkflowJob .TemplateID )
269
+ r .InventoryID = types .Int64Value (resultApiWorkflowJob .Inventory )
247
270
diags = r .ParseIgnoredFields (resultApiWorkflowJob .IgnoredFields )
248
271
return diags
249
272
}
0 commit comments