From ed05161fd0ab49175243e128cf7c8d66bf21d6dc Mon Sep 17 00:00:00 2001 From: Kazunori Kojima Date: Mon, 22 Aug 2016 10:24:34 +0900 Subject: [PATCH] provider/aws: Support import `aws_s3_bucket_notification` --- .../import_aws_s3_bucket_notification_test.go | 66 +++++++++++++++++++ .../resource_aws_s3_bucket_notification.go | 3 + helper/resource/testing_import_state.go | 2 +- .../r/s3_bucket_notification.html.markdown | 7 ++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 builtin/providers/aws/import_aws_s3_bucket_notification_test.go diff --git a/builtin/providers/aws/import_aws_s3_bucket_notification_test.go b/builtin/providers/aws/import_aws_s3_bucket_notification_test.go new file mode 100644 index 000000000..9ab574fef --- /dev/null +++ b/builtin/providers/aws/import_aws_s3_bucket_notification_test.go @@ -0,0 +1,66 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSS3BucketNotification_importBasic(t *testing.T) { + resourceName := "aws_s3_bucket_notification.notification" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSS3BucketNotificationDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSS3BucketConfigWithTopicNotification(acctest.RandInt()), + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"bucket"}, + }, + }, + }) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSS3BucketNotificationDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSS3BucketConfigWithQueueNotification(acctest.RandInt()), + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"bucket"}, + }, + }, + }) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSS3BucketNotificationDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSS3BucketConfigWithLambdaNotification(acctest.RandInt()), + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"bucket"}, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_s3_bucket_notification.go b/builtin/providers/aws/resource_aws_s3_bucket_notification.go index 562dc723a..f3e19b484 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket_notification.go +++ b/builtin/providers/aws/resource_aws_s3_bucket_notification.go @@ -20,6 +20,9 @@ func resourceAwsS3BucketNotification() *schema.Resource { Read: resourceAwsS3BucketNotificationRead, Update: resourceAwsS3BucketNotificationPut, Delete: resourceAwsS3BucketNotificationDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "bucket": &schema.Schema{ diff --git a/helper/resource/testing_import_state.go b/helper/resource/testing_import_state.go index 00ec87324..d5c579629 100644 --- a/helper/resource/testing_import_state.go +++ b/helper/resource/testing_import_state.go @@ -78,7 +78,7 @@ func testStepImportState( // Find the existing resource var oldR *terraform.ResourceState for _, r2 := range old { - if r2.Primary != nil && r2.Primary.ID == r.Primary.ID { + if r2.Primary != nil && r2.Primary.ID == r.Primary.ID && r2.Type == r.Type { oldR = r2 break } diff --git a/website/source/docs/providers/aws/r/s3_bucket_notification.html.markdown b/website/source/docs/providers/aws/r/s3_bucket_notification.html.markdown index 3f6564d17..fa2f258db 100644 --- a/website/source/docs/providers/aws/r/s3_bucket_notification.html.markdown +++ b/website/source/docs/providers/aws/r/s3_bucket_notification.html.markdown @@ -234,3 +234,10 @@ The `lambda_function` notification configuration supports the following: * `filter_prefix` - (Optional) Specifies object key name prefix. * `filter_suffix` - (Optional) Specifies object key name suffix. +## Import + +S3 bucket notification can be imported using the `bucket`, e.g. + +``` +$ terraform import aws_s3_bucket_notification.bucket_notification bucket-name +```