provider/aws: Enable aws_cloudfront_distribution HTTP/2
Added http_version to aws_cloudfront_distribution, which allows selection of the maximum HTTP version to use in the distribution. Defaults to http2. Fixes hashicorp/terraform#8730.
This commit is contained in:
parent
a8a1f6d166
commit
ec2b345ed0
|
@ -46,6 +46,7 @@ func expandDistributionConfig(d *schema.ResourceData) *cloudfront.DistributionCo
|
|||
CustomErrorResponses: expandCustomErrorResponses(d.Get("custom_error_response").(*schema.Set)),
|
||||
DefaultCacheBehavior: expandDefaultCacheBehavior(d.Get("default_cache_behavior").(*schema.Set).List()[0].(map[string]interface{})),
|
||||
Enabled: aws.Bool(d.Get("enabled").(bool)),
|
||||
HttpVersion: aws.String(d.Get("http_version").(string)),
|
||||
Origins: expandOrigins(d.Get("origin").(*schema.Set)),
|
||||
PriceClass: aws.String(d.Get("price_class").(string)),
|
||||
}
|
||||
|
@ -122,6 +123,9 @@ func flattenDistributionConfig(d *schema.ResourceData, distributionConfig *cloud
|
|||
if distributionConfig.DefaultRootObject != nil {
|
||||
d.Set("default_root_object", distributionConfig.DefaultRootObject)
|
||||
}
|
||||
if distributionConfig.HttpVersion != nil {
|
||||
d.Set("http_version", distributionConfig.HttpVersion)
|
||||
}
|
||||
if distributionConfig.WebACLId != nil {
|
||||
d.Set("web_acl_id", distributionConfig.WebACLId)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
|
@ -251,6 +252,12 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
|
|||
Type: schema.TypeBool,
|
||||
Required: true,
|
||||
},
|
||||
"http_version": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Default: "http2",
|
||||
ValidateFunc: validateHTTP,
|
||||
},
|
||||
"logging_config": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
|
@ -609,3 +616,20 @@ func resourceAwsCloudFrontWebDistributionStateRefreshFunc(id string, meta interf
|
|||
return resp.Distribution, *resp.Distribution.Status, nil
|
||||
}
|
||||
}
|
||||
|
||||
// validateHTTP ensures that the http_version resource parameter is
|
||||
// correct.
|
||||
func validateHTTP(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := v.(string)
|
||||
found := false
|
||||
for _, w := range []string{"http1.1", "http2"} {
|
||||
if value == w {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if found == false {
|
||||
errors = append(errors, fmt.Errorf(
|
||||
"HTTP version parameter must be one of http1.1 or http2"))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -110,6 +110,30 @@ func TestAccAWSCloudFrontDistribution_noOptionalItemsConfig(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
// TestAccAWSCloudFrontDistribution_HTTP11Config runs an
|
||||
// aws_cloudfront_distribution acceptance test with the HTTP version set to
|
||||
// 1.1.
|
||||
//
|
||||
// If you are testing manually and can't wait for deletion, set the
|
||||
// TF_TEST_CLOUDFRONT_RETAIN environment variable.
|
||||
func TestAccAWSCloudFrontDistribution_HTTP11Config(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSCloudFrontDistributionHTTP11Config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudFrontDistributionExistence(
|
||||
"aws_cloudfront_distribution.http_1_1",
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAWSCloudFrontDistribution_noCustomErrorResponseConfig(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -491,3 +515,51 @@ resource "aws_cloudfront_distribution" "no_optional_items" {
|
|||
%s
|
||||
}
|
||||
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
|
||||
|
||||
var testAccAWSCloudFrontDistributionHTTP11Config = fmt.Sprintf(`
|
||||
variable rand_id {
|
||||
default = %d
|
||||
}
|
||||
|
||||
resource "aws_cloudfront_distribution" "http_1_1" {
|
||||
origin {
|
||||
domain_name = "www.example.com"
|
||||
origin_id = "myCustomOrigin"
|
||||
custom_origin_config {
|
||||
http_port = 80
|
||||
https_port = 443
|
||||
origin_protocol_policy = "http-only"
|
||||
origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
|
||||
}
|
||||
}
|
||||
enabled = true
|
||||
comment = "Some comment"
|
||||
default_cache_behavior {
|
||||
allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
|
||||
cached_methods = [ "GET", "HEAD" ]
|
||||
target_origin_id = "myCustomOrigin"
|
||||
smooth_streaming = false
|
||||
forwarded_values {
|
||||
query_string = false
|
||||
cookies {
|
||||
forward = "all"
|
||||
}
|
||||
}
|
||||
viewer_protocol_policy = "allow-all"
|
||||
min_ttl = 0
|
||||
default_ttl = 3600
|
||||
max_ttl = 86400
|
||||
}
|
||||
http_version = "http1.1"
|
||||
restrictions {
|
||||
geo_restriction {
|
||||
restriction_type = "whitelist"
|
||||
locations = [ "US", "CA", "GB", "DE" ]
|
||||
}
|
||||
}
|
||||
viewer_certificate {
|
||||
cloudfront_default_certificate = true
|
||||
}
|
||||
%s
|
||||
}
|
||||
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
|
||||
|
|
|
@ -110,6 +110,10 @@ of several sub-resources - these resources are laid out below.
|
|||
* `enabled` (Required) - Whether the distribution is enabled to accept end
|
||||
user requests for content.
|
||||
|
||||
* `http_version` (Optional) - The maximum HTTP version to support on the
|
||||
distribution. Allowed values are `http1.1` and `http2`. The default is
|
||||
`http2`.
|
||||
|
||||
* `logging_config` (Optional) - The [logging
|
||||
configuration](#logging-config-arguments) that controls how logs are written
|
||||
to your distribution (maximum one).
|
||||
|
|
Loading…
Reference in New Issue