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 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
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 @@ -20,6 +20,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
19 changes: 15 additions & 4 deletions aws/resource_aws_batch_job_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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 @@ -60,11 +61,15 @@ func TestAccAWSBatchJobDefinition_basic(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckBatchJobDefinitionExists("aws_batch_job_definition.test", &jd),
resource.TestCheckResourceAttr("aws_batch_job_definition.test", "name", fmt.Sprintf("tf_acctest_batch_job_definition_%d", ri)),
testAccCheckBatchJobDefinitionExists(resourceName, &jd),
testAccCheckBatchJobDefinitionAttributes(&jd, &compare),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -75,6 +80,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 @@ -83,17 +89,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
5 changes: 5 additions & 0 deletions aws/resource_aws_batch_job_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func TestAccAWSBatchJobQueue_disappears(t *testing.T) {
),
ExpectNonEmptyPlan: true,
},
{
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
```