Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fix for issue #167 - defaulting restrictions to none for cloudf… #3364

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions aws/resource_aws_cloudfront_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,15 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
},
"restrictions": {
Type: schema.TypeSet,
Required: true,
Optional: true,
Set: restrictionsHash,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"geo_restriction": {
Type: schema.TypeSet,
Required: true,
Optional: true,
Set: geoRestrictionHash,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"locations": {
Expand All @@ -451,7 +450,8 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
},
"restriction_type": {
Type: schema.TypeString,
Required: true,
Optional: true,
Default: cloudfront.GeoRestrictionTypeNone,
},
},
},
Expand Down
120 changes: 73 additions & 47 deletions aws/resource_aws_cloudfront_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ func TestAccAWSCloudFrontDistribution_S3Origin(t *testing.T) {
})
}

func TestAccAWSCloudFrontDistribution_S3Origin_Restrictions(t *testing.T) {
ri := acctest.RandInt()
testConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3ConfigRestrictions, ri, originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
Steps: []resource.TestStep{
{
Config: testConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudFrontDistributionExistence(
"aws_cloudfront_distribution.s3_distribution",
),
resource.TestCheckResourceAttr(
"aws_cloudfront_distribution.s3_distribution",
"hosted_zone_id",
"Z2FDTNDATAQYW2",
),
),
},
},
})
}

func TestAccAWSCloudFrontDistribution_S3OriginWithTags(t *testing.T) {
ri := acctest.RandInt()
preConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3ConfigWithTags, ri, originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
Expand Down Expand Up @@ -344,6 +369,54 @@ resource "aws_cloudfront_distribution" "s3_distribution" {
max_ttl = 86400
}
price_class = "PriceClass_200"
viewer_certificate {
cloudfront_default_certificate = true
}
%s
}
`

var testAccAWSCloudFrontDistributionS3ConfigRestrictions = `
variable rand_id {
default = %d
}

# origin bucket
%s

# log bucket
%s

resource "aws_cloudfront_distribution" "s3_distribution" {
origin {
domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com"
origin_id = "myS3Origin"
}
enabled = true
default_root_object = "index.html"
logging_config {
include_cookies = false
bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com"
prefix = "myprefix"
}
aliases = [ "mysite.${var.rand_id}.example.com", "yoursite.${var.rand_id}.example.com" ]
default_cache_behavior {
allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
cached_methods = [ "GET", "HEAD" ]
target_origin_id = "myS3Origin"
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
viewer_protocol_policy = "allow-all"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
}
price_class = "PriceClass_200"

restrictions {
geo_restriction {
restriction_type = "whitelist"
Expand Down Expand Up @@ -392,12 +465,6 @@ resource "aws_cloudfront_distribution" "s3_distribution" {
max_ttl = 86400
}
price_class = "PriceClass_200"
restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = [ "US", "CA", "GB", "DE" ]
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
Expand Down Expand Up @@ -444,12 +511,6 @@ resource "aws_cloudfront_distribution" "s3_distribution" {
max_ttl = 86400
}
price_class = "PriceClass_200"
restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = [ "US", "CA", "GB", "DE" ]
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
Expand Down Expand Up @@ -507,12 +568,6 @@ resource "aws_cloudfront_distribution" "custom_distribution" {
max_ttl = 86400
}
price_class = "PriceClass_200"
restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = [ "US", "CA", "GB", "DE" ]
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
Expand Down Expand Up @@ -612,11 +667,6 @@ resource "aws_cloudfront_distribution" "multi_origin_distribution" {
response_code = 200
error_caching_min_ttl = 30
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
Expand Down Expand Up @@ -662,12 +712,6 @@ resource "aws_cloudfront_distribution" "no_custom_error_responses" {
error_code = 404
error_caching_min_ttl = 30
}
restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = [ "US", "CA", "GB", "DE" ]
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
Expand Down Expand Up @@ -709,12 +753,6 @@ resource "aws_cloudfront_distribution" "no_optional_items" {
default_ttl = 3600
max_ttl = 86400
}
restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = [ "US", "CA", "GB", "DE" ]
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
Expand Down Expand Up @@ -757,12 +795,6 @@ resource "aws_cloudfront_distribution" "http_1_1" {
max_ttl = 86400
}
http_version = "http1.1"
restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = [ "US", "CA", "GB", "DE" ]
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
Expand Down Expand Up @@ -806,12 +838,6 @@ resource "aws_cloudfront_distribution" "is_ipv6_enabled" {
max_ttl = 86400
}
http_version = "http1.1"
restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = [ "US", "CA", "GB", "DE" ]
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
Expand Down