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_definition #11407

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions aws/resource_aws_batch_job_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ func resourceAwsBatchJobDefinition() *schema.Resource {
Read: resourceAwsBatchJobDefinitionRead,
Delete: resourceAwsBatchJobDefinitionDelete,

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{
"name": {
Type: schema.TypeString,
Expand Down
18 changes: 15 additions & 3 deletions aws/resource_aws_batch_job_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestAccAWSBatchJobDefinition_basic(t *testing.T) {
}
ri := acctest.RandInt()
config := fmt.Sprintf(testAccBatchJobDefinitionBaseConfig, ri)
resourceName := "aws_batch_job_definition.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSBatch(t) },
Providers: testAccProviders,
Expand All @@ -59,10 +60,15 @@ func TestAccAWSBatchJobDefinition_basic(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckBatchJobDefinitionExists("aws_batch_job_definition.test", &jd),
testAccCheckBatchJobDefinitionExists(resourceName, &jd),
testAccCheckBatchJobDefinitionAttributes(&jd, &compare),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -73,6 +79,7 @@ func TestAccAWSBatchJobDefinition_updateForcesNewResource(t *testing.T) {
ri := acctest.RandInt()
config := fmt.Sprintf(testAccBatchJobDefinitionBaseConfig, ri)
updateConfig := fmt.Sprintf(testAccBatchJobDefinitionUpdateConfig, ri)
resourceName := "aws_batch_job_definition.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSBatch(t) },
Providers: testAccProviders,
Expand All @@ -81,17 +88,22 @@ func TestAccAWSBatchJobDefinition_updateForcesNewResource(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckBatchJobDefinitionExists("aws_batch_job_definition.test", &before),
testAccCheckBatchJobDefinitionExists(resourceName, &before),
testAccCheckBatchJobDefinitionAttributes(&before, nil),
),
},
{
Config: updateConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckBatchJobDefinitionExists("aws_batch_job_definition.test", &after),
testAccCheckBatchJobDefinitionExists(resourceName, &after),
testAccCheckJobDefinitionRecreated(t, &before, &after),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
7 changes: 7 additions & 0 deletions 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{
Copy link
Contributor

@bflad bflad Jan 2, 2020

Choose a reason for hiding this comment

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

Please note: This pull request currently contains the changes from #11406, which needs adjustments. If the aws_batch_job_queue changes are removed from this pull request, we can likely get the aws_batch_job_definition changes (which look okay at first glance) merged sooner. 👍

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
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_definition.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ In addition to all arguments above, the following attributes are exported:

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

## Import

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

```
$ terraform import aws_batch_job_definition.test arn:aws:batch:us-east-1:123456789012:job-definition/sample
```
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
```