github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/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  			resource.TestStep{
    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  			resource.TestStep{
    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  			resource.TestStep{
   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  			resource.TestStep{
   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  			resource.TestStep{
   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  			resource.TestStep{
   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  			resource.TestStep{
   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  		}
   481  	}
   482  	enabled = true
   483  	comment = "Some comment"
   484  	default_root_object = "index.html"
   485  	logging_config {
   486  		include_cookies = false
   487  		bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com"
   488  		prefix = "myprefix"
   489  	}
   490  	aliases = [ "mysite.${var.rand_id}.example.com", "*.yoursite.${var.rand_id}.example.com" ]
   491  	default_cache_behavior {
   492  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   493  		cached_methods = [ "GET", "HEAD" ]
   494  		target_origin_id = "myCustomOrigin"
   495  		smooth_streaming = false
   496  		forwarded_values {
   497  			query_string = false
   498  			cookies {
   499  				forward = "all"
   500  			}
   501  		}
   502  		viewer_protocol_policy = "allow-all"
   503  		min_ttl = 0
   504  		default_ttl = 3600
   505  		max_ttl = 86400
   506  	}
   507  	price_class = "PriceClass_200"
   508  	restrictions {
   509  		geo_restriction {
   510  			restriction_type = "whitelist"
   511  			locations = [ "US", "CA", "GB", "DE" ]
   512  		}
   513  	}
   514  	viewer_certificate {
   515  		cloudfront_default_certificate = true
   516  	}
   517  	%s
   518  }
   519  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), logBucket, testAccAWSCloudFrontDistributionRetainConfig())
   520  
   521  var testAccAWSCloudFrontDistributionMultiOriginConfig = fmt.Sprintf(`
   522  variable rand_id {
   523  	default = %d
   524  }
   525  
   526  # origin bucket
   527  %s
   528  
   529  # log bucket
   530  %s
   531  
   532  resource "aws_cloudfront_distribution" "multi_origin_distribution" {
   533  	origin {
   534  		domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com"
   535  		origin_id = "myS3Origin"
   536  	}
   537  	origin {
   538  		domain_name = "www.example.com"
   539  		origin_id = "myCustomOrigin"
   540  		custom_origin_config {
   541  			http_port = 80
   542  			https_port = 443
   543  			origin_protocol_policy = "http-only"
   544  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   545  		}
   546  	}
   547  	enabled = true
   548  	comment = "Some comment"
   549  	default_root_object = "index.html"
   550  	logging_config {
   551  		include_cookies = false
   552  		bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com"
   553  		prefix = "myprefix"
   554  	}
   555  	aliases = [ "mysite.${var.rand_id}.example.com", "*.yoursite.${var.rand_id}.example.com" ]
   556  	default_cache_behavior {
   557  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   558  		cached_methods = [ "GET", "HEAD" ]
   559  		target_origin_id = "myS3Origin"
   560  		smooth_streaming = true
   561  		forwarded_values {
   562  			query_string = false
   563  			cookies {
   564  				forward = "all"
   565  			}
   566  		}
   567  		min_ttl = 100
   568  		default_ttl = 100
   569  		max_ttl = 100
   570  		viewer_protocol_policy = "allow-all"
   571  	}
   572  	cache_behavior {
   573  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   574  		cached_methods = [ "GET", "HEAD" ]
   575  		target_origin_id = "myS3Origin"
   576  		forwarded_values {
   577  			query_string = true
   578  			cookies {
   579  				forward = "none"
   580  			}
   581  		}
   582  		min_ttl = 50
   583  		default_ttl = 50
   584  		max_ttl = 50
   585  		viewer_protocol_policy = "allow-all"
   586  		path_pattern = "images1/*.jpg"
   587  	}
   588  	cache_behavior {
   589  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   590  		cached_methods = [ "GET", "HEAD" ]
   591  		target_origin_id = "myCustomOrigin"
   592  		forwarded_values {
   593  			query_string = true
   594  			cookies {
   595  				forward = "none"
   596  			}
   597  		}
   598  		min_ttl = 50
   599  		default_ttl = 50
   600  		max_ttl = 50
   601  		viewer_protocol_policy = "allow-all"
   602  		path_pattern = "images2/*.jpg"
   603  	}
   604  
   605  	price_class = "PriceClass_All"
   606  	custom_error_response {
   607  		error_code = 404
   608  		response_page_path = "/error-pages/404.html"
   609  		response_code = 200
   610  		error_caching_min_ttl = 30
   611  	}
   612  	restrictions {
   613  		geo_restriction {
   614  			restriction_type = "none"
   615  		}
   616  	}
   617  	viewer_certificate {
   618  		cloudfront_default_certificate = true
   619  	}
   620  	%s
   621  }
   622  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig())
   623  
   624  var testAccAWSCloudFrontDistributionNoCustomErroResponseInfo = fmt.Sprintf(`
   625  variable rand_id {
   626  	default = %d
   627  }
   628  
   629  resource "aws_cloudfront_distribution" "no_custom_error_responses" {
   630  	origin {
   631  		domain_name = "www.example.com"
   632  		origin_id = "myCustomOrigin"
   633  		custom_origin_config {
   634  			http_port = 80
   635  			https_port = 443
   636  			origin_protocol_policy = "http-only"
   637  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   638  		}
   639  	}
   640  	enabled = true
   641  	comment = "Some comment"
   642  	default_cache_behavior {
   643  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   644  		cached_methods = [ "GET", "HEAD" ]
   645  		target_origin_id = "myCustomOrigin"
   646  		smooth_streaming = false
   647  		forwarded_values {
   648  			query_string = false
   649  			cookies {
   650  				forward = "all"
   651  			}
   652  		}
   653  		viewer_protocol_policy = "allow-all"
   654  		min_ttl = 0
   655  		default_ttl = 3600
   656  		max_ttl = 86400
   657  	}
   658  	custom_error_response {
   659  		error_code = 404
   660  		error_caching_min_ttl = 30
   661  	}
   662  	restrictions {
   663  		geo_restriction {
   664  			restriction_type = "whitelist"
   665  			locations = [ "US", "CA", "GB", "DE" ]
   666  		}
   667  	}
   668  	viewer_certificate {
   669  		cloudfront_default_certificate = true
   670  	}
   671  	%s
   672  }
   673  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
   674  
   675  var testAccAWSCloudFrontDistributionNoOptionalItemsConfig = fmt.Sprintf(`
   676  variable rand_id {
   677  	default = %d
   678  }
   679  
   680  resource "aws_cloudfront_distribution" "no_optional_items" {
   681  	origin {
   682  		domain_name = "www.example.com"
   683  		origin_id = "myCustomOrigin"
   684  		custom_origin_config {
   685  			http_port = 80
   686  			https_port = 443
   687  			origin_protocol_policy = "http-only"
   688  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   689  		}
   690  	}
   691  	enabled = true
   692  	comment = "Some comment"
   693  	default_cache_behavior {
   694  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   695  		cached_methods = [ "GET", "HEAD" ]
   696  		target_origin_id = "myCustomOrigin"
   697  		smooth_streaming = false
   698  		forwarded_values {
   699  			query_string = false
   700  			cookies {
   701  				forward = "all"
   702  			}
   703  		}
   704  		viewer_protocol_policy = "allow-all"
   705  		min_ttl = 0
   706  		default_ttl = 3600
   707  		max_ttl = 86400
   708  	}
   709  	restrictions {
   710  		geo_restriction {
   711  			restriction_type = "whitelist"
   712  			locations = [ "US", "CA", "GB", "DE" ]
   713  		}
   714  	}
   715  	viewer_certificate {
   716  		cloudfront_default_certificate = true
   717  	}
   718  	%s
   719  }
   720  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
   721  
   722  var testAccAWSCloudFrontDistributionHTTP11Config = fmt.Sprintf(`
   723  variable rand_id {
   724  	default = %d
   725  }
   726  
   727  resource "aws_cloudfront_distribution" "http_1_1" {
   728  	origin {
   729  		domain_name = "www.example.com"
   730  		origin_id = "myCustomOrigin"
   731  		custom_origin_config {
   732  			http_port = 80
   733  			https_port = 443
   734  			origin_protocol_policy = "http-only"
   735  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   736  		}
   737  	}
   738  	enabled = true
   739  	comment = "Some comment"
   740  	default_cache_behavior {
   741  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   742  		cached_methods = [ "GET", "HEAD" ]
   743  		target_origin_id = "myCustomOrigin"
   744  		smooth_streaming = false
   745  		forwarded_values {
   746  			query_string = false
   747  			cookies {
   748  				forward = "all"
   749  			}
   750  		}
   751  		viewer_protocol_policy = "allow-all"
   752  		min_ttl = 0
   753  		default_ttl = 3600
   754  		max_ttl = 86400
   755  	}
   756  	http_version = "http1.1"
   757  	restrictions {
   758  		geo_restriction {
   759  			restriction_type = "whitelist"
   760  			locations = [ "US", "CA", "GB", "DE" ]
   761  		}
   762  	}
   763  	viewer_certificate {
   764  		cloudfront_default_certificate = true
   765  	}
   766  	%s
   767  }
   768  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())
   769  
   770  var testAccAWSCloudFrontDistributionIsIPV6EnabledConfig = fmt.Sprintf(`
   771  variable rand_id {
   772  	default = %d
   773  }
   774  
   775  resource "aws_cloudfront_distribution" "is_ipv6_enabled" {
   776  	origin {
   777  		domain_name = "www.example.com"
   778  		origin_id = "myCustomOrigin"
   779  		custom_origin_config {
   780  			http_port = 80
   781  			https_port = 443
   782  			origin_protocol_policy = "http-only"
   783  			origin_ssl_protocols = [ "SSLv3", "TLSv1" ]
   784  		}
   785  	}
   786  	enabled = true
   787  	is_ipv6_enabled = true
   788  	comment = "Some comment"
   789  	default_cache_behavior {
   790  		allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
   791  		cached_methods = [ "GET", "HEAD" ]
   792  		target_origin_id = "myCustomOrigin"
   793  		smooth_streaming = false
   794  		forwarded_values {
   795  			query_string = false
   796  			cookies {
   797  				forward = "all"
   798  			}
   799  		}
   800  		viewer_protocol_policy = "allow-all"
   801  		min_ttl = 0
   802  		default_ttl = 3600
   803  		max_ttl = 86400
   804  	}
   805  	http_version = "http1.1"
   806  	restrictions {
   807  		geo_restriction {
   808  			restriction_type = "whitelist"
   809  			locations = [ "US", "CA", "GB", "DE" ]
   810  		}
   811  	}
   812  	viewer_certificate {
   813  		cloudfront_default_certificate = true
   814  	}
   815  	%s
   816  }
   817  `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())