Skip to content

Commit

Permalink
Added job reference flags and new test
Browse files Browse the repository at this point in the history
  • Loading branch information
markotting committed Sep 24, 2024
1 parent 27a6ca2 commit ee9d02c
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 17 deletions.
20 changes: 12 additions & 8 deletions rundeck/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,18 @@ type JobCommandScriptInterpreter struct {

// JobCommandJobRef is a reference to another job that will run as one of the commands of a job.
type JobCommandJobRef struct {
XMLName xml.Name `xml:"jobref"`
Name string `xml:"name,attr"`
GroupName string `xml:"group,attr"`
Project string `xml:"project,attr"`
RunForEachNode bool `xml:"nodeStep,attr"`
Dispatch *JobDispatch `xml:"dispatch,omitempty"`
NodeFilter *JobNodeFilter `xml:"nodefilters,omitempty"`
Arguments JobCommandJobRefArguments `xml:"arg"`
XMLName xml.Name `xml:"jobref"`
Name string `xml:"name,attr"`
GroupName string `xml:"group,attr"`
Project string `xml:"project,attr"`
RunForEachNode bool `xml:"nodeStep,attr"`
Dispatch *JobDispatch `xml:"dispatch,omitempty"`
NodeFilter *JobNodeFilter `xml:"nodefilters,omitempty"`
Arguments JobCommandJobRefArguments `xml:"arg"`
ChildNodes bool `xml:"childNodes,attr"`
FailOnDisable bool `xml:"failOnDisable,attr"`
IgnoreNotifications bool `xml:"ignoreNotifications,attr"`
ImportOptions bool `xml:"importOptions,attr"`
}

// JobCommandJobRefArguments is a string representing the arguments in a JobCommandJobRef.
Expand Down
42 changes: 33 additions & 9 deletions rundeck/resource_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,22 @@ func resourceRundeckJobCommandJob() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"child_nodes": {
Type: schema.TypeBool,
Optional: true,
},
"fail_on_disable": {
Type: schema.TypeBool,
Optional: true,
},
"ignore_notifications": {
Type: schema.TypeBool,
Optional: true,
},
"import_options": {
Type: schema.TypeBool,
Optional: true,
},
"node_filters": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1255,11 +1271,15 @@ func jobCommandJobRefFromResourceData(key string, commandMap map[string]interfac
}
jobRefMap := jobRefsI[0].(map[string]interface{})
jobRef := &JobCommandJobRef{
Name: jobRefMap["name"].(string),
GroupName: jobRefMap["group_name"].(string),
Project: jobRefMap["project_name"].(string),
RunForEachNode: jobRefMap["run_for_each_node"].(bool),
Arguments: JobCommandJobRefArguments(jobRefMap["args"].(string)),
Name: jobRefMap["name"].(string),
GroupName: jobRefMap["group_name"].(string),
Project: jobRefMap["project_name"].(string),
RunForEachNode: jobRefMap["run_for_each_node"].(bool),
Arguments: JobCommandJobRefArguments(jobRefMap["args"].(string)),
ChildNodes: jobRefMap["child_nodes"].(bool),
FailOnDisable: jobRefMap["fail_on_disable"].(bool),
ImportOptions: jobRefMap["import_options"].(bool),
IgnoreNotifications: jobRefMap["ignore_notifications"].(bool),
}
nodeFiltersI := jobRefMap["node_filters"].([]interface{})
if len(nodeFiltersI) > 1 {
Expand Down Expand Up @@ -1355,10 +1375,14 @@ func commandToResourceData(command *JobCommand) (map[string]interface{}, error)

if command.Job != nil {
jobRefConfigI := map[string]interface{}{
"name": command.Job.Name,
"group_name": command.Job.GroupName,
"run_for_each_node": command.Job.RunForEachNode,
"args": command.Job.Arguments,
"name": command.Job.Name,
"group_name": command.Job.GroupName,
"run_for_each_node": command.Job.RunForEachNode,
"args": command.Job.Arguments,
"child_nodes": command.Job.ChildNodes,
"fail_on_disable": command.Job.FailOnDisable,
"import_options": command.Job.ImportOptions,
"ignore_notifications": command.Job.IgnoreNotifications,
}
if command.Job.NodeFilter != nil {
nodeFilterConfigI := map[string]interface{}{
Expand Down
81 changes: 81 additions & 0 deletions rundeck/resource_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ func TestAccJob_cmd_nodefilter(t *testing.T) {
})
}

func TestAccJob_cmd_referred_job(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_referred_job,
Check: resource.ComposeTestCheckFunc(
testAccJobCheckExists("rundeck_job.target_test_job", &job),
func(s *terraform.State) error {
if expected := "target_references_job"; job.Name != expected {
return fmt.Errorf("wrong name; expected %v, got %v", expected, job.Name)
}
return nil
},
),
},
},
})
}

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

Expand Down Expand Up @@ -420,6 +444,63 @@ resource "rundeck_job" "test" {
}
`

const testAccJobConfig_cmd_referred_job = `
resource "rundeck_project" "source_test" {
name = "source_project"
description = "Source project for referred job acceptance tests"
resource_model_source {
type = "file"
config = {
format = "resourcexml"
file = "/tmp/terraform-acc-tests.xml"
}
}
}
resource "rundeck_project" "target_test" {
name = "target_project"
description = "Target project for job acceptance tests"
resource_model_source {
type = "file"
config = {
format = "resourcexml"
file = "/tmp/terraform-acc-tests.xml"
}
}
}
resource "rundeck_job" "source_test_job" {
project_name = "${rundeck_project.source_test.name}"
name = "source_test_job"
description = "A basic job"
execution_enabled = true
option {
name = "foo"
default_value = "bar"
}
}
resource "rundeck_job" "target_test_job" {
project_name = "${rundeck_project.target_test.name}"
name = "target_references_job"
description = "A job referencing another job"
execution_enabled = true
option {
name = "foo"
default_value = "bar"
command {
job {
name = "${rundeck_job.source_test_job.name}"
group_name = "${rundeck_project.target_test.name}"
run_for_each_node = true
child_nodes = true
fail_on_disable = true
ignore_notifications = true
import_options = true
}
}
}
`

const testAccJobConfig_noNodeFilterQuery = `
resource "rundeck_project" "test" {
name = "terraform-acc-test-job-node-filter"
Expand Down

0 comments on commit ee9d02c

Please sign in to comment.