github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/import_aws_s3_bucket_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/acctest" 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func TestAccAWSS3Bucket_importBasic(t *testing.T) { 13 resourceName := "aws_s3_bucket.bucket" 14 rInt := acctest.RandInt() 15 16 resource.Test(t, resource.TestCase{ 17 PreCheck: func() { testAccPreCheck(t) }, 18 Providers: testAccProviders, 19 CheckDestroy: testAccCheckAWSS3BucketDestroy, 20 Steps: []resource.TestStep{ 21 { 22 Config: testAccAWSS3BucketConfig(rInt), 23 }, 24 25 { 26 ResourceName: resourceName, 27 ImportState: true, 28 ImportStateVerify: true, 29 ImportStateVerifyIgnore: []string{ 30 "force_destroy", "acl"}, 31 }, 32 }, 33 }) 34 } 35 36 func TestAccAWSS3Bucket_importWithPolicy(t *testing.T) { 37 rInt := acctest.RandInt() 38 39 checkFn := func(s []*terraform.InstanceState) error { 40 // Expect 2: bucket + policy 41 if len(s) != 2 { 42 return fmt.Errorf("expected 2 states: %#v", s) 43 } 44 bucketState, policyState := s[0], s[1] 45 46 expectedBucketId := fmt.Sprintf("tf-test-bucket-%d", rInt) 47 48 if bucketState.ID != expectedBucketId { 49 return fmt.Errorf("expected bucket of ID %s, %s received", 50 expectedBucketId, bucketState.ID) 51 } 52 53 if policyState.ID != expectedBucketId { 54 return fmt.Errorf("expected policy of ID %s, %s received", 55 expectedBucketId, bucketState.ID) 56 } 57 58 return nil 59 } 60 61 resource.Test(t, resource.TestCase{ 62 PreCheck: func() { testAccPreCheck(t) }, 63 Providers: testAccProviders, 64 CheckDestroy: testAccCheckAWSS3BucketDestroy, 65 Steps: []resource.TestStep{ 66 { 67 Config: testAccAWSS3BucketConfigWithPolicy(rInt), 68 }, 69 70 { 71 ResourceName: "aws_s3_bucket.bucket", 72 ImportState: true, 73 ImportStateCheck: checkFn, 74 }, 75 }, 76 }) 77 }