Skip to content

Commit

Permalink
resource/aws_glue_job: Remove deprecated allocated_capacity argument
Browse files Browse the repository at this point in the history
Reference: #7340
Reference: #13398

Output from acceptance testing:

```
--- PASS: TestAccAWSGlueJob_basic (14.45s)
--- PASS: TestAccAWSGlueJob_Description (21.70s)
--- PASS: TestAccAWSGlueJob_GlueVersion (21.74s)
--- PASS: TestAccAWSGlueJob_MaxRetries (21.92s)
--- PASS: TestAccAWSGlueJob_Command (21.95s)
--- PASS: TestAccAWSGlueJob_DefaultArguments (22.08s)
--- PASS: TestAccAWSGlueJob_NotificationProperty (22.10s)
--- PASS: TestAccAWSGlueJob_Timeout (22.13s)
--- PASS: TestAccAWSGlueJob_ExecutionProperty (22.43s)
--- PASS: TestAccAWSGlueJob_MaxCapacity (22.43s)
--- PASS: TestAccAWSGlueJob_SecurityConfiguration (22.48s)
--- PASS: TestAccAWSGlueJob_WorkerType (29.22s)
--- PASS: TestAccAWSGlueJob_Tags (29.29s)
--- PASS: TestAccAWSGlueJob_PythonShell (30.12s)
```
  • Loading branch information
bflad committed Jul 22, 2020
1 parent 2793104 commit 4b939cc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 117 deletions.
28 changes: 4 additions & 24 deletions aws/resource_aws_glue_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ func resourceAwsGlueJob() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"allocated_capacity": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ConflictsWith: []string{"max_capacity", "number_of_workers", "worker_type"},
Deprecated: "Please use attribute `max_capacity' instead. This attribute might be removed in future releases.",
ValidateFunc: validation.IntAtLeast(2),
},
"arn": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -98,7 +90,7 @@ func resourceAwsGlueJob() *schema.Resource {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
ConflictsWith: []string{"allocated_capacity", "number_of_workers", "worker_type"},
ConflictsWith: []string{"number_of_workers", "worker_type"},
},
"max_retries": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -144,7 +136,7 @@ func resourceAwsGlueJob() *schema.Resource {
"worker_type": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"allocated_capacity", "max_capacity"},
ConflictsWith: []string{"max_capacity"},
ValidateFunc: validation.StringInSlice([]string{
glue.WorkerTypeG1x,
glue.WorkerTypeG2x,
Expand All @@ -154,7 +146,7 @@ func resourceAwsGlueJob() *schema.Resource {
"number_of_workers": {
Type: schema.TypeInt,
Optional: true,
ConflictsWith: []string{"allocated_capacity", "max_capacity"},
ConflictsWith: []string{"max_capacity"},
ValidateFunc: validation.IntAtLeast(2),
},
},
Expand All @@ -175,11 +167,6 @@ func resourceAwsGlueJobCreate(d *schema.ResourceData, meta interface{}) error {

if v, ok := d.GetOk("max_capacity"); ok {
input.MaxCapacity = aws.Float64(v.(float64))
} else {
if v, ok := d.GetOk("allocated_capacity"); ok {
input.MaxCapacity = aws.Float64(float64(v.(int)))
log.Printf("[WARN] Using deprecated `allocated_capacity' attribute.")
}
}

if v, ok := d.GetOk("connections"); ok {
Expand Down Expand Up @@ -314,16 +301,13 @@ func resourceAwsGlueJobRead(d *schema.ResourceData, meta interface{}) error {
d.Set("worker_type", job.WorkerType)
d.Set("number_of_workers", int(aws.Int64Value(job.NumberOfWorkers)))

// TODO: Deprecated fields - remove in next major version
d.Set("allocated_capacity", int(aws.Int64Value(job.AllocatedCapacity)))

return nil
}

func resourceAwsGlueJobUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).glueconn

if d.HasChanges("allocated_capacity", "command", "connections", "default_arguments", "description",
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") {
jobUpdate := &glue.JobUpdate{
Expand All @@ -338,10 +322,6 @@ func resourceAwsGlueJobUpdate(d *schema.ResourceData, meta interface{}) error {
if v, ok := d.GetOk("max_capacity"); ok {
jobUpdate.MaxCapacity = aws.Float64(v.(float64))
}
if d.HasChange("allocated_capacity") {
jobUpdate.MaxCapacity = aws.Float64(float64(d.Get("allocated_capacity").(int)))
log.Printf("[WARN] Using deprecated `allocated_capacity' attribute.")
}
}

if v, ok := d.GetOk("connections"); ok {
Expand Down
122 changes: 33 additions & 89 deletions aws/resource_aws_glue_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,44 +90,6 @@ func TestAccAWSGlueJob_basic(t *testing.T) {
})
}

func TestAccAWSGlueJob_AllocatedCapacity(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_AllocatedCapacity(rName, 1),
ExpectError: regexp.MustCompile(`expected allocated_capacity to be at least`),
},
{
Config: testAccAWSGlueJobConfig_AllocatedCapacity(rName, 2),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueJobExists(resourceName, &job),
resource.TestCheckResourceAttr(resourceName, "allocated_capacity", "2"),
),
},
{
Config: testAccAWSGlueJobConfig_AllocatedCapacity(rName, 3),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueJobExists(resourceName, &job),
resource.TestCheckResourceAttr(resourceName, "allocated_capacity", "3"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

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

Expand Down Expand Up @@ -730,32 +692,14 @@ resource "aws_iam_role_policy_attachment" "test" {
`, rName)
}

func testAccAWSGlueJobConfig_AllocatedCapacity(rName string, allocatedCapacity int) string {
return fmt.Sprintf(`
%s
resource "aws_glue_job" "test" {
allocated_capacity = %d
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
command {
script_location = "testscriptlocation"
}
depends_on = ["aws_iam_role_policy_attachment.test"]
}
`, testAccAWSGlueJobConfig_Base(rName), allocatedCapacity, rName)
}

func testAccAWSGlueJobConfig_Command(rName, scriptLocation string) string {
return fmt.Sprintf(`
%s
resource "aws_glue_job" "test" {
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
allocated_capacity = 10
max_capacity = 10
name = "%s"
role_arn = aws_iam_role.test.arn
command {
script_location = "%s"
Expand All @@ -771,9 +715,9 @@ func testAccAWSGlueJobConfig_DefaultArguments(rName, jobBookmarkOption, jobLangu
%s
resource "aws_glue_job" "test" {
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
allocated_capacity = 10
max_capacity = 10
name = "%s"
role_arn = aws_iam_role.test.arn
command {
script_location = "testscriptlocation"
Expand All @@ -794,10 +738,10 @@ func testAccAWSGlueJobConfig_Description(rName, description string) string {
%s
resource "aws_glue_job" "test" {
description = "%s"
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
allocated_capacity = 10
description = "%s"
max_capacity = 10
name = "%s"
role_arn = aws_iam_role.test.arn
command {
script_location = "testscriptlocation"
Expand All @@ -813,10 +757,10 @@ func testAccAWSGlueJobConfig_GlueVersion(rName, glueVersion string) string {
%s
resource "aws_glue_job" "test" {
glue_version = "%s"
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
allocated_capacity = 10
glue_version = "%s"
max_capacity = 10
name = "%s"
role_arn = aws_iam_role.test.arn
command {
script_location = "testscriptlocation"
Expand All @@ -832,9 +776,9 @@ func testAccAWSGlueJobConfig_ExecutionProperty(rName string, maxConcurrentRuns i
%s
resource "aws_glue_job" "test" {
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
allocated_capacity = 10
max_capacity = 10
name = "%s"
role_arn = aws_iam_role.test.arn
command {
script_location = "testscriptlocation"
Expand All @@ -854,10 +798,10 @@ func testAccAWSGlueJobConfig_MaxRetries(rName string, maxRetries int) string {
%s
resource "aws_glue_job" "test" {
max_retries = %d
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
allocated_capacity = 10
max_capacity = 10
max_retries = %d
name = "%s"
role_arn = aws_iam_role.test.arn
command {
script_location = "testscriptlocation"
Expand All @@ -873,9 +817,9 @@ func testAccAWSGlueJobConfig_NotificationProperty(rName string, notifyDelayAfter
%s
resource "aws_glue_job" "test" {
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
allocated_capacity = 10
max_capacity = 10
name = "%s"
role_arn = aws_iam_role.test.arn
command {
script_location = "testscriptlocation"
Expand All @@ -895,9 +839,9 @@ func testAccAWSGlueJobConfig_Required(rName string) string {
%s
resource "aws_glue_job" "test" {
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
allocated_capacity = 10
max_capacity = 10
name = "%s"
role_arn = aws_iam_role.test.arn
command {
script_location = "testscriptlocation"
Expand Down Expand Up @@ -956,10 +900,10 @@ func testAccAWSGlueJobConfig_Timeout(rName string, timeout int) string {
%s
resource "aws_glue_job" "test" {
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
timeout = %d
allocated_capacity = 10
max_capacity = 10
name = "%s"
role_arn = aws_iam_role.test.arn
timeout = %d
command {
script_location = "testscriptlocation"
Expand All @@ -975,10 +919,10 @@ func testAccAWSGlueJobConfig_SecurityConfiguration(rName string, securityConfigu
%s
resource "aws_glue_job" "test" {
max_capacity = 10
name = "%s"
role_arn = "${aws_iam_role.test.arn}"
role_arn = aws_iam_role.test.arn
security_configuration = "%s"
allocated_capacity = 10
command {
script_location = "testscriptlocation"
Expand Down
27 changes: 27 additions & 0 deletions website/docs/guides/version-3-upgrade.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Upgrade topics:
- [Resource: aws_dx_gateway](#resource-aws_dx_gateway)
- [Resource: aws_elastic_transcoder_preset](#resource-aws_elastic_transcoder_preset)
- [Resource: aws_emr_cluster](#resource-aws_emr_cluster)
- [Resource: aws_glue_job](#resource-aws_glue_job)
- [Resource: aws_lambda_alias](#resource-aws_lambda_alias)
- [Resource: aws_launch_template](#resource-aws_launch_template)
- [Resource: aws_lb_listener_rule](#resource-aws_lb_listener_rule)
Expand Down Expand Up @@ -386,6 +387,32 @@ resource "aws_emr_cluster" "example" {
}
```

## Resource: aws_glue_job

### allocated_capacity Argument Removal

The Glue API has deprecated the `allocated_capacity` argument. Switch your Terraform configuration to the `max_capacity` argument instead.

For example, given this previous configuration:

```hcl
resource "aws_glue_job" "example" {
# ... other configuration ...
allocated_capacity = 2
}
```

An updated configuration:

```hcl
resource "aws_glue_job" "example" {
# ... other configuration ...
max_capacity = 2
}
```

## Resource: aws_lambda_alias

### Import No Longer Converts Function Name to ARN
Expand Down
4 changes: 0 additions & 4 deletions website/docs/r/glue_job.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ resource "aws_glue_job" "example" {

The following arguments are supported:

~> **NOTE:** The `allocated_capacity` attribute has been deprecated and might
be removed in future releases, please use `max_capacity` instead.

* `allocated_capacity`**DEPRECATED** (Optional) The number of AWS Glue data processing units (DPUs) to allocate to this Job. At least 2 DPUs need to be allocated; the default is 10. A DPU is a relative measure of processing power that consists of 4 vCPUs of compute capacity and 16 GB of memory.
* `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.
Expand Down

0 comments on commit 4b939cc

Please sign in to comment.