Skip to content

Commit

Permalink
resource/aws_batch_job_queue: Support resource import (#11406)
Browse files Browse the repository at this point in the history
Output from acceptance testing (after upcoming disappears test fix):

```
--- PASS: TestAccAWSBatchJobQueue_disappears (80.44s)
--- PASS: TestAccAWSBatchJobQueue_basic (81.18s)
--- PASS: TestAccAWSBatchJobQueue_update (94.82s)
```
  • Loading branch information
prabusah authored and bflad committed Jan 6, 2020
1 parent 259e0b1 commit c26deb2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
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,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -94,6 +100,11 @@ func TestAccAWSBatchJobQueue_disappears(t *testing.T) {
),
ExpectNonEmptyPlan: true,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
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
```

0 comments on commit c26deb2

Please sign in to comment.