diff --git a/aws/resource_aws_batch_job_definition.go b/aws/resource_aws_batch_job_definition.go index e4eac2109e3..715c7d2bbdc 100644 --- a/aws/resource_aws_batch_job_definition.go +++ b/aws/resource_aws_batch_job_definition.go @@ -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, diff --git a/aws/resource_aws_batch_job_definition_test.go b/aws/resource_aws_batch_job_definition_test.go index 52f4d15fe44..7b1609941ae 100644 --- a/aws/resource_aws_batch_job_definition_test.go +++ b/aws/resource_aws_batch_job_definition_test.go @@ -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, @@ -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, + }, }, }) } @@ -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, @@ -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, + }, }, }) } diff --git a/aws/resource_aws_batch_job_queue_test.go b/aws/resource_aws_batch_job_queue_test.go index 931ccfebd74..fc9e4f87141 100644 --- a/aws/resource_aws_batch_job_queue_test.go +++ b/aws/resource_aws_batch_job_queue_test.go @@ -100,6 +100,11 @@ func TestAccAWSBatchJobQueue_disappears(t *testing.T) { ), ExpectNonEmptyPlan: true, }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } diff --git a/website/docs/r/batch_job_definition.html.markdown b/website/docs/r/batch_job_definition.html.markdown index 3d805b7c287..8ac612f6abd 100644 --- a/website/docs/r/batch_job_definition.html.markdown +++ b/website/docs/r/batch_job_definition.html.markdown @@ -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 +``` \ No newline at end of file