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 import support for aws_batch_job_queue #11406

Merged
merged 3 commits into from
Jan 6, 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
9 changes: 8 additions & 1 deletion aws/resource_aws_batch_job_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func resourceAwsBatchJobQueue() *schema.Resource {
Update: resourceAwsBatchJobQueueUpdate,
Delete: resourceAwsBatchJobQueueDelete,

Importer: &schema.ResourceImporter{
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
d.Set("arn", d.Id())
return []*schema.ResourceData{d}, nil
},
},

Schema: map[string]*schema.Schema{
"compute_environments": {
Type: schema.TypeList,
Expand Down Expand Up @@ -86,7 +93,7 @@ func resourceAwsBatchJobQueueCreate(d *schema.ResourceData, meta interface{}) er
func resourceAwsBatchJobQueueRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).batchconn

jq, err := getJobQueue(conn, d.Get("name").(string))
jq, err := getJobQueue(conn, d.Id())
if err != nil {
return err
}
Expand Down
23 changes: 20 additions & 3 deletions aws/resource_aws_batch_job_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestAccAWSBatchJobQueue_basic(t *testing.T) {
var jq batch.JobQueueDetail
ri := acctest.RandInt()
config := fmt.Sprintf(testAccBatchJobQueueBasic, ri)
resourceName := "aws_batch_job_queue.test_queue"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSBatch(t) },
Providers: testAccProviders,
Expand All @@ -68,10 +69,15 @@ func TestAccAWSBatchJobQueue_basic(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckBatchJobQueueExists("aws_batch_job_queue.test_queue", &jq),
testAccCheckBatchJobQueueExists(resourceName, &jq),
testAccCheckBatchJobQueueAttributes(&jq),
),
},
{
ResourceName: resourceName,
ImportState: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new acceptance testing is currently failing for this test and the others:

--- FAIL: TestAccAWSBatchJobQueue_basic (71.48s)
    testing.go:640: Step 1 error: : Provided name  is not supported pattern[a-zA-Z_0-9-]{1,128}
        	status code: 400, request id: fb70a8c2-e8e2-4417-a94e-7f357fda0ebe

This is happening because the resource Read function is dependent on the name attribute being set:

https://github.com/terraform-providers/terraform-provider-aws/blob/b4a971dfc9db81c20df443b0274f2893a976a30c/aws/resource_aws_batch_job_queue.go#L89

The easiest fix here should be to use the resource ID instead of trying to read the name attribute, since the Batch DescribeJobQueues API notes support for full ARN in addition to just the name, e.g.

jq, err := getJobQueue(conn, d.Id())

ImportStateVerify: true,
},
},
})
}
Expand All @@ -94,6 +100,11 @@ func TestAccAWSBatchJobQueue_disappears(t *testing.T) {
),
ExpectNonEmptyPlan: true,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
Comment on lines +103 to +107
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since _disappears tests are removing the resource in question to verify Terraform triggers recreation of the resource instead of an error, these tests will generate the below error when trying to do ImportState testing:

--- FAIL: TestAccAWSBatchJobQueue_disappears (80.44s)
    testing.go:640: Step 1 error: Resource specified by ResourceName couldn't be found: aws_batch_job_queue.test_queue

The solution here is just to not include the import testing in "disappears" tests like these. 👍

},
})
}
Expand All @@ -103,6 +114,7 @@ func TestAccAWSBatchJobQueue_update(t *testing.T) {
ri := acctest.RandInt()
config := fmt.Sprintf(testAccBatchJobQueueBasic, ri)
updateConfig := fmt.Sprintf(testAccBatchJobQueueUpdate, ri)
resourceName := "aws_batch_job_queue.test_queue"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSBatch(t) },
Providers: testAccProviders,
Expand All @@ -111,17 +123,22 @@ func TestAccAWSBatchJobQueue_update(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckBatchJobQueueExists("aws_batch_job_queue.test_queue", &jq),
testAccCheckBatchJobQueueExists(resourceName, &jq),
testAccCheckBatchJobQueueAttributes(&jq),
),
},
{
Config: updateConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckBatchJobQueueExists("aws_batch_job_queue.test_queue", &jq),
testAccCheckBatchJobQueueExists(resourceName, &jq),
testAccCheckBatchJobQueueAttributes(&jq),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/batch_job_queue.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `arn` - The Amazon Resource Name of the job queue.

## Import

Batch Job Queue can be imported using the `arn`, e.g.

```
$ terraform import aws_batch_job_queue.test_queue arn:aws:batch:us-east-1:123456789012:job-queue/sample
```