Merge pull request #9175 from PayscaleNateW/provider/aws/fix-acceptance-test-log-bucket
Provider/aws/fix acceptance test log bucket
This commit is contained in:
commit
60f0603f1c
|
@ -1,12 +1,17 @@
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSCloudFrontDistribution_importBasic(t *testing.T) {
|
func TestAccAWSCloudFrontDistribution_importBasic(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
testConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3Config, ri, originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
|
||||||
|
|
||||||
resourceName := "aws_cloudfront_distribution.s3_distribution"
|
resourceName := "aws_cloudfront_distribution.s3_distribution"
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
@ -15,7 +20,7 @@ func TestAccAWSCloudFrontDistribution_importBasic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
|
CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSCloudFrontDistributionS3Config,
|
Config: testConfig,
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
ResourceName: resourceName,
|
ResourceName: resourceName,
|
||||||
|
|
|
@ -20,13 +20,15 @@ import (
|
||||||
// If you are testing manually and can't wait for deletion, set the
|
// If you are testing manually and can't wait for deletion, set the
|
||||||
// TF_TEST_CLOUDFRONT_RETAIN environment variable.
|
// TF_TEST_CLOUDFRONT_RETAIN environment variable.
|
||||||
func TestAccAWSCloudFrontDistribution_S3Origin(t *testing.T) {
|
func TestAccAWSCloudFrontDistribution_S3Origin(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
testConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3Config, ri, originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
|
CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSCloudFrontDistributionS3Config,
|
Config: testConfig,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFrontDistributionExistence(
|
testAccCheckCloudFrontDistributionExistence(
|
||||||
"aws_cloudfront_distribution.s3_distribution",
|
"aws_cloudfront_distribution.s3_distribution",
|
||||||
|
@ -44,8 +46,8 @@ func TestAccAWSCloudFrontDistribution_S3Origin(t *testing.T) {
|
||||||
|
|
||||||
func TestAccAWSCloudFrontDistribution_S3OriginWithTags(t *testing.T) {
|
func TestAccAWSCloudFrontDistribution_S3OriginWithTags(t *testing.T) {
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
preConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3ConfigWithTags, ri, testAccAWSCloudFrontDistributionRetainConfig())
|
preConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3ConfigWithTags, ri, originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
|
||||||
postConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3ConfigWithTagsUpdated, ri, testAccAWSCloudFrontDistributionRetainConfig())
|
postConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3ConfigWithTagsUpdated, ri, originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -251,26 +253,41 @@ func testAccAWSCloudFrontDistributionRetainConfig() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccAWSCloudFrontDistributionS3Config = fmt.Sprintf(`
|
var originBucket = fmt.Sprintf(`
|
||||||
|
resource "aws_s3_bucket" "s3_bucket_origin" {
|
||||||
|
bucket = "mybucket.${var.rand_id}"
|
||||||
|
acl = "public-read"
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
var logBucket = fmt.Sprintf(`
|
||||||
|
resource "aws_s3_bucket" "s3_bucket_logs" {
|
||||||
|
bucket = "mylogs.${var.rand_id}"
|
||||||
|
acl = "public-read"
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
var testAccAWSCloudFrontDistributionS3Config = `
|
||||||
variable rand_id {
|
variable rand_id {
|
||||||
default = %d
|
default = %d
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_s3_bucket" "s3_bucket" {
|
# origin bucket
|
||||||
bucket = "mybucket.${var.rand_id}.s3.amazonaws.com"
|
%s
|
||||||
acl = "public-read"
|
|
||||||
}
|
# log bucket
|
||||||
|
%s
|
||||||
|
|
||||||
resource "aws_cloudfront_distribution" "s3_distribution" {
|
resource "aws_cloudfront_distribution" "s3_distribution" {
|
||||||
origin {
|
origin {
|
||||||
domain_name = "${aws_s3_bucket.s3_bucket.id}"
|
domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com"
|
||||||
origin_id = "myS3Origin"
|
origin_id = "myS3Origin"
|
||||||
}
|
}
|
||||||
enabled = true
|
enabled = true
|
||||||
default_root_object = "index.html"
|
default_root_object = "index.html"
|
||||||
logging_config {
|
logging_config {
|
||||||
include_cookies = false
|
include_cookies = false
|
||||||
bucket = "mylogs.${var.rand_id}.s3.amazonaws.com"
|
bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com"
|
||||||
prefix = "myprefix"
|
prefix = "myprefix"
|
||||||
}
|
}
|
||||||
aliases = [ "mysite.${var.rand_id}.example.com", "yoursite.${var.rand_id}.example.com" ]
|
aliases = [ "mysite.${var.rand_id}.example.com", "yoursite.${var.rand_id}.example.com" ]
|
||||||
|
@ -301,21 +318,22 @@ resource "aws_cloudfront_distribution" "s3_distribution" {
|
||||||
}
|
}
|
||||||
%s
|
%s
|
||||||
}
|
}
|
||||||
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
|
`
|
||||||
|
|
||||||
var testAccAWSCloudFrontDistributionS3ConfigWithTags = `
|
var testAccAWSCloudFrontDistributionS3ConfigWithTags = `
|
||||||
variable rand_id {
|
variable rand_id {
|
||||||
default = %d
|
default = %d
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_s3_bucket" "s3_bucket" {
|
# origin bucket
|
||||||
bucket = "mybucket.${var.rand_id}.s3.amazonaws.com"
|
%s
|
||||||
acl = "public-read"
|
|
||||||
}
|
# log bucket
|
||||||
|
%s
|
||||||
|
|
||||||
resource "aws_cloudfront_distribution" "s3_distribution" {
|
resource "aws_cloudfront_distribution" "s3_distribution" {
|
||||||
origin {
|
origin {
|
||||||
domain_name = "${aws_s3_bucket.s3_bucket.id}"
|
domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com"
|
||||||
origin_id = "myS3Origin"
|
origin_id = "myS3Origin"
|
||||||
}
|
}
|
||||||
enabled = true
|
enabled = true
|
||||||
|
@ -359,14 +377,15 @@ variable rand_id {
|
||||||
default = %d
|
default = %d
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_s3_bucket" "s3_bucket" {
|
# origin bucket
|
||||||
bucket = "mybucket.${var.rand_id}.s3.amazonaws.com"
|
%s
|
||||||
acl = "public-read"
|
|
||||||
}
|
# log bucket
|
||||||
|
%s
|
||||||
|
|
||||||
resource "aws_cloudfront_distribution" "s3_distribution" {
|
resource "aws_cloudfront_distribution" "s3_distribution" {
|
||||||
origin {
|
origin {
|
||||||
domain_name = "${aws_s3_bucket.s3_bucket.id}"
|
domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com"
|
||||||
origin_id = "myS3Origin"
|
origin_id = "myS3Origin"
|
||||||
}
|
}
|
||||||
enabled = true
|
enabled = true
|
||||||
|
@ -409,6 +428,9 @@ variable rand_id {
|
||||||
default = %d
|
default = %d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# log bucket
|
||||||
|
%s
|
||||||
|
|
||||||
resource "aws_cloudfront_distribution" "custom_distribution" {
|
resource "aws_cloudfront_distribution" "custom_distribution" {
|
||||||
origin {
|
origin {
|
||||||
domain_name = "www.example.com"
|
domain_name = "www.example.com"
|
||||||
|
@ -425,7 +447,7 @@ resource "aws_cloudfront_distribution" "custom_distribution" {
|
||||||
default_root_object = "index.html"
|
default_root_object = "index.html"
|
||||||
logging_config {
|
logging_config {
|
||||||
include_cookies = false
|
include_cookies = false
|
||||||
bucket = "mylogs.${var.rand_id}.s3.amazonaws.com"
|
bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com"
|
||||||
prefix = "myprefix"
|
prefix = "myprefix"
|
||||||
}
|
}
|
||||||
aliases = [ "mysite.${var.rand_id}.example.com", "*.yoursite.${var.rand_id}.example.com" ]
|
aliases = [ "mysite.${var.rand_id}.example.com", "*.yoursite.${var.rand_id}.example.com" ]
|
||||||
|
@ -457,21 +479,22 @@ resource "aws_cloudfront_distribution" "custom_distribution" {
|
||||||
}
|
}
|
||||||
%s
|
%s
|
||||||
}
|
}
|
||||||
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
|
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), logBucket, testAccAWSCloudFrontDistributionRetainConfig())
|
||||||
|
|
||||||
var testAccAWSCloudFrontDistributionMultiOriginConfig = fmt.Sprintf(`
|
var testAccAWSCloudFrontDistributionMultiOriginConfig = fmt.Sprintf(`
|
||||||
variable rand_id {
|
variable rand_id {
|
||||||
default = %d
|
default = %d
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_s3_bucket" "s3_bucket" {
|
# origin bucket
|
||||||
bucket = "mybucket.${var.rand_id}.s3.amazonaws.com"
|
%s
|
||||||
acl = "public-read"
|
|
||||||
}
|
# log bucket
|
||||||
|
%s
|
||||||
|
|
||||||
resource "aws_cloudfront_distribution" "multi_origin_distribution" {
|
resource "aws_cloudfront_distribution" "multi_origin_distribution" {
|
||||||
origin {
|
origin {
|
||||||
domain_name = "${aws_s3_bucket.s3_bucket.id}"
|
domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com"
|
||||||
origin_id = "myS3Origin"
|
origin_id = "myS3Origin"
|
||||||
}
|
}
|
||||||
origin {
|
origin {
|
||||||
|
@ -489,7 +512,7 @@ resource "aws_cloudfront_distribution" "multi_origin_distribution" {
|
||||||
default_root_object = "index.html"
|
default_root_object = "index.html"
|
||||||
logging_config {
|
logging_config {
|
||||||
include_cookies = false
|
include_cookies = false
|
||||||
bucket = "mylogs.${var.rand_id}.s3.amazonaws.com"
|
bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com"
|
||||||
prefix = "myprefix"
|
prefix = "myprefix"
|
||||||
}
|
}
|
||||||
aliases = [ "mysite.${var.rand_id}.example.com", "*.yoursite.${var.rand_id}.example.com" ]
|
aliases = [ "mysite.${var.rand_id}.example.com", "*.yoursite.${var.rand_id}.example.com" ]
|
||||||
|
@ -541,6 +564,7 @@ resource "aws_cloudfront_distribution" "multi_origin_distribution" {
|
||||||
viewer_protocol_policy = "allow-all"
|
viewer_protocol_policy = "allow-all"
|
||||||
path_pattern = "images2/*.jpg"
|
path_pattern = "images2/*.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
price_class = "PriceClass_All"
|
price_class = "PriceClass_All"
|
||||||
custom_error_response {
|
custom_error_response {
|
||||||
error_code = 404
|
error_code = 404
|
||||||
|
@ -558,7 +582,7 @@ resource "aws_cloudfront_distribution" "multi_origin_distribution" {
|
||||||
}
|
}
|
||||||
%s
|
%s
|
||||||
}
|
}
|
||||||
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
|
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
|
||||||
|
|
||||||
var testAccAWSCloudFrontDistributionNoCustomErroResponseInfo = fmt.Sprintf(`
|
var testAccAWSCloudFrontDistributionNoCustomErroResponseInfo = fmt.Sprintf(`
|
||||||
variable rand_id {
|
variable rand_id {
|
||||||
|
|
Loading…
Reference in New Issue