Merge pull request #8383 from kjmkznr/import-aws-s3-b-notification

provider/aws: Support import `aws_s3_bucket_notification`
This commit is contained in:
James Nugent 2016-09-03 15:50:25 -07:00 committed by GitHub
commit 6c23181686
4 changed files with 77 additions and 1 deletions

View File

@ -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"},
},
},
})
}

View File

@ -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{

View File

@ -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
}

View File

@ -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
```