mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/aws: Randomize all S3 bucket names per test, not per run
The existing `randInt` is being use per run (so all tests use the same bucket name), not per run (where each test would get a random int) Fixes that
This commit is contained in:
parent
97ea366671
commit
244e727c6f
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ import (
|
|||||||
var tf, err = ioutil.TempFile("", "tf")
|
var tf, err = ioutil.TempFile("", "tf")
|
||||||
|
|
||||||
func TestAccAWSS3BucketObject_source(t *testing.T) {
|
func TestAccAWSS3BucketObject_source(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
// first write some data to the tempfile just so it's not 0 bytes.
|
// first write some data to the tempfile just so it's not 0 bytes.
|
||||||
ioutil.WriteFile(tf.Name(), []byte("{anything will do }"), 0644)
|
ioutil.WriteFile(tf.Name(), []byte("{anything will do }"), 0644)
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
@ -29,7 +31,7 @@ func TestAccAWSS3BucketObject_source(t *testing.T) {
|
|||||||
CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketObjectConfigSource,
|
Config: testAccAWSS3BucketObjectConfigSource(rInt),
|
||||||
Check: testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object"),
|
Check: testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -37,6 +39,7 @@ func TestAccAWSS3BucketObject_source(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSS3BucketObject_content(t *testing.T) {
|
func TestAccAWSS3BucketObject_content(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() {
|
PreCheck: func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,7 +51,7 @@ func TestAccAWSS3BucketObject_content(t *testing.T) {
|
|||||||
CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketObjectConfigContent,
|
Config: testAccAWSS3BucketObjectConfigContent(rInt),
|
||||||
Check: testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object"),
|
Check: testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -56,6 +59,7 @@ func TestAccAWSS3BucketObject_content(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSS3BucketObject_withContentCharacteristics(t *testing.T) {
|
func TestAccAWSS3BucketObject_withContentCharacteristics(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
// first write some data to the tempfile just so it's not 0 bytes.
|
// first write some data to the tempfile just so it's not 0 bytes.
|
||||||
ioutil.WriteFile(tf.Name(), []byte("{anything will do }"), 0644)
|
ioutil.WriteFile(tf.Name(), []byte("{anything will do }"), 0644)
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
@ -69,7 +73,7 @@ func TestAccAWSS3BucketObject_withContentCharacteristics(t *testing.T) {
|
|||||||
CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketObjectConfig_withContentCharacteristics,
|
Config: testAccAWSS3BucketObjectConfig_withContentCharacteristics(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object"),
|
testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
@ -129,8 +133,8 @@ func testAccCheckAWSS3BucketObjectExists(n string) resource.TestCheckFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var randomBucket = randInt
|
func testAccAWSS3BucketObjectConfigSource(randInt int) string {
|
||||||
var testAccAWSS3BucketObjectConfigSource = fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "object_bucket" {
|
resource "aws_s3_bucket" "object_bucket" {
|
||||||
bucket = "tf-object-test-bucket-%d"
|
bucket = "tf-object-test-bucket-%d"
|
||||||
}
|
}
|
||||||
@ -140,9 +144,11 @@ resource "aws_s3_bucket_object" "object" {
|
|||||||
source = "%s"
|
source = "%s"
|
||||||
content_type = "binary/octet-stream"
|
content_type = "binary/octet-stream"
|
||||||
}
|
}
|
||||||
`, randomBucket, tf.Name())
|
`, randInt, tf.Name())
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketObjectConfig_withContentCharacteristics = fmt.Sprintf(`
|
func testAccAWSS3BucketObjectConfig_withContentCharacteristics(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "object_bucket_2" {
|
resource "aws_s3_bucket" "object_bucket_2" {
|
||||||
bucket = "tf-object-test-bucket-%d"
|
bucket = "tf-object-test-bucket-%d"
|
||||||
}
|
}
|
||||||
@ -154,9 +160,11 @@ resource "aws_s3_bucket_object" "object" {
|
|||||||
content_language = "en"
|
content_language = "en"
|
||||||
content_type = "binary/octet-stream"
|
content_type = "binary/octet-stream"
|
||||||
}
|
}
|
||||||
`, randomBucket, tf.Name())
|
`, randInt, tf.Name())
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketObjectConfigContent = fmt.Sprintf(`
|
func testAccAWSS3BucketObjectConfigContent(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "object_bucket" {
|
resource "aws_s3_bucket" "object_bucket" {
|
||||||
bucket = "tf-object-test-bucket-%d"
|
bucket = "tf-object-test-bucket-%d"
|
||||||
}
|
}
|
||||||
@ -165,4 +173,5 @@ resource "aws_s3_bucket_object" "object" {
|
|||||||
key = "test-key"
|
key = "test-key"
|
||||||
content = "some_bucket_content"
|
content = "some_bucket_content"
|
||||||
}
|
}
|
||||||
`, randomBucket)
|
`, randInt)
|
||||||
|
}
|
||||||
|
@ -3,13 +3,12 @@ package aws
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSS3Bucket_basic(t *testing.T) {
|
func TestAccAWSS3Bucket_basic(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
arnRegexp := regexp.MustCompile(
|
arnRegexp := regexp.MustCompile(
|
||||||
"^arn:aws:s3:::")
|
"^arn:aws:s3:::")
|
||||||
|
|
||||||
@ -29,7 +28,7 @@ func TestAccAWSS3Bucket_basic(t *testing.T) {
|
|||||||
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketConfig,
|
Config: testAccAWSS3BucketConfig(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
@ -47,21 +46,23 @@ func TestAccAWSS3Bucket_basic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSS3Bucket_Policy(t *testing.T) {
|
func TestAccAWSS3Bucket_Policy(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketConfigWithPolicy,
|
Config: testAccAWSS3BucketConfigWithPolicy(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketPolicy(
|
testAccCheckAWSS3BucketPolicy(
|
||||||
"aws_s3_bucket.bucket", testAccAWSS3BucketPolicy),
|
"aws_s3_bucket.bucket", testAccAWSS3BucketPolicy(rInt)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketConfig,
|
Config: testAccAWSS3BucketConfig(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketPolicy(
|
testAccCheckAWSS3BucketPolicy(
|
||||||
@ -73,7 +74,6 @@ func TestAccAWSS3Bucket_Policy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSS3Bucket_UpdateAcl(t *testing.T) {
|
func TestAccAWSS3Bucket_UpdateAcl(t *testing.T) {
|
||||||
|
|
||||||
ri := genRandInt()
|
ri := genRandInt()
|
||||||
preConfig := fmt.Sprintf(testAccAWSS3BucketConfigWithAcl, ri)
|
preConfig := fmt.Sprintf(testAccAWSS3BucketConfigWithAcl, ri)
|
||||||
postConfig := fmt.Sprintf(testAccAWSS3BucketConfigWithAclUpdate, ri)
|
postConfig := fmt.Sprintf(testAccAWSS3BucketConfigWithAclUpdate, ri)
|
||||||
@ -104,33 +104,34 @@ func TestAccAWSS3Bucket_UpdateAcl(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSS3Bucket_Website_Simple(t *testing.T) {
|
func TestAccAWSS3Bucket_Website_Simple(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketWebsiteConfig,
|
Config: testAccAWSS3BucketWebsiteConfig(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketWebsite(
|
testAccCheckAWSS3BucketWebsite(
|
||||||
"aws_s3_bucket.bucket", "index.html", "", "", ""),
|
"aws_s3_bucket.bucket", "index.html", "", "", ""),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_s3_bucket.bucket", "website_endpoint", testAccWebsiteEndpoint),
|
"aws_s3_bucket.bucket", "website_endpoint", testAccWebsiteEndpoint(rInt)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketWebsiteConfigWithError,
|
Config: testAccAWSS3BucketWebsiteConfigWithError(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketWebsite(
|
testAccCheckAWSS3BucketWebsite(
|
||||||
"aws_s3_bucket.bucket", "index.html", "error.html", "", ""),
|
"aws_s3_bucket.bucket", "index.html", "error.html", "", ""),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_s3_bucket.bucket", "website_endpoint", testAccWebsiteEndpoint),
|
"aws_s3_bucket.bucket", "website_endpoint", testAccWebsiteEndpoint(rInt)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketConfig,
|
Config: testAccAWSS3BucketConfig(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketWebsite(
|
testAccCheckAWSS3BucketWebsite(
|
||||||
@ -144,33 +145,34 @@ func TestAccAWSS3Bucket_Website_Simple(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSS3Bucket_WebsiteRedirect(t *testing.T) {
|
func TestAccAWSS3Bucket_WebsiteRedirect(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketWebsiteConfigWithRedirect,
|
Config: testAccAWSS3BucketWebsiteConfigWithRedirect(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketWebsite(
|
testAccCheckAWSS3BucketWebsite(
|
||||||
"aws_s3_bucket.bucket", "", "", "", "hashicorp.com"),
|
"aws_s3_bucket.bucket", "", "", "", "hashicorp.com"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_s3_bucket.bucket", "website_endpoint", testAccWebsiteEndpoint),
|
"aws_s3_bucket.bucket", "website_endpoint", testAccWebsiteEndpoint(rInt)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketWebsiteConfigWithHttpsRedirect,
|
Config: testAccAWSS3BucketWebsiteConfigWithHttpsRedirect(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketWebsite(
|
testAccCheckAWSS3BucketWebsite(
|
||||||
"aws_s3_bucket.bucket", "", "", "https", "hashicorp.com"),
|
"aws_s3_bucket.bucket", "", "", "https", "hashicorp.com"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_s3_bucket.bucket", "website_endpoint", testAccWebsiteEndpoint),
|
"aws_s3_bucket.bucket", "website_endpoint", testAccWebsiteEndpoint(rInt)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketConfig,
|
Config: testAccAWSS3BucketConfig(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketWebsite(
|
testAccCheckAWSS3BucketWebsite(
|
||||||
@ -187,13 +189,14 @@ func TestAccAWSS3Bucket_WebsiteRedirect(t *testing.T) {
|
|||||||
// not empty" error in Terraform, to check against regresssions.
|
// not empty" error in Terraform, to check against regresssions.
|
||||||
// See https://github.com/hashicorp/terraform/pull/2925
|
// See https://github.com/hashicorp/terraform/pull/2925
|
||||||
func TestAccAWSS3Bucket_shouldFailNotFound(t *testing.T) {
|
func TestAccAWSS3Bucket_shouldFailNotFound(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketDestroyedConfig,
|
Config: testAccAWSS3BucketDestroyedConfig(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3DestroyBucket("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3DestroyBucket("aws_s3_bucket.bucket"),
|
||||||
@ -205,13 +208,14 @@ func TestAccAWSS3Bucket_shouldFailNotFound(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSS3Bucket_Versioning(t *testing.T) {
|
func TestAccAWSS3Bucket_Versioning(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketConfig,
|
Config: testAccAWSS3BucketConfig(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketVersioning(
|
testAccCheckAWSS3BucketVersioning(
|
||||||
@ -219,7 +223,7 @@ func TestAccAWSS3Bucket_Versioning(t *testing.T) {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketConfigWithVersioning,
|
Config: testAccAWSS3BucketConfigWithVersioning(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketVersioning(
|
testAccCheckAWSS3BucketVersioning(
|
||||||
@ -227,7 +231,7 @@ func TestAccAWSS3Bucket_Versioning(t *testing.T) {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketConfigWithDisableVersioning,
|
Config: testAccAWSS3BucketConfigWithDisableVersioning(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketVersioning(
|
testAccCheckAWSS3BucketVersioning(
|
||||||
@ -239,13 +243,14 @@ func TestAccAWSS3Bucket_Versioning(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSS3Bucket_Cors(t *testing.T) {
|
func TestAccAWSS3Bucket_Cors(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketConfigWithCORS,
|
Config: testAccAWSS3BucketConfigWithCORS(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketCors(
|
testAccCheckAWSS3BucketCors(
|
||||||
@ -267,13 +272,14 @@ func TestAccAWSS3Bucket_Cors(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSS3Bucket_Logging(t *testing.T) {
|
func TestAccAWSS3Bucket_Logging(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSS3BucketConfigWithLogging,
|
Config: testAccAWSS3BucketConfigWithLogging(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
testAccCheckAWSS3BucketLogging(
|
testAccCheckAWSS3BucketLogging(
|
||||||
@ -534,18 +540,25 @@ func testAccCheckAWSS3BucketLogging(n, b, p string) resource.TestCheckFunc {
|
|||||||
|
|
||||||
// These need a bit of randomness as the name can only be used once globally
|
// These need a bit of randomness as the name can only be used once globally
|
||||||
// within AWS
|
// within AWS
|
||||||
var randInt = rand.New(rand.NewSource(time.Now().UnixNano())).Int()
|
func testAccWebsiteEndpoint(randInt int) string {
|
||||||
var testAccWebsiteEndpoint = fmt.Sprintf("tf-test-bucket-%d.s3-website-us-west-2.amazonaws.com", randInt)
|
return fmt.Sprintf("tf-test-bucket-%d.s3-website-us-west-2.amazonaws.com", randInt)
|
||||||
var testAccAWSS3BucketPolicy = fmt.Sprintf(`{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::tf-test-bucket-%d/*" } ] }`, randInt)
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketConfig = fmt.Sprintf(`
|
func testAccAWSS3BucketPolicy(randInt int) string {
|
||||||
|
return fmt.Sprintf(`{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::tf-test-bucket-%d/*" } ] }`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccAWSS3BucketConfig(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
bucket = "tf-test-bucket-%d"
|
bucket = "tf-test-bucket-%d"
|
||||||
acl = "public-read"
|
acl = "public-read"
|
||||||
}
|
}
|
||||||
`, randInt)
|
`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketWebsiteConfig = fmt.Sprintf(`
|
func testAccAWSS3BucketWebsiteConfig(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
bucket = "tf-test-bucket-%d"
|
bucket = "tf-test-bucket-%d"
|
||||||
acl = "public-read"
|
acl = "public-read"
|
||||||
@ -555,8 +568,10 @@ resource "aws_s3_bucket" "bucket" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, randInt)
|
`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketWebsiteConfigWithError = fmt.Sprintf(`
|
func testAccAWSS3BucketWebsiteConfigWithError(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
bucket = "tf-test-bucket-%d"
|
bucket = "tf-test-bucket-%d"
|
||||||
acl = "public-read"
|
acl = "public-read"
|
||||||
@ -567,8 +582,10 @@ resource "aws_s3_bucket" "bucket" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, randInt)
|
`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketWebsiteConfigWithRedirect = fmt.Sprintf(`
|
func testAccAWSS3BucketWebsiteConfigWithRedirect(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
bucket = "tf-test-bucket-%d"
|
bucket = "tf-test-bucket-%d"
|
||||||
acl = "public-read"
|
acl = "public-read"
|
||||||
@ -578,8 +595,10 @@ resource "aws_s3_bucket" "bucket" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, randInt)
|
`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketWebsiteConfigWithHttpsRedirect = fmt.Sprintf(`
|
func testAccAWSS3BucketWebsiteConfigWithHttpsRedirect(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
bucket = "tf-test-bucket-%d"
|
bucket = "tf-test-bucket-%d"
|
||||||
acl = "public-read"
|
acl = "public-read"
|
||||||
@ -589,23 +608,29 @@ resource "aws_s3_bucket" "bucket" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, randInt)
|
`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketConfigWithPolicy = fmt.Sprintf(`
|
func testAccAWSS3BucketConfigWithPolicy(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
bucket = "tf-test-bucket-%d"
|
bucket = "tf-test-bucket-%d"
|
||||||
acl = "public-read"
|
acl = "public-read"
|
||||||
policy = %s
|
policy = %s
|
||||||
}
|
}
|
||||||
`, randInt, strconv.Quote(testAccAWSS3BucketPolicy))
|
`, randInt, strconv.Quote(testAccAWSS3BucketPolicy(randInt)))
|
||||||
|
}
|
||||||
|
|
||||||
var destroyedName = fmt.Sprintf("tf-test-bucket-%d", randInt)
|
func testAccAWSS3BucketDestroyedConfig(randInt int) string {
|
||||||
var testAccAWSS3BucketDestroyedConfig = fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
bucket = "%s"
|
bucket = "tf-test-bucket-%d"
|
||||||
acl = "public-read"
|
acl = "public-read"
|
||||||
}
|
}
|
||||||
`, destroyedName)
|
`, randInt)
|
||||||
var testAccAWSS3BucketConfigWithVersioning = fmt.Sprintf(`
|
}
|
||||||
|
|
||||||
|
func testAccAWSS3BucketConfigWithVersioning(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
bucket = "tf-test-bucket-%d"
|
bucket = "tf-test-bucket-%d"
|
||||||
acl = "public-read"
|
acl = "public-read"
|
||||||
@ -614,8 +639,10 @@ resource "aws_s3_bucket" "bucket" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, randInt)
|
`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketConfigWithDisableVersioning = fmt.Sprintf(`
|
func testAccAWSS3BucketConfigWithDisableVersioning(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
bucket = "tf-test-bucket-%d"
|
bucket = "tf-test-bucket-%d"
|
||||||
acl = "public-read"
|
acl = "public-read"
|
||||||
@ -624,8 +651,10 @@ resource "aws_s3_bucket" "bucket" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, randInt)
|
`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketConfigWithCORS = fmt.Sprintf(`
|
func testAccAWSS3BucketConfigWithCORS(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
bucket = "tf-test-bucket-%d"
|
bucket = "tf-test-bucket-%d"
|
||||||
acl = "public-read"
|
acl = "public-read"
|
||||||
@ -638,6 +667,7 @@ resource "aws_s3_bucket" "bucket" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, randInt)
|
`, randInt)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAWSS3BucketConfigWithAcl = `
|
var testAccAWSS3BucketConfigWithAcl = `
|
||||||
resource "aws_s3_bucket" "bucket" {
|
resource "aws_s3_bucket" "bucket" {
|
||||||
@ -653,7 +683,8 @@ resource "aws_s3_bucket" "bucket" {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
var testAccAWSS3BucketConfigWithLogging = fmt.Sprintf(`
|
func testAccAWSS3BucketConfigWithLogging(randInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_s3_bucket" "log_bucket" {
|
resource "aws_s3_bucket" "log_bucket" {
|
||||||
bucket = "tf-test-log-bucket-%d"
|
bucket = "tf-test-log-bucket-%d"
|
||||||
acl = "log-delivery-write"
|
acl = "log-delivery-write"
|
||||||
@ -667,3 +698,4 @@ resource "aws_s3_bucket" "bucket" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, randInt, randInt)
|
`, randInt, randInt)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user