Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setting options types (file or text) #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rundeck/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ type JobOption struct {

// Option should be hidden from job run page
Hidden bool `xml:"hidden,omitempty"`

// Type of the option. One of: text, file
Type string `xml:"type,attr,omitempty"`
}

// JobValueChoices is a specialization of []string representing a sequence of predefined values
Expand Down
13 changes: 13 additions & 0 deletions rundeck/resource_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ func resourceRundeckJob() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
Default: "text",
},
},
},
},
Expand Down Expand Up @@ -820,6 +825,7 @@ func jobFromResourceData(d *schema.ResourceData) (*JobDetail, error) {
ValueIsExposedToScripts: optionMap["exposed_to_scripts"].(bool),
StoragePath: optionMap["storage_path"].(string),
Hidden: optionMap["hidden"].(bool),
Type: optionMap["type"].(string),
}
if option.StoragePath != "" && !option.ObscureInput {
return nil, fmt.Errorf("argument \"obscure_input\" must be set to `true` when \"storage_path\" is not empty")
Expand All @@ -835,6 +841,9 @@ func jobFromResourceData(d *schema.ResourceData) (*JobDetail, error) {
option.ValueChoices = append(option.ValueChoices, iv.(string))
}

if option.Type != "" && option.Type != "text" && option.Type != "file" {
return nil, fmt.Errorf("argument \"type\" cannot have \"%s\" as a value; allowed values: \"text\", \"file\"", option.Type)
}
optionsConfig.Options = append(optionsConfig.Options, option)
}
job.OptionsConfig = optionsConfig
Expand Down Expand Up @@ -1065,6 +1074,10 @@ func jobToResourceData(job *JobDetail, d *schema.ResourceData) error {
"exposed_to_scripts": option.ValueIsExposedToScripts,
"storage_path": option.StoragePath,
"hidden": option.Hidden,
"type": option.Type,
}
if optionConfigI["type"] == "" {
optionConfigI["type"] = "text"
}
optionConfigsI = append(optionConfigsI, optionConfigI)
}
Expand Down
74 changes: 74 additions & 0 deletions rundeck/resource_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,39 @@ func TestAccJobOptions_secure_choice(t *testing.T) {
})
}

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccJobCheckDestroy(&job),
Steps: []resource.TestStep{
{
Config: testAccJobOptions_option_type,
Check: resource.ComposeTestCheckFunc(
testAccJobCheckExists("rundeck_job.test", &job),
func(s *terraform.State) error {
fileOption := job.OptionsConfig.Options[0]
if expected := "file"; fileOption.Type != expected {
return fmt.Errorf("wrong option type; expected %v, got %v", expected, fileOption.Type)
}
filenameOption := job.OptionsConfig.Options[1]
if expected := "text"; filenameOption.Type != expected {
return fmt.Errorf("wrong option type; expected %v, got %v", expected, filenameOption.Type)
}
fileextensionOption := job.OptionsConfig.Options[2]
if expected := "text"; fileextensionOption.Type != expected {
return fmt.Errorf("wrong option type; expected %v, got %v", expected, fileextensionOption.Type)
}
return nil
},
),
},
},
})
}

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

Expand Down Expand Up @@ -702,6 +735,47 @@ resource "rundeck_job" "test" {
}
`

const testAccJobOptions_option_type = `
resource "rundeck_project" "test" {
name = "terraform-acc-test-job-option-option-type"
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"
description = "A basic job"

preserve_options_order = true

option {
name = "input_file"
type = "file"
}

option {
name = "output_file_name"
}

option {
name = "output_file_extension"
type = "text"
}

command {
description = "Prints the contents of the input file"
shell_command = "cat $${file.input_file} > $${option.output_file_name}.$${option.output_file_extension}"
}
}
`

const testOchestration_maxperecent = `
resource "rundeck_project" "test" {
name = "terraform-acc-test-job"
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/job.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ The following arguments are supported:
* `hidden`: (Optional) Boolean controlling whether this option should be hidden from the UI on the job run page.
Defaults to `false`.

* `type`: (Optional) Option type. One of: `file`, `text`. Defaults to `text`.

`command` blocks must have any one of the following combinations of arguments as contents:

* `description`: (Optional) gives a description to the command block.
Expand Down Expand Up @@ -342,4 +344,4 @@ Rundeck job can be imported using the project and job uuid, e.g.
$ terraform import rundeck_job.my_job project_name/JOB-UUID
```

It is also possible to use `import` blocks to generate job config from existing jobs. [See Hashi Docs here](https://developer.hashicorp.com/terraform/language/import/generating-configuration)
It is also possible to use `import` blocks to generate job config from existing jobs. [See Hashi Docs here](https://developer.hashicorp.com/terraform/language/import/generating-configuration)