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

r/glue_job - add non_overridable_arguments argument #14793

Merged
merged 5 commits into from
Sep 22, 2020
Merged
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
36 changes: 20 additions & 16 deletions aws/resource_aws_glue_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,19 @@ func resourceAwsGlueJob() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"max_capacity"},
ValidateFunc: validation.StringInSlice([]string{
glue.WorkerTypeG1x,
glue.WorkerTypeG2x,
glue.WorkerTypeStandard,
}, false),
ValidateFunc: validation.StringInSlice(glue.WorkerType_Values(), false),
},
"number_of_workers": {
Type: schema.TypeInt,
Optional: true,
ConflictsWith: []string{"max_capacity"},
ValidateFunc: validation.IntAtLeast(2),
},
"non_overridable_arguments": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
Expand Down Expand Up @@ -176,11 +177,11 @@ func resourceAwsGlueJobCreate(d *schema.ResourceData, meta interface{}) error {
}

if kv, ok := d.GetOk("default_arguments"); ok {
defaultArgumentsMap := make(map[string]string)
for k, v := range kv.(map[string]interface{}) {
defaultArgumentsMap[k] = v.(string)
}
input.DefaultArguments = aws.StringMap(defaultArgumentsMap)
input.DefaultArguments = stringMapToPointers(kv.(map[string]interface{}))
}

if kv, ok := d.GetOk("non_overridable_arguments"); ok {
input.NonOverridableArguments = stringMapToPointers(kv.(map[string]interface{}))
}

if v, ok := d.GetOk("description"); ok {
Expand Down Expand Up @@ -270,6 +271,9 @@ func resourceAwsGlueJobRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("default_arguments", aws.StringValueMap(job.DefaultArguments)); err != nil {
return fmt.Errorf("error setting default_arguments: %s", err)
}
if err := d.Set("non_overridable_arguments", aws.StringValueMap(job.NonOverridableArguments)); err != nil {
return fmt.Errorf("error setting non_overridable_arguments: %w", err)
}
d.Set("description", job.Description)
d.Set("glue_version", job.GlueVersion)
if err := d.Set("execution_property", flattenGlueExecutionProperty(job.ExecutionProperty)); err != nil {
Expand Down Expand Up @@ -309,7 +313,7 @@ func resourceAwsGlueJobUpdate(d *schema.ResourceData, meta interface{}) error {

if d.HasChanges("command", "connections", "default_arguments", "description",
"execution_property", "glue_version", "max_capacity", "max_retries", "notification_property", "number_of_workers",
"role_arn", "security_configuration", "timeout", "worker_type") {
"role_arn", "security_configuration", "timeout", "worker_type", "non_overridable_arguments") {
jobUpdate := &glue.JobUpdate{
Command: expandGlueJobCommand(d.Get("command").([]interface{})),
Role: aws.String(d.Get("role_arn").(string)),
Expand All @@ -331,11 +335,11 @@ func resourceAwsGlueJobUpdate(d *schema.ResourceData, meta interface{}) error {
}

if kv, ok := d.GetOk("default_arguments"); ok {
defaultArgumentsMap := make(map[string]string)
for k, v := range kv.(map[string]interface{}) {
defaultArgumentsMap[k] = v.(string)
}
jobUpdate.DefaultArguments = aws.StringMap(defaultArgumentsMap)
jobUpdate.DefaultArguments = stringMapToPointers(kv.(map[string]interface{}))
}

if kv, ok := d.GetOk("non_overridable_arguments"); ok {
jobUpdate.NonOverridableArguments = stringMapToPointers(kv.(map[string]interface{}))
}

if v, ok := d.GetOk("description"); ok {
Expand Down
85 changes: 85 additions & 0 deletions aws/resource_aws_glue_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestAccAWSGlueJob_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "command.#", "1"),
resource.TestCheckResourceAttr(resourceName, "command.0.script_location", "testscriptlocation"),
resource.TestCheckResourceAttr(resourceName, "default_arguments.%", "0"),
resource.TestCheckResourceAttr(resourceName, "non_overridable_arguments.%", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttrPair(resourceName, "role_arn", roleResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand Down Expand Up @@ -164,6 +165,44 @@ func TestAccAWSGlueJob_DefaultArguments(t *testing.T) {
})
}

func TestAccAWSGlueJob_nonOverridableArguments(t *testing.T) {
var job glue.Job

rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "aws_glue_job.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSGlueJobDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSGlueJobnonOverridableArgumentsConfig(rName, "job-bookmark-disable", "python"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueJobExists(resourceName, &job),
resource.TestCheckResourceAttr(resourceName, "non_overridable_arguments.%", "2"),
resource.TestCheckResourceAttr(resourceName, "non_overridable_arguments.--job-bookmark-option", "job-bookmark-disable"),
resource.TestCheckResourceAttr(resourceName, "non_overridable_arguments.--job-language", "python"),
),
},
{
Config: testAccAWSGlueJobnonOverridableArgumentsConfig(rName, "job-bookmark-enable", "scala"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueJobExists(resourceName, &job),
resource.TestCheckResourceAttr(resourceName, "non_overridable_arguments.%", "2"),
resource.TestCheckResourceAttr(resourceName, "non_overridable_arguments.--job-bookmark-option", "job-bookmark-enable"),
resource.TestCheckResourceAttr(resourceName, "non_overridable_arguments.--job-language", "scala"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSGlueJob_Description(t *testing.T) {
var job glue.Job

Expand Down Expand Up @@ -596,6 +635,29 @@ func TestAccAWSGlueJob_MaxCapacity(t *testing.T) {
})
}

func TestAccAWSGlueJob_disappears(t *testing.T) {
var job glue.Job

rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "aws_glue_job.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSGlueJobDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSGlueJobConfig_Required(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueJobExists(resourceName, &job),
testAccCheckResourceDisappears(testAccProvider, resourceAwsGlueJob(), resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccCheckAWSGlueJobExists(resourceName string, job *glue.Job) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -733,6 +795,29 @@ resource "aws_glue_job" "test" {
`, testAccAWSGlueJobConfig_Base(rName), rName, jobBookmarkOption, jobLanguage)
}

func testAccAWSGlueJobnonOverridableArgumentsConfig(rName, jobBookmarkOption, jobLanguage string) string {
return fmt.Sprintf(`
%s

resource "aws_glue_job" "test" {
max_capacity = 10
name = "%s"
role_arn = aws_iam_role.test.arn

command {
script_location = "testscriptlocation"
}

non_overridable_arguments = {
"--job-bookmark-option" = "%s"
"--job-language" = "%s"
}

depends_on = [aws_iam_role_policy_attachment.test]
}
`, testAccAWSGlueJobConfig_Base(rName), rName, jobBookmarkOption, jobLanguage)
}

func testAccAWSGlueJobConfig_Description(rName, description string) string {
return fmt.Sprintf(`
%s
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/glue_job.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ The following arguments are supported:
* `command` – (Required) The command of the job. Defined below.
* `connections` – (Optional) The list of connections used for this job.
* `default_arguments` – (Optional) The map of default arguments for this job. You can specify arguments here that your own job-execution script consumes, as well as arguments that AWS Glue itself consumes. For information about how to specify and consume your own Job arguments, see the [Calling AWS Glue APIs in Python](http://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-python-calling.html) topic in the developer guide. For information about the key-value pairs that AWS Glue consumes to set up your job, see the [Special Parameters Used by AWS Glue](http://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-python-glue-arguments.html) topic in the developer guide.
* `non_overridable_arguments` – (Optional) Non-overridable arguments for this job, specified as name-value pairs.
* `description` – (Optional) Description of the job.
* `execution_property` – (Optional) Execution property of the job. Defined below.
* `glue_version` - (Optional) The version of glue to use, for example "1.0". For information about available versions, see the [AWS Glue Release Notes](https://docs.aws.amazon.com/glue/latest/dg/release-notes.html).
Expand Down