Skip to content

Commit 6c4f141

Browse files
authored
fix(resource_job_template_launch): rename inventory to inventory_id and add support for yaml variables (#59)
1 parent 271a682 commit 6c4f141

1 file changed

Lines changed: 11 additions & 21 deletions

File tree

awx/resource_job_template_launch.go

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,20 @@ func resourceJobTemplateLaunch() *schema.Resource {
6161
ForceNew: true,
6262
Description: "List of comma delimited hosts to limit job execution. Required ask_limit_on_launch set on job_template.",
6363
},
64-
"inventory": {
64+
"inventory_id": {
6565
Type: schema.TypeInt,
6666
Required: false,
6767
Optional: true,
68-
Default: "",
68+
Computed: true,
6969
Description: "Override Inventory ID. Required ask_inventory_on_launch set on job_template.",
7070
ForceNew: true,
7171
},
7272
"extra_vars": {
7373
Type: schema.TypeString,
7474
Optional: true,
75-
Description: "Override job template variables. Only JSON content is supported yet.",
75+
Description: "Override job template variables. YAML or JSON values are supported.",
7676
ForceNew: true,
77+
StateFunc: normalizeJsonYaml,
7778
},
7879
"wait_for_completion": {
7980
Type: schema.TypeBool,
@@ -112,9 +113,9 @@ func jobTemplateLaunchWait(ctx context.Context, svc *awx.JobService, job *awx.Jo
112113

113114
// JobTemplateLaunchData provides payload data used by the JobTemplateLaunch method
114115
type JobTemplateLaunchData struct {
115-
Limit string `json:"limit,omitempty"`
116-
Inventory int `json:"inventory,omitempty"`
117-
ExtraVars map[string]interface{} `json:"extra_vars,omitempty"`
116+
Limit string `json:"limit,omitempty"`
117+
InventoryID int `json:"inventory,omitempty"`
118+
ExtraVars string `json:"extra_vars,omitempty"`
118119
}
119120

120121
func resourceJobTemplateLaunchCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -129,21 +130,10 @@ func resourceJobTemplateLaunchCreate(ctx context.Context, d *schema.ResourceData
129130
return buildDiagNotFoundFail("job template", jobTemplateID, err)
130131
}
131132

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-
143133
data := JobTemplateLaunchData{
144-
Limit: d.Get("limit").(string),
145-
Inventory: d.Get("inventory").(int),
146-
ExtraVars: iExtraVars,
134+
Limit: d.Get("limit").(string),
135+
InventoryID: d.Get("inventory_id").(int),
136+
ExtraVars: d.Get("extra_vars").(string),
147137
}
148138

149139
var iData map[string]interface{}
@@ -170,7 +160,7 @@ func resourceJobTemplateLaunchCreate(ctx context.Context, d *schema.ResourceData
170160
diags = append(diags, diag.Diagnostic{
171161
Severity: diag.Error,
172162
Summary: "JobTemplate execution failure",
173-
Detail: fmt.Sprintf("JobTemplateLaunch with template ID %d, failed to complete %s", d.Get("job_template_id").(int), err.Error()),
163+
Detail: fmt.Sprintf("JobTemplateLaunch with ID %d and template ID %d, failed to complete %s", res.ID, d.Get("job_template_id").(int), err.Error()),
174164
})
175165
}
176166
}

0 commit comments

Comments
 (0)