Skip to content

Commit 3e4ab25

Browse files
jnaheloudenouche
authored andcommitted
feat(resource_job_template_launch): add extra_vars option
1 parent abe120c commit 3e4ab25

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

awx/resource_job_template_launch.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ func resourceJobTemplateLaunch() *schema.Resource {
6969
Description: "Override Inventory ID. Required ask_inventory_on_launch set on job_template.",
7070
ForceNew: true,
7171
},
72+
"extra_vars": {
73+
Type: schema.TypeString,
74+
Optional: true,
75+
Description: "Override job template variables. Only JSON content is supported yet.",
76+
ForceNew: true,
77+
},
7278
"wait_for_completion": {
7379
Type: schema.TypeBool,
7480
Required: false,
@@ -106,8 +112,9 @@ func jobTemplateLaunchWait(ctx context.Context, svc *awx.JobService, job *awx.Jo
106112

107113
// JobTemplateLaunchData provides payload data used by the JobTemplateLaunch method
108114
type JobTemplateLaunchData struct {
109-
Limit string `json:"limit,omitempty"`
110-
Inventory int `json:"inventory,omitempty"`
115+
Limit string `json:"limit,omitempty"`
116+
Inventory int `json:"inventory,omitempty"`
117+
ExtraVars map[string]interface{} `json:"extra_vars,omitempty"`
111118
}
112119

113120
func resourceJobTemplateLaunchCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -122,9 +129,21 @@ func resourceJobTemplateLaunchCreate(ctx context.Context, d *schema.ResourceData
122129
return buildDiagNotFoundFail("job template", jobTemplateID, err)
123130
}
124131

132+
var iExtraVars map[string]interface{}
133+
err = json.Unmarshal([]byte(d.Get("extra_vars").(string)), &iExtraVars)
134+
if err != nil {
135+
diags = append(diags, diag.Diagnostic{
136+
Severity: diag.Error,
137+
Summary: "Failed to decode extra_vars",
138+
Detail: fmt.Sprintf("JobTemplateLaunch with template ID %d, failed to decode extra_vars %s", d.Get("job_template_id").(int), err.Error()),
139+
})
140+
return diags
141+
}
142+
125143
data := JobTemplateLaunchData{
126144
Limit: d.Get("limit").(string),
127145
Inventory: d.Get("inventory").(int),
146+
ExtraVars: iExtraVars,
128147
}
129148

130149
var iData map[string]interface{}

0 commit comments

Comments
 (0)