Skip to content

Commit

Permalink
Allow overriding of job node filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Moultrie authored and ProTip committed Aug 2, 2019
1 parent 562f24a commit bebe52c
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
26 changes: 26 additions & 0 deletions rundeck/resource_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,22 @@ func resourceRundeckJob() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"nodefilters": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"excludeprecedence": {
Type: schema.TypeString,
Optional: true,
},
"filter": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -451,6 +467,15 @@ func jobFromResourceData(d *schema.ResourceData) (*JobDetail, error) {
GroupName: jobRefMap["group_name"].(string),
RunForEachNode: jobRefMap["run_for_each_node"].(bool),
Arguments: JobCommandJobRefArguments(jobRefMap["args"].(string)),
NodeFilter: &JobNodeFilter{},
//NodeFilter: jobRefMap["nodefilters"].(map[string]interface{}),
}
nodeFilterMap := jobRefMap["nodefilters"].(map[string]interface{})
if nodeFilterMap["filter"] != nil {
command.Job.NodeFilter.Query = nodeFilterMap["filter"].(string)
}
if nodeFilterMap["excludeprecedence"] != nil {
command.Job.NodeFilter.ExcludePrecedence = nodeFilterMap["excludeprecedence"].(bool)
}
}

Expand Down Expand Up @@ -730,6 +755,7 @@ func jobToResourceData(job *JobDetail, d *schema.ResourceData) error {
"group_name": command.Job.GroupName,
"run_for_each_node": command.Job.RunForEachNode,
"args": command.Job.Arguments,
"nodefilters": command.Job.NodeFilter,
},
}
}
Expand Down
75 changes: 75 additions & 0 deletions rundeck/resource_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,33 @@ func TestAccJob_basic(t *testing.T) {
})
}

func TestAccJob_cmd_nodefilter(t *testing.T) {
var job JobDetail

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccJobCheckDestroy(&job),
Steps: []resource.TestStep{
{
Config: testAccJobConfig_cmd_nodefilter,
Check: resource.ComposeTestCheckFunc(
testAccJobCheckExists("rundeck_job.test", &job),
func(s *terraform.State) error {
if expected := "basic-job-with-node-filter"; job.Name != expected {
return fmt.Errorf("wrong name; expected %v, got %v", expected, job.Name)
}
if expected := "name: tacobell"; job.CommandSequence.Commands[0].Job.NodeFilter.Query != expected {
return fmt.Errorf("failed to set job node filter; expected %v, got %v", expected, job.CommandSequence.Commands[0].Job.NodeFilter.Query)
}
return nil
},
),
},
},
})
}

func TestAccJob_Idempotency(t *testing.T) {
var job JobDetail

Expand Down Expand Up @@ -179,6 +206,54 @@ resource "rundeck_job" "test" {
}
`

const testAccJobConfig_cmd_nodefilter = `
resource "rundeck_project" "test" {
name = "terraform-acc-test-job"
description = "parent project for job acceptance tests"
resource_model_source {
type = "file"
config = {
format = "resourcexml"
file = "/tmp/terraform-acc-tests.xml"
}
}
}
resource "rundeck_job" "test" {
project_name = "${rundeck_project.test.name}"
name = "basic-job-with-node-filter"
description = "A basic job"
execution_enabled = true
node_filter_query = "example"
allow_concurrent_executions = true
max_thread_count = 1
rank_order = "ascending"
schedule = "0 0 12 * * * *"
schedule_enabled = true
option {
name = "foo"
default_value = "bar"
}
command {
job {
name = "Other Job Name"
run_for_each_node = true
nodefilters = {
filter: "name: tacobell"
}
}
description = "Prints Hello World"
shell_command = "echo Hello World"
}
notification {
type = "on_success"
email {
recipients = ["[email protected]"]
}
}
}
`

const testAccJobConfig_noNodeFilterQuery = `
resource "rundeck_project" "test" {
name = "terraform-acc-test-job-node-filter"
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/job.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ A command's `job` block has the following structure:

* `args`: (Optional) A string giving the arguments to pass to the target job, using
[Rundeck's job arguments syntax](http://rundeck.org/docs/manual/jobs.html#job-reference-step).

* `nodefilters`: (Optional) A map for overriding the referenced job's node filters.

A command's `nodefilters` block has the following structure:

* `excludeprecedence`: (Optional) Whether to exclude precedence or not.

* `filter`: (Optional) The node filter query string to use.

A command's `step_plugin` or `node_step_plugin` block both have the following structure:

Expand Down

0 comments on commit bebe52c

Please sign in to comment.