From f3732ded25d7feef978378f1684fe29bb033ab58 Mon Sep 17 00:00:00 2001 From: prabusah Date: Sat, 21 Dec 2019 23:17:47 -0600 Subject: [PATCH 1/3] Add import support for aws_batch_job_queue #11207 --- aws/resource_aws_batch_job_queue.go | 7 ++++++ aws/resource_aws_batch_job_queue_test.go | 23 +++++++++++++++++--- website/docs/r/batch_job_queue.html.markdown | 8 +++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_batch_job_queue.go b/aws/resource_aws_batch_job_queue.go index 65e4ab0d7bf..b0e42f1d818 100644 --- a/aws/resource_aws_batch_job_queue.go +++ b/aws/resource_aws_batch_job_queue.go @@ -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, diff --git a/aws/resource_aws_batch_job_queue_test.go b/aws/resource_aws_batch_job_queue_test.go index 5fb3e6d5c24..fc9e4f87141 100644 --- a/aws/resource_aws_batch_job_queue_test.go +++ b/aws/resource_aws_batch_job_queue_test.go @@ -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, @@ -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, + }, }, }) } @@ -94,6 +100,11 @@ func TestAccAWSBatchJobQueue_disappears(t *testing.T) { ), ExpectNonEmptyPlan: true, }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -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, @@ -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, + }, }, }) } diff --git a/website/docs/r/batch_job_queue.html.markdown b/website/docs/r/batch_job_queue.html.markdown index 4fccf4cdb00..093cbfd1802 100644 --- a/website/docs/r/batch_job_queue.html.markdown +++ b/website/docs/r/batch_job_queue.html.markdown @@ -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 +``` \ No newline at end of file From a916e96b2ba2939dedb25e6a8eb520e09ab214ad Mon Sep 17 00:00:00 2001 From: prabusah Date: Sat, 21 Dec 2019 23:52:44 -0600 Subject: [PATCH 2/3] Add import support for aws_batch_job_definition --- aws/resource_aws_batch_job_definition.go | 7 +++++++ aws/resource_aws_batch_job_definition_test.go | 18 +++++++++++++++--- .../docs/r/batch_job_definition.html.markdown | 8 ++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_batch_job_definition.go b/aws/resource_aws_batch_job_definition.go index f2b5d049fbc..3ebee97d3e6 100644 --- a/aws/resource_aws_batch_job_definition.go +++ b/aws/resource_aws_batch_job_definition.go @@ -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, diff --git a/aws/resource_aws_batch_job_definition_test.go b/aws/resource_aws_batch_job_definition_test.go index 928f7a53b9e..74acf3814c4 100644 --- a/aws/resource_aws_batch_job_definition_test.go +++ b/aws/resource_aws_batch_job_definition_test.go @@ -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, @@ -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, + }, }, }) } @@ -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, @@ -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, + }, }, }) } 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 From 96d0dd6f93d56aee68db554ca713b17b7a04eba5 Mon Sep 17 00:00:00 2001 From: prabusah Date: Sun, 22 Dec 2019 13:43:46 -0600 Subject: [PATCH 3/3] formatting fix --- aws/resource_aws_batch_job_definition.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_batch_job_definition.go b/aws/resource_aws_batch_job_definition.go index 3ebee97d3e6..43a5984098c 100644 --- a/aws/resource_aws_batch_job_definition.go +++ b/aws/resource_aws_batch_job_definition.go @@ -23,7 +23,7 @@ func resourceAwsBatchJobDefinition() *schema.Resource { d.Set("arn", d.Id()) return []*schema.ResourceData{d}, nil }, - }, + }, Schema: map[string]*schema.Schema{ "name": {