Skip to content

Commit c3a9dba

Browse files
Merge pull request #42 from maxbirkner/fix-default-value-workflow-job-template-limit
Fix workflow job template's default value for limit field (#15)
2 parents 895fe07 + 54bf2f1 commit c3a9dba

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.7.1
1+
v1.7.2

internal/awx/resource_workflow_job_template.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func resourceWorkflowJobTemplateCreate(ctx context.Context, d *schema.ResourceDa
113113
client := m.(*awx.AWX)
114114
awxService := client.WorkflowJobTemplateService
115115

116-
result, err := awxService.CreateWorkflowJobTemplate(map[string]interface{}{
116+
payload := map[string]interface{}{
117117
"name": d.Get("name").(string),
118118
"description": d.Get("description").(string),
119119
"organization": d.Get("organization_id").(int),
@@ -122,14 +122,23 @@ func resourceWorkflowJobTemplateCreate(ctx context.Context, d *schema.ResourceDa
122122
"survey_enabled": d.Get("survey_enabled").(bool),
123123
"allow_simultaneous": d.Get("allow_simultaneous").(bool),
124124
"ask_variables_on_launch": d.Get("ask_variables_on_launch").(bool),
125-
"limit": d.Get("limit").(string),
126125
"scm_branch": d.Get("scm_branch").(string),
127126
"ask_inventory_on_launch": d.Get("ask_inventory_on_launch").(bool),
128127
"ask_scm_branch_on_launch": d.Get("ask_scm_branch_on_launch").(bool),
129128
"ask_limit_on_launch": d.Get("ask_limit_on_launch").(bool),
130129
"webhook_service": d.Get("webhook_service").(string),
131130
"webhook_credential": d.Get("webhook_credential").(string),
132-
}, map[string]string{})
131+
}
132+
133+
// Workaround limitation mentioned in https://github.com/ansible/awx/issues/12991
134+
limit := d.Get("limit").(string)
135+
if limit == "" {
136+
payload["limit"] = nil
137+
} else {
138+
payload["limit"] = limit
139+
}
140+
141+
result, err := awxService.CreateWorkflowJobTemplate(payload, map[string]string{})
133142
if err != nil {
134143
log.Printf("Fail to Create Template %v", err)
135144
diags = append(diags, diag.Diagnostic{
@@ -156,7 +165,7 @@ func resourceWorkflowJobTemplateUpdate(ctx context.Context, d *schema.ResourceDa
156165
return utils.DiagNotFound("job Workflow template", id, err)
157166
}
158167

159-
if _, err := client.WorkflowJobTemplateService.UpdateWorkflowJobTemplate(id, map[string]interface{}{
168+
payload := map[string]interface{}{
160169
"name": d.Get("name").(string),
161170
"description": d.Get("description").(string),
162171
"organization": d.Get("organization_id").(int),
@@ -165,14 +174,23 @@ func resourceWorkflowJobTemplateUpdate(ctx context.Context, d *schema.ResourceDa
165174
"survey_enabled": d.Get("survey_enabled").(bool),
166175
"allow_simultaneous": d.Get("allow_simultaneous").(bool),
167176
"ask_variables_on_launch": d.Get("ask_variables_on_launch").(bool),
168-
"limit": d.Get("limit").(string),
169177
"scm_branch": d.Get("scm_branch").(string),
170178
"ask_inventory_on_launch": d.Get("ask_inventory_on_launch").(bool),
171179
"ask_scm_branch_on_launch": d.Get("ask_scm_branch_on_launch").(bool),
172180
"ask_limit_on_launch": d.Get("ask_limit_on_launch").(bool),
173181
"webhook_service": d.Get("webhook_service").(string),
174182
"webhook_credential": d.Get("webhook_credential").(string),
175-
}, map[string]string{}); err != nil {
183+
}
184+
185+
// Workaround limitation mentioned in https://github.com/ansible/awx/issues/12991
186+
limit := d.Get("limit").(string)
187+
if limit == "" {
188+
payload["limit"] = nil
189+
} else {
190+
payload["limit"] = limit
191+
}
192+
193+
if _, err := client.WorkflowJobTemplateService.UpdateWorkflowJobTemplate(id, payload, map[string]string{}); err != nil {
176194
return utils.DiagUpdate("Job Workflow template", d.Get("name").(string), err)
177195
}
178196

@@ -232,8 +250,19 @@ func setWorkflowJobTemplateResourceData(d *schema.ResourceData, r *awx.WorkflowJ
232250
if err := d.Set("ask_variables_on_launch", r.AskVariablesOnLaunch); err != nil {
233251
fmt.Println("Error setting ask_variables_on_launch", err)
234252
}
235-
if err := d.Set("limit", r.Limit); err != nil {
236-
fmt.Println("Error setting limit", err)
253+
// Workaround limitation mentioned in https://github.com/ansible/awx/issues/12991
254+
if r.Limit != nil {
255+
if limitStr, ok := r.Limit.(string); ok {
256+
if err := d.Set("limit", limitStr); err != nil {
257+
fmt.Println("Error setting limit", err)
258+
}
259+
} else {
260+
fmt.Println("Error converting limit to string")
261+
}
262+
} else {
263+
if err := d.Set("limit", ""); err != nil {
264+
fmt.Println("Error setting limit", err)
265+
}
237266
}
238267
if err := d.Set("scm_branch", r.ScmBranch); err != nil {
239268
fmt.Println("Error setting scm_branch", err)

0 commit comments

Comments
 (0)