github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/aws/resource_aws_cloudfront_distribution_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"math/rand"
     6  	"os"
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/aws/aws-sdk-go/aws"
    11  	"github.com/aws/aws-sdk-go/service/cloudfront"
    12  	"github.com/hashicorp/terraform/helper/acctest"
    13  	"github.com/hashicorp/terraform/helper/resource"
    14  	"github.com/hashicorp/terraform/terraform"
    15  )
    16  
    17  // TestAccAWSCloudFrontDistribution_S3Origin runs an
    18  // aws_cloudfront_distribution acceptance test with a single S3 origin.
    19  //
    20  // If you are testing manually and can't wait for deletion, set the
    21  // TF_TEST_CLOUDFRONT_RETAIN environment variable.
    22  func TestAccAWSCloudFrontDistribution_S3Origin(t *testing.T) {
    23  	ri := acctest.RandInt()
    24  	testConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3Config, ri, originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
    25  	resource.Test(t, resource.TestCase{
    26  		PreCheck:     func() { testAccPreCheck(t) },
    27  		Providers:    testAccProviders,
    28  		CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
    29  		Steps: []resource.TestStep{
    30  			{
    31  				Config: testConfig,
    32  				Check: resource.ComposeTestCheckFunc(
    33  					testAccCheckCloudFrontDistributionExistence(
    34  						"aws_cloudfront_distribution.s3_distribution",
    35  					),
    36  					resource.TestCheckResourceAttr(
    37  						"aws_cloudfront_distribution.s3_distribution",
    38  						"hosted_zone_id",
    39  						"Z2FDTNDATAQYW2",
    40  					),
    41  				),
    42  			},
    43  		},
    44  	})
    45  }
    46  
    47  func TestAccAWSCloudFrontDistribution_S3OriginWithTags(t *testing.T) {
    48  	ri := acctest.RandInt()
    49  	preConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3ConfigWithTags, ri, originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
    50  	postConfig := fmt.Sprintf(testAccAWSCloudFrontDistributionS3ConfigWithTagsUpdated, ri, originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
    51  
    52  	resource.Test(t, resource.TestCase{
    53  		PreCheck:     func() { testAccPreCheck(t) },
    54  		Providers:    testAccProviders,
    55  		CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
    56  		Steps: []resource.TestStep{
    57  			{
    58  				Config: preConfig,
    59  				Check: resource.ComposeTestCheckFunc(
    60  					testAccCheckCloudFrontDistributionExistence(
    61  						"aws_cloudfront_distribution.s3_distribution",
    62  					),
    63  					resource.TestCheckResourceAttr(
    64  						"aws_cloudfront_distribution.s3_distribution", "tags.%", "2"),
    65  					resource.TestCheckResourceAttr(
    66  						"aws_cloudfront_distribution.s3_distribution", "tags.environment", "production"),
    67  					resource.TestCheckResourceAttr(
    68  						"aws_cloudfront_distribution.s3_distribution", "tags.account", "main"),
    69  				),
    70  			},
    71  			{
    72  				Config: postConfig,
    73  				Check: resource.ComposeTestCheckFunc(
    74  					testAccCheckCloudFrontDistributionExistence(
    75  						"aws_cloudfront_distribution.s3_distribution",
    76  					),
    77  					resource.TestCheckResourceAttr(
    78  						"aws_cloudfront_distribution.s3_distribution", "tags.%", "1"),
    79  					resource.TestCheckResourceAttr(
    80  						"aws_cloudfront_distribution.s3_distribution", "tags.environment", "dev"),
    81  				),
    82  			},
    83  		},
    84  	})
    85  }
    86  
    87  // TestAccAWSCloudFrontDistribution_customOriginruns an
    88  // aws_cloudfront_distribution acceptance test with a single custom origin.
    89  //
    90  // If you are testing manually and can't wait for deletion, set the
    91  // TF_TEST_CLOUDFRONT_RETAIN environment variable.
    92  func TestAccAWSCloudFrontDistribution_customOrigin(t *testing.T) {
    93  	resource.Test(t, resource.TestCase{
    94  		PreCheck:     func() { testAccPreCheck(t) },
    95  		Providers:    testAccProviders,
    96  		CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
    97  		Steps: []resource.TestStep{
    98  			{
    99  				Config: testAccAWSCloudFrontDistributionCustomConfig,
   100  				Check: resource.ComposeTestCheckFunc(
   101  					testAccCheckCloudFrontDistributionExistence(
   102  						"aws_cloudfront_distribution.custom_distribution",
   103  					),
   104  				),
   105  			},
   106  		},
   107  	})
   108  }
   109  
   110  // TestAccAWSCloudFrontDistribution_multiOrigin runs an
   111  // aws_cloudfront_distribution acceptance test with multiple origins.
   112  //
   113  // If you are testing manually and can't wait for deletion, set the
   114  // TF_TEST_CLOUDFRONT_RETAIN environment variable.
   115  func TestAccAWSCloudFrontDistribution_multiOrigin(t *testing.T) {
   116  	resource.Test(t, resource.TestCase{
   117  		PreCheck:     func() { testAccPreCheck(t) },
   118  		Providers:    testAccProviders,
   119  		CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
   120  		Steps: []resource.TestStep{
   121  			{
   122  				Config: testAccAWSCloudFrontDistributionMultiOriginConfig,
   123  				Check: resource.ComposeTestCheckFunc(
   124  					testAccCheckCloudFrontDistributionExistence(
   125  						"aws_cloudfront_distribution.multi_origin_distribution",
   126  					),
   127  				),
   128  			},
   129  		},
   130  	})
   131  }
   132  
   133  // TestAccAWSCloudFrontDistribution_noOptionalItemsConfig runs an
   134  // aws_cloudfront_distribution acceptance test with no optional items set.
   135  //
   136  // If you are testing manually and can't wait for deletion, set the
   137  // TF_TEST_CLOUDFRONT_RETAIN environment variable.
   138  func TestAccAWSCloudFrontDistribution_noOptionalItemsConfig(t *testing.T) {
   139  	resource.Test(t, resource.TestCase{
   140  		PreCheck:     func() { testAccPreCheck(t) },
   141  		Providers:    testAccProviders,
   142  		CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
   143  		Steps: []resource.TestStep{
   144  			{
   145  				Config: testAccAWSCloudFrontDistributionNoOptionalItemsConfig,
   146  				Check: resource.ComposeTestCheckFunc(
   147  					testAccCheckCloudFrontDistributionExistence(
   148  						"aws_cloudfront_distribution.no_optional_items",
   149  					),
   150  				),
   151  			},
   152  		},
   153  	})
   154  }
   155  
   156  // TestAccAWSCloudFrontDistribution_HTTP11Config runs an
   157  // aws_cloudfront_distribution acceptance test with the HTTP version set to
   158  // 1.1.
   159  //
   160  // If you are testing manually and can't wait for deletion, set the
   161  // TF_TEST_CLOUDFRONT_RETAIN environment variable.
   162  func TestAccAWSCloudFrontDistribution_HTTP11Config(t *testing.T) {
   163  	resource.Test(t, resource.TestCase{
   164  		PreCheck:     func() { testAccPreCheck(t) },
   165  		Providers:    testAccProviders,
   166  		CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
   167  		Steps: []resource.TestStep{
   168  			{
   169  				Config: testAccAWSCloudFrontDistributionHTTP11Config,
   170  				Check: resource.ComposeTestCheckFunc(
   171  					testAccCheckCloudFrontDistributionExistence(
   172  						"aws_cloudfront_distribution.http_1_1",
   173  					),
   174  				),
   175  			},
   176  		},
   177  	})
   178  }
   179  
   180  func TestAccAWSCloudFrontDistribution_IsIPV6EnabledConfig(t *testing.T) {
   181  	resource.Test(t, resource.TestCase{
   182  		PreCheck:     func() { testAccPreCheck(t) },
   183  		Providers:    testAccProviders,
   184  		CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
   185  		Steps: []resource.TestStep{
   186  			{
   187  				Config: testAccAWSCloudFrontDistributionIsIPV6EnabledConfig,
   188  				Check: resource.ComposeTestCheckFunc(
   189  					testAccCheckCloudFrontDistributionExistence(
   190  						"aws_cloudfront_distribution.is_ipv6_enabled",
   191  					),
   192  					resource.TestCheckResourceAttr(
   193  						"aws_cloudfront_distribution.is_ipv6_enabled", "is_ipv6_enabled", "true"),
   194  				),
   195  			},
   196  		},
   197  	})
   198  }
   199  
   200  func TestAccAWSCloudFrontDistribution_noCustomErrorResponseConfig(t *testing.T) {
   201  	resource.Test(t, resource.TestCase{
   202  		PreCheck:     func() { testAccPreCheck(t) },
   203  		Providers:    testAccProviders,
   204  		CheckDestroy: testAccCheckCloudFrontDistributionDestroy,
   205  		Steps: []resource.TestStep{
   206  			{
   207  				Config: testAccAWSCloudFrontDistributionNoCustomErroResponseInfo,
   208  				Check: resource.ComposeTestCheckFunc(
   209  					testAccCheckCloudFrontDistributionExistence(
   210  						"aws_cloudfront_distribution.no_custom_error_responses",
   211  					),
   212  				),
   213  			},
   214  		},
   215  	})
   216  }
   217  
   218  func TestResourceAWSCloudFrontDistribution_validateHTTP(t *testing.T) {
   219  	var value string
   220  	var errors []error
   221  
   222  	value = "incorrect"
   223  	_, errors = validateHTTP(value, "http_version")
   224  	if len(errors) == 0 {
   225  		t.Fatalf("Expected %q to trigger a validation error", value)
   226  	}
   227  
   228  	value = "http1.1"
   229  	_, errors = validateHTTP(value, "http_version")
   230  	if len(errors) != 0 {
   231  		t.Fatalf("Expected %q not to trigger a validation error", value)
   232  	}
   233  }
   234  
   235  func testAccCheckCloudFrontDistributionDestroy(s *terraform.State) error {
   236  	for k, rs := range s.RootModule().Resources {
   237  		if rs.Type != "aws_cloudfront_distribution" {
   238  			continue
   239  		}
   240  		dist, err := testAccAuxCloudFrontGetDistributionConfig(s, k)
   241  		if err == nil {
   242  			if _, ok := os.LookupEnv("TF_TEST_CLOUDFRONT_RETAIN"); ok {
   243  				if *dist.DistributionConfig.Enabled != false {
   244  					return fmt.Errorf("CloudFront distribution should be disabled")
   245  				}
   246  				return nil
   247  			}
   248  			return fmt.Errorf("CloudFront distribution did not destroy")
   249  		}
   250  	}
   251  	return nil
   252  }
   253  
   254  func testAccCheckCloudFrontDistributionExistence(cloudFrontResource string) resource.TestCheckFunc {
   255  	return func(s *terraform.State) error {
   256  		_, err := testAccAuxCloudFrontGetDistributionConfig(s, cloudFrontResource)
   257  
   258  		return err
   259  	}
   260  }
   261  
   262  func testAccAuxCloudFrontGetDistributionConfig(s *terraform.State, cloudFrontResource string) (*cloudfront.Distribution, error) {
   263  	cf, ok := s.RootModule().Resources[cloudFrontResource]
   264  	if !ok {
   265  		return nil, fmt.Errorf("Not found: %s", cloudFrontResource)
   266  	}
   267  
   268  	if cf.Primary.ID == "" {
   269  		return nil, fmt.Errorf("No Id is set")
   270  	}
   271  
   272  	cloudfrontconn := testAccProvider.Meta().(*AWSClient).cloudfrontconn
   273  
   274  	req := &cloudfront.GetDistributionInput{
   275  		Id: aws.String(cf.Primary.ID),
   276  	}
   277  
   278  	res, err := cloudfrontconn.GetDistribution(req)
   279  	if err != nil {
   280  		return nil, fmt.Errorf("Error retrieving CloudFront distribution: %s", err)
   281  	}
   282  
   283  	return res.Distribution, nil
   284  }
   285  
   286  func testAccAWSCloudFrontDistributionRetainConfig() string {
   287  	if _, ok := os.LookupEnv("TF_TEST_CLOUDFRONT_RETAIN"); ok {
   288  		return "retain_on_delete = true"
   289  	}
   290  	return ""
   291  }
   292  
   293  var originBucket = fmt.Sprintf(`
   294  resource "aws_s3_bucket" "s3_bucket_origin" {
   295  	bucket = "mybucket.${var.rand_id}"
   296  	acl = "public-read"
   297  }
   298  `)
   299  
   300  var logBucket = fmt.Sprintf(`
   301  resource "aws_s3_bucket" "s3_bucket_logs" {
   302  	bucket = "mylogs.${var.rand_id}"
   303  	acl = "public-read"
   304  }
   305  `)
   306  
   307  var testAccAWSCloudFrontDistributionS3Config = `
   308  variable rand_id {
   309  	default = %d
   310  }
   311  
   312  # origin bucket
   313  %s
   314  
   315  # log bucket
   316  %s
   317  
   318  resource "aws_cloudfront_distribution" "s3_distribution" {
   319  	origin {
   320  		domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com"
   321  		origin_id = "myS3Origin"
   322  	}
   323  	enabled = true
   324  	default_root_object = "index.html"
   325  	logging_config {
   326  		include_cookies = false
   327  		bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com"
   328  		prefix = "myprefix"
   329  	}
   330  	aliases = [ "mysite.${var.rand_id}.example.com", "yoursite.${var.rand_id}.example.com" ]
   331  	default_cache_behavior {
   332  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   333  		cached_methods = [ "GET", "HEAD" ]
   334  		target_origin_id = "myS3Origin"
   335  		forwarded_values {
   336  			query_string = false
   337  			cookies {
   338  				forward = "none"
   339  			}
   340  		}
   341  		viewer_protocol_policy = "allow-all"
   342  		min_ttl = 0
   343  		default_ttl = 3600
   344  		max_ttl = 86400
   345  	}
   346  	price_class = "PriceClass_200"
   347  	restrictions {
   348  		geo_restriction {
   349  			restriction_type = "whitelist"
   350  			locations = [ "US", "CA", "GB", "DE" ]
   351  		}
   352  	}
   353  	viewer_certificate {
   354  		cloudfront_default_certificate = true
   355  	}
   356  	%s
   357  }
   358  `
   359  
   360  var testAccAWSCloudFrontDistributionS3ConfigWithTags = `
   361  variable rand_id {
   362  	default = %d
   363  }
   364  
   365  # origin bucket
   366  %s
   367  
   368  # log bucket
   369  %s
   370  
   371  resource "aws_cloudfront_distribution" "s3_distribution" {
   372  	origin {
   373  		domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com"
   374  		origin_id = "myS3Origin"
   375  	}
   376  	enabled = true
   377  	default_root_object = "index.html"
   378  	aliases = [ "mysite.${var.rand_id}.example.com", "yoursite.${var.rand_id}.example.com" ]
   379  	default_cache_behavior {
   380  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   381  		cached_methods = [ "GET", "HEAD" ]
   382  		target_origin_id = "myS3Origin"
   383  		forwarded_values {
   384  			query_string = false
   385  			cookies {
   386  				forward = "none"
   387  			}
   388  		}
   389  		viewer_protocol_policy = "allow-all"
   390  		min_ttl = 0
   391  		default_ttl = 3600
   392  		max_ttl = 86400
   393  	}
   394  	price_class = "PriceClass_200"
   395  	restrictions {
   396  		geo_restriction {
   397  			restriction_type = "whitelist"
   398  			locations = [ "US", "CA", "GB", "DE" ]
   399  		}
   400  	}
   401  	viewer_certificate {
   402  		cloudfront_default_certificate = true
   403  	}
   404  	tags {
   405              environment = "production"
   406              account = "main"
   407  	}
   408  	%s
   409  }
   410  `
   411  
   412  var testAccAWSCloudFrontDistributionS3ConfigWithTagsUpdated = `
   413  variable rand_id {
   414  	default = %d
   415  }
   416  
   417  # origin bucket
   418  %s
   419  
   420  # log bucket
   421  %s
   422  
   423  resource "aws_cloudfront_distribution" "s3_distribution" {
   424  	origin {
   425  		domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com"
   426  		origin_id = "myS3Origin"
   427  	}
   428  	enabled = true
   429  	default_root_object = "index.html"
   430  	aliases = [ "mysite.${var.rand_id}.example.com", "yoursite.${var.rand_id}.example.com" ]
   431  	default_cache_behavior {
   432  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   433  		cached_methods = [ "GET", "HEAD" ]
   434  		target_origin_id = "myS3Origin"
   435  		forwarded_values {
   436  			query_string = false
   437  			cookies {
   438  				forward = "none"
   439  			}
   440  		}
   441  		viewer_protocol_policy = "allow-all"
   442  		min_ttl = 0
   443  		default_ttl = 3600
   444  		max_ttl = 86400
   445  	}
   446  	price_class = "PriceClass_200"
   447  	restrictions {
   448  		geo_restriction {
   449  			restriction_type = "whitelist"
   450  			locations = [ "US", "CA", "GB", "DE" ]
   451  		}
   452  	}
   453  	viewer_certificate {
   454  		cloudfront_default_certificate = true
   455  	}
   456  	tags {
   457              environment = "dev"
   458  	}
   459  	%s
   460  }
   461  `
   462  
   463  var testAccAWSCloudFrontDistributionCustomConfig = fmt.Sprintf(`
   464  variable rand_id {
   465  	default = %d
   466  }
   467  
   468  # log bucket
   469  %s
   470  
   471  resource "aws_cloudfront_distribution" "custom_distribution" {
   472  	origin {
   473  		domain_name = "www.example.com"
   474  		origin_id = "myCustomOrigin"
   475  		custom_origin_config {
   476  			http_port = 80
   477  			https_port = 443
   478  			origin_protocol_policy = "http-only"
   479  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   480  			origin_read_timeout = 30
   481  			origin_keepalive_timeout = 5
   482  		}
   483  	}
   484  	enabled = true
   485  	comment = "Some comment"
   486  	default_root_object = "index.html"
   487  	logging_config {
   488  		include_cookies = false
   489  		bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com"
   490  		prefix = "myprefix"
   491  	}
   492  	aliases = [ "mysite.${var.rand_id}.example.com", "*.yoursite.${var.rand_id}.example.com" ]
   493  	default_cache_behavior {
   494  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   495  		cached_methods = [ "GET", "HEAD" ]
   496  		target_origin_id = "myCustomOrigin"
   497  		smooth_streaming = false
   498  		forwarded_values {
   499  			query_string = false
   500  			cookies {
   501  				forward = "all"
   502  			}
   503  		}
   504  		viewer_protocol_policy = "allow-all"
   505  		min_ttl = 0
   506  		default_ttl = 3600
   507  		max_ttl = 86400
   508  	}
   509  	price_class = "PriceClass_200"
   510  	restrictions {
   511  		geo_restriction {
   512  			restriction_type = "whitelist"
   513  			locations = [ "US", "CA", "GB", "DE" ]
   514  		}
   515  	}
   516  	viewer_certificate {
   517  		cloudfront_default_certificate = true
   518  	}
   519  	%s
   520  }
   521  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), logBucket, testAccAWSCloudFrontDistributionRetainConfig())
   522  
   523  var testAccAWSCloudFrontDistributionMultiOriginConfig = fmt.Sprintf(`
   524  variable rand_id {
   525  	default = %d
   526  }
   527  
   528  # origin bucket
   529  %s
   530  
   531  # log bucket
   532  %s
   533  
   534  resource "aws_cloudfront_distribution" "multi_origin_distribution" {
   535  	origin {
   536  		domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com"
   537  		origin_id = "myS3Origin"
   538  	}
   539  	origin {
   540  		domain_name = "www.example.com"
   541  		origin_id = "myCustomOrigin"
   542  		custom_origin_config {
   543  			http_port = 80
   544  			https_port = 443
   545  			origin_protocol_policy = "http-only"
   546  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   547  			origin_keepalive_timeout = 45
   548  		}
   549  	}
   550  	enabled = true
   551  	comment = "Some comment"
   552  	default_root_object = "index.html"
   553  	logging_config {
   554  		include_cookies = false
   555  		bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com"
   556  		prefix = "myprefix"
   557  	}
   558  	aliases = [ "mysite.${var.rand_id}.example.com", "*.yoursite.${var.rand_id}.example.com" ]
   559  	default_cache_behavior {
   560  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   561  		cached_methods = [ "GET", "HEAD" ]
   562  		target_origin_id = "myS3Origin"
   563  		smooth_streaming = true
   564  		forwarded_values {
   565  			query_string = false
   566  			cookies {
   567  				forward = "all"
   568  			}
   569  		}
   570  		min_ttl = 100
   571  		default_ttl = 100
   572  		max_ttl = 100
   573  		viewer_protocol_policy = "allow-all"
   574  	}
   575  	cache_behavior {
   576  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   577  		cached_methods = [ "GET", "HEAD" ]
   578  		target_origin_id = "myS3Origin"
   579  		forwarded_values {
   580  			query_string = true
   581  			cookies {
   582  				forward = "none"
   583  			}
   584  		}
   585  		min_ttl = 50
   586  		default_ttl = 50
   587  		max_ttl = 50
   588  		viewer_protocol_policy = "allow-all"
   589  		path_pattern = "images1/*.jpg"
   590  	}
   591  	cache_behavior {
   592  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   593  		cached_methods = [ "GET", "HEAD" ]
   594  		target_origin_id = "myCustomOrigin"
   595  		forwarded_values {
   596  			query_string = true
   597  			cookies {
   598  				forward = "none"
   599  			}
   600  		}
   601  		min_ttl = 50
   602  		default_ttl = 50
   603  		max_ttl = 50
   604  		viewer_protocol_policy = "allow-all"
   605  		path_pattern = "images2/*.jpg"
   606  	}
   607  
   608  	price_class = "PriceClass_All"
   609  	custom_error_response {
   610  		error_code = 404
   611  		response_page_path = "/error-pages/404.html"
   612  		response_code = 200
   613  		error_caching_min_ttl = 30
   614  	}
   615  	restrictions {
   616  		geo_restriction {
   617  			restriction_type = "none"
   618  		}
   619  	}
   620  	viewer_certificate {
   621  		cloudfront_default_certificate = true
   622  	}
   623  	%s
   624  }
   625  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
   626  
   627  var testAccAWSCloudFrontDistributionNoCustomErroResponseInfo = fmt.Sprintf(`
   628  variable rand_id {
   629  	default = %d
   630  }
   631  
   632  resource "aws_cloudfront_distribution" "no_custom_error_responses" {
   633  	origin {
   634  		domain_name = "www.example.com"
   635  		origin_id = "myCustomOrigin"
   636  		custom_origin_config {
   637  			http_port = 80
   638  			https_port = 443
   639  			origin_protocol_policy = "http-only"
   640  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   641  		}
   642  	}
   643  	enabled = true
   644  	comment = "Some comment"
   645  	default_cache_behavior {
   646  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   647  		cached_methods = [ "GET", "HEAD" ]
   648  		target_origin_id = "myCustomOrigin"
   649  		smooth_streaming = false
   650  		forwarded_values {
   651  			query_string = false
   652  			cookies {
   653  				forward = "all"
   654  			}
   655  		}
   656  		viewer_protocol_policy = "allow-all"
   657  		min_ttl = 0
   658  		default_ttl = 3600
   659  		max_ttl = 86400
   660  	}
   661  	custom_error_response {
   662  		error_code = 404
   663  		error_caching_min_ttl = 30
   664  	}
   665  	restrictions {
   666  		geo_restriction {
   667  			restriction_type = "whitelist"
   668  			locations = [ "US", "CA", "GB", "DE" ]
   669  		}
   670  	}
   671  	viewer_certificate {
   672  		cloudfront_default_certificate = true
   673  	}
   674  	%s
   675  }
   676  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
   677  
   678  var testAccAWSCloudFrontDistributionNoOptionalItemsConfig = fmt.Sprintf(`
   679  variable rand_id {
   680  	default = %d
   681  }
   682  
   683  resource "aws_cloudfront_distribution" "no_optional_items" {
   684  	origin {
   685  		domain_name = "www.example.com"
   686  		origin_id = "myCustomOrigin"
   687  		custom_origin_config {
   688  			http_port = 80
   689  			https_port = 443
   690  			origin_protocol_policy = "http-only"
   691  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   692  		}
   693  	}
   694  	enabled = true
   695  	comment = "Some comment"
   696  	default_cache_behavior {
   697  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   698  		cached_methods = [ "GET", "HEAD" ]
   699  		target_origin_id = "myCustomOrigin"
   700  		smooth_streaming = false
   701  		forwarded_values {
   702  			query_string = false
   703  			cookies {
   704  				forward = "all"
   705  			}
   706  		}
   707  		viewer_protocol_policy = "allow-all"
   708  		min_ttl = 0
   709  		default_ttl = 3600
   710  		max_ttl = 86400
   711  	}
   712  	restrictions {
   713  		geo_restriction {
   714  			restriction_type = "whitelist"
   715  			locations = [ "US", "CA", "GB", "DE" ]
   716  		}
   717  	}
   718  	viewer_certificate {
   719  		cloudfront_default_certificate = true
   720  	}
   721  	%s
   722  }
   723  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
   724  
   725  var testAccAWSCloudFrontDistributionHTTP11Config = fmt.Sprintf(`
   726  variable rand_id {
   727  	default = %d
   728  }
   729  
   730  resource "aws_cloudfront_distribution" "http_1_1" {
   731  	origin {
   732  		domain_name = "www.example.com"
   733  		origin_id = "myCustomOrigin"
   734  		custom_origin_config {
   735  			http_port = 80
   736  			https_port = 443
   737  			origin_protocol_policy = "http-only"
   738  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   739  		}
   740  	}
   741  	enabled = true
   742  	comment = "Some comment"
   743  	default_cache_behavior {
   744  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   745  		cached_methods = [ "GET", "HEAD" ]
   746  		target_origin_id = "myCustomOrigin"
   747  		smooth_streaming = false
   748  		forwarded_values {
   749  			query_string = false
   750  			cookies {
   751  				forward = "all"
   752  			}
   753  		}
   754  		viewer_protocol_policy = "allow-all"
   755  		min_ttl = 0
   756  		default_ttl = 3600
   757  		max_ttl = 86400
   758  	}
   759  	http_version = "http1.1"
   760  	restrictions {
   761  		geo_restriction {
   762  			restriction_type = "whitelist"
   763  			locations = [ "US", "CA", "GB", "DE" ]
   764  		}
   765  	}
   766  	viewer_certificate {
   767  		cloudfront_default_certificate = true
   768  	}
   769  	%s
   770  }
   771  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
   772  
   773  var testAccAWSCloudFrontDistributionIsIPV6EnabledConfig = fmt.Sprintf(`
   774  variable rand_id {
   775  	default = %d
   776  }
   777  
   778  resource "aws_cloudfront_distribution" "is_ipv6_enabled" {
   779  	origin {
   780  		domain_name = "www.example.com"
   781  		origin_id = "myCustomOrigin"
   782  		custom_origin_config {
   783  			http_port = 80
   784  			https_port = 443
   785  			origin_protocol_policy = "http-only"
   786  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   787  		}
   788  	}
   789  	enabled = true
   790  	is_ipv6_enabled = true
   791  	comment = "Some comment"
   792  	default_cache_behavior {
   793  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   794  		cached_methods = [ "GET", "HEAD" ]
   795  		target_origin_id = "myCustomOrigin"
   796  		smooth_streaming = false
   797  		forwarded_values {
   798  			query_string = false
   799  			cookies {
   800  				forward = "all"
   801  			}
   802  		}
   803  		viewer_protocol_policy = "allow-all"
   804  		min_ttl = 0
   805  		default_ttl = 3600
   806  		max_ttl = 86400
   807  	}
   808  	http_version = "http1.1"
   809  	restrictions {
   810  		geo_restriction {
   811  			restriction_type = "whitelist"
   812  			locations = [ "US", "CA", "GB", "DE" ]
   813  		}
   814  	}
   815  	viewer_certificate {
   816  		cloudfront_default_certificate = true
   817  	}
   818  	%s
   819  }
   820  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())