github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/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_noCustomErrorResponseConfig(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: testAccAWSCloudFrontDistributionNoCustomErroResponseInfo, 188 Check: resource.ComposeTestCheckFunc( 189 testAccCheckCloudFrontDistributionExistence( 190 "aws_cloudfront_distribution.no_custom_error_responses", 191 ), 192 ), 193 }, 194 }, 195 }) 196 } 197 198 func TestResourceAWSCloudFrontDistribution_validateHTTP(t *testing.T) { 199 var value string 200 var errors []error 201 202 value = "incorrect" 203 _, errors = validateHTTP(value, "http_version") 204 if len(errors) == 0 { 205 t.Fatalf("Expected %q to trigger a validation error", value) 206 } 207 208 value = "http1.1" 209 _, errors = validateHTTP(value, "http_version") 210 if len(errors) != 0 { 211 t.Fatalf("Expected %q not to trigger a validation error", value) 212 } 213 } 214 215 func testAccCheckCloudFrontDistributionDestroy(s *terraform.State) error { 216 for k, rs := range s.RootModule().Resources { 217 if rs.Type != "aws_cloudfront_distribution" { 218 continue 219 } 220 dist, err := testAccAuxCloudFrontGetDistributionConfig(s, k) 221 if err == nil { 222 if _, ok := os.LookupEnv("TF_TEST_CLOUDFRONT_RETAIN"); ok { 223 if *dist.DistributionConfig.Enabled != false { 224 return fmt.Errorf("CloudFront distribution should be disabled") 225 } 226 return nil 227 } 228 return fmt.Errorf("CloudFront distribution did not destroy") 229 } 230 } 231 return nil 232 } 233 234 func testAccCheckCloudFrontDistributionExistence(cloudFrontResource string) resource.TestCheckFunc { 235 return func(s *terraform.State) error { 236 _, err := testAccAuxCloudFrontGetDistributionConfig(s, cloudFrontResource) 237 238 return err 239 } 240 } 241 242 func testAccAuxCloudFrontGetDistributionConfig(s *terraform.State, cloudFrontResource string) (*cloudfront.Distribution, error) { 243 cf, ok := s.RootModule().Resources[cloudFrontResource] 244 if !ok { 245 return nil, fmt.Errorf("Not found: %s", cloudFrontResource) 246 } 247 248 if cf.Primary.ID == "" { 249 return nil, fmt.Errorf("No Id is set") 250 } 251 252 cloudfrontconn := testAccProvider.Meta().(*AWSClient).cloudfrontconn 253 254 req := &cloudfront.GetDistributionInput{ 255 Id: aws.String(cf.Primary.ID), 256 } 257 258 res, err := cloudfrontconn.GetDistribution(req) 259 if err != nil { 260 return nil, fmt.Errorf("Error retrieving CloudFront distribution: %s", err) 261 } 262 263 return res.Distribution, nil 264 } 265 266 func testAccAWSCloudFrontDistributionRetainConfig() string { 267 if _, ok := os.LookupEnv("TF_TEST_CLOUDFRONT_RETAIN"); ok { 268 return "retain_on_delete = true" 269 } 270 return "" 271 } 272 273 var originBucket = fmt.Sprintf(` 274 resource "aws_s3_bucket" "s3_bucket_origin" { 275 bucket = "mybucket.${var.rand_id}" 276 acl = "public-read" 277 } 278 `) 279 280 var logBucket = fmt.Sprintf(` 281 resource "aws_s3_bucket" "s3_bucket_logs" { 282 bucket = "mylogs.${var.rand_id}" 283 acl = "public-read" 284 } 285 `) 286 287 var testAccAWSCloudFrontDistributionS3Config = ` 288 variable rand_id { 289 default = %d 290 } 291 292 # origin bucket 293 %s 294 295 # log bucket 296 %s 297 298 resource "aws_cloudfront_distribution" "s3_distribution" { 299 origin { 300 domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com" 301 origin_id = "myS3Origin" 302 } 303 enabled = true 304 default_root_object = "index.html" 305 logging_config { 306 include_cookies = false 307 bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com" 308 prefix = "myprefix" 309 } 310 aliases = [ "mysite.${var.rand_id}.example.com", "yoursite.${var.rand_id}.example.com" ] 311 default_cache_behavior { 312 allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ] 313 cached_methods = [ "GET", "HEAD" ] 314 target_origin_id = "myS3Origin" 315 forwarded_values { 316 query_string = false 317 cookies { 318 forward = "none" 319 } 320 } 321 viewer_protocol_policy = "allow-all" 322 min_ttl = 0 323 default_ttl = 3600 324 max_ttl = 86400 325 } 326 price_class = "PriceClass_200" 327 restrictions { 328 geo_restriction { 329 restriction_type = "whitelist" 330 locations = [ "US", "CA", "GB", "DE" ] 331 } 332 } 333 viewer_certificate { 334 cloudfront_default_certificate = true 335 } 336 %s 337 } 338 ` 339 340 var testAccAWSCloudFrontDistributionS3ConfigWithTags = ` 341 variable rand_id { 342 default = %d 343 } 344 345 # origin bucket 346 %s 347 348 # log bucket 349 %s 350 351 resource "aws_cloudfront_distribution" "s3_distribution" { 352 origin { 353 domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com" 354 origin_id = "myS3Origin" 355 } 356 enabled = true 357 default_root_object = "index.html" 358 aliases = [ "mysite.${var.rand_id}.example.com", "yoursite.${var.rand_id}.example.com" ] 359 default_cache_behavior { 360 allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ] 361 cached_methods = [ "GET", "HEAD" ] 362 target_origin_id = "myS3Origin" 363 forwarded_values { 364 query_string = false 365 cookies { 366 forward = "none" 367 } 368 } 369 viewer_protocol_policy = "allow-all" 370 min_ttl = 0 371 default_ttl = 3600 372 max_ttl = 86400 373 } 374 price_class = "PriceClass_200" 375 restrictions { 376 geo_restriction { 377 restriction_type = "whitelist" 378 locations = [ "US", "CA", "GB", "DE" ] 379 } 380 } 381 viewer_certificate { 382 cloudfront_default_certificate = true 383 } 384 tags { 385 environment = "production" 386 account = "main" 387 } 388 %s 389 } 390 ` 391 392 var testAccAWSCloudFrontDistributionS3ConfigWithTagsUpdated = ` 393 variable rand_id { 394 default = %d 395 } 396 397 # origin bucket 398 %s 399 400 # log bucket 401 %s 402 403 resource "aws_cloudfront_distribution" "s3_distribution" { 404 origin { 405 domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com" 406 origin_id = "myS3Origin" 407 } 408 enabled = true 409 default_root_object = "index.html" 410 aliases = [ "mysite.${var.rand_id}.example.com", "yoursite.${var.rand_id}.example.com" ] 411 default_cache_behavior { 412 allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ] 413 cached_methods = [ "GET", "HEAD" ] 414 target_origin_id = "myS3Origin" 415 forwarded_values { 416 query_string = false 417 cookies { 418 forward = "none" 419 } 420 } 421 viewer_protocol_policy = "allow-all" 422 min_ttl = 0 423 default_ttl = 3600 424 max_ttl = 86400 425 } 426 price_class = "PriceClass_200" 427 restrictions { 428 geo_restriction { 429 restriction_type = "whitelist" 430 locations = [ "US", "CA", "GB", "DE" ] 431 } 432 } 433 viewer_certificate { 434 cloudfront_default_certificate = true 435 } 436 tags { 437 environment = "dev" 438 } 439 %s 440 } 441 ` 442 443 var testAccAWSCloudFrontDistributionCustomConfig = fmt.Sprintf(` 444 variable rand_id { 445 default = %d 446 } 447 448 # log bucket 449 %s 450 451 resource "aws_cloudfront_distribution" "custom_distribution" { 452 origin { 453 domain_name = "www.example.com" 454 origin_id = "myCustomOrigin" 455 custom_origin_config { 456 http_port = 80 457 https_port = 443 458 origin_protocol_policy = "http-only" 459 origin_ssl_protocols = [ "SSLv3", "TLSv1" ] 460 } 461 } 462 enabled = true 463 comment = "Some comment" 464 default_root_object = "index.html" 465 logging_config { 466 include_cookies = false 467 bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com" 468 prefix = "myprefix" 469 } 470 aliases = [ "mysite.${var.rand_id}.example.com", "*.yoursite.${var.rand_id}.example.com" ] 471 default_cache_behavior { 472 allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ] 473 cached_methods = [ "GET", "HEAD" ] 474 target_origin_id = "myCustomOrigin" 475 smooth_streaming = false 476 forwarded_values { 477 query_string = false 478 cookies { 479 forward = "all" 480 } 481 } 482 viewer_protocol_policy = "allow-all" 483 min_ttl = 0 484 default_ttl = 3600 485 max_ttl = 86400 486 } 487 price_class = "PriceClass_200" 488 restrictions { 489 geo_restriction { 490 restriction_type = "whitelist" 491 locations = [ "US", "CA", "GB", "DE" ] 492 } 493 } 494 viewer_certificate { 495 cloudfront_default_certificate = true 496 } 497 %s 498 } 499 `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), logBucket, testAccAWSCloudFrontDistributionRetainConfig()) 500 501 var testAccAWSCloudFrontDistributionMultiOriginConfig = fmt.Sprintf(` 502 variable rand_id { 503 default = %d 504 } 505 506 # origin bucket 507 %s 508 509 # log bucket 510 %s 511 512 resource "aws_cloudfront_distribution" "multi_origin_distribution" { 513 origin { 514 domain_name = "${aws_s3_bucket.s3_bucket_origin.id}.s3.amazonaws.com" 515 origin_id = "myS3Origin" 516 } 517 origin { 518 domain_name = "www.example.com" 519 origin_id = "myCustomOrigin" 520 custom_origin_config { 521 http_port = 80 522 https_port = 443 523 origin_protocol_policy = "http-only" 524 origin_ssl_protocols = [ "SSLv3", "TLSv1" ] 525 } 526 } 527 enabled = true 528 comment = "Some comment" 529 default_root_object = "index.html" 530 logging_config { 531 include_cookies = false 532 bucket = "${aws_s3_bucket.s3_bucket_logs.id}.s3.amazonaws.com" 533 prefix = "myprefix" 534 } 535 aliases = [ "mysite.${var.rand_id}.example.com", "*.yoursite.${var.rand_id}.example.com" ] 536 default_cache_behavior { 537 allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ] 538 cached_methods = [ "GET", "HEAD" ] 539 target_origin_id = "myS3Origin" 540 smooth_streaming = true 541 forwarded_values { 542 query_string = false 543 cookies { 544 forward = "all" 545 } 546 } 547 min_ttl = 100 548 default_ttl = 100 549 max_ttl = 100 550 viewer_protocol_policy = "allow-all" 551 } 552 cache_behavior { 553 allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ] 554 cached_methods = [ "GET", "HEAD" ] 555 target_origin_id = "myS3Origin" 556 forwarded_values { 557 query_string = true 558 cookies { 559 forward = "none" 560 } 561 } 562 min_ttl = 50 563 default_ttl = 50 564 max_ttl = 50 565 viewer_protocol_policy = "allow-all" 566 path_pattern = "images1/*.jpg" 567 } 568 cache_behavior { 569 allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ] 570 cached_methods = [ "GET", "HEAD" ] 571 target_origin_id = "myCustomOrigin" 572 forwarded_values { 573 query_string = true 574 cookies { 575 forward = "none" 576 } 577 } 578 min_ttl = 50 579 default_ttl = 50 580 max_ttl = 50 581 viewer_protocol_policy = "allow-all" 582 path_pattern = "images2/*.jpg" 583 } 584 585 price_class = "PriceClass_All" 586 custom_error_response { 587 error_code = 404 588 response_page_path = "/error-pages/404.html" 589 response_code = 200 590 error_caching_min_ttl = 30 591 } 592 restrictions { 593 geo_restriction { 594 restriction_type = "none" 595 } 596 } 597 viewer_certificate { 598 cloudfront_default_certificate = true 599 } 600 %s 601 } 602 `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), originBucket, logBucket, testAccAWSCloudFrontDistributionRetainConfig()) 603 604 var testAccAWSCloudFrontDistributionNoCustomErroResponseInfo = fmt.Sprintf(` 605 variable rand_id { 606 default = %d 607 } 608 609 resource "aws_cloudfront_distribution" "no_custom_error_responses" { 610 origin { 611 domain_name = "www.example.com" 612 origin_id = "myCustomOrigin" 613 custom_origin_config { 614 http_port = 80 615 https_port = 443 616 origin_protocol_policy = "http-only" 617 origin_ssl_protocols = [ "SSLv3", "TLSv1" ] 618 } 619 } 620 enabled = true 621 comment = "Some comment" 622 default_cache_behavior { 623 allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ] 624 cached_methods = [ "GET", "HEAD" ] 625 target_origin_id = "myCustomOrigin" 626 smooth_streaming = false 627 forwarded_values { 628 query_string = false 629 cookies { 630 forward = "all" 631 } 632 } 633 viewer_protocol_policy = "allow-all" 634 min_ttl = 0 635 default_ttl = 3600 636 max_ttl = 86400 637 } 638 custom_error_response { 639 error_code = 404 640 error_caching_min_ttl = 30 641 } 642 restrictions { 643 geo_restriction { 644 restriction_type = "whitelist" 645 locations = [ "US", "CA", "GB", "DE" ] 646 } 647 } 648 viewer_certificate { 649 cloudfront_default_certificate = true 650 } 651 %s 652 } 653 `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig()) 654 655 var testAccAWSCloudFrontDistributionNoOptionalItemsConfig = fmt.Sprintf(` 656 variable rand_id { 657 default = %d 658 } 659 660 resource "aws_cloudfront_distribution" "no_optional_items" { 661 origin { 662 domain_name = "www.example.com" 663 origin_id = "myCustomOrigin" 664 custom_origin_config { 665 http_port = 80 666 https_port = 443 667 origin_protocol_policy = "http-only" 668 origin_ssl_protocols = [ "SSLv3", "TLSv1" ] 669 } 670 } 671 enabled = true 672 comment = "Some comment" 673 default_cache_behavior { 674 allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ] 675 cached_methods = [ "GET", "HEAD" ] 676 target_origin_id = "myCustomOrigin" 677 smooth_streaming = false 678 forwarded_values { 679 query_string = false 680 cookies { 681 forward = "all" 682 } 683 } 684 viewer_protocol_policy = "allow-all" 685 min_ttl = 0 686 default_ttl = 3600 687 max_ttl = 86400 688 } 689 restrictions { 690 geo_restriction { 691 restriction_type = "whitelist" 692 locations = [ "US", "CA", "GB", "DE" ] 693 } 694 } 695 viewer_certificate { 696 cloudfront_default_certificate = true 697 } 698 %s 699 } 700 `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig()) 701 702 var testAccAWSCloudFrontDistributionHTTP11Config = fmt.Sprintf(` 703 variable rand_id { 704 default = %d 705 } 706 707 resource "aws_cloudfront_distribution" "http_1_1" { 708 origin { 709 domain_name = "www.example.com" 710 origin_id = "myCustomOrigin" 711 custom_origin_config { 712 http_port = 80 713 https_port = 443 714 origin_protocol_policy = "http-only" 715 origin_ssl_protocols = [ "SSLv3", "TLSv1" ] 716 } 717 } 718 enabled = true 719 comment = "Some comment" 720 default_cache_behavior { 721 allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ] 722 cached_methods = [ "GET", "HEAD" ] 723 target_origin_id = "myCustomOrigin" 724 smooth_streaming = false 725 forwarded_values { 726 query_string = false 727 cookies { 728 forward = "all" 729 } 730 } 731 viewer_protocol_policy = "allow-all" 732 min_ttl = 0 733 default_ttl = 3600 734 max_ttl = 86400 735 } 736 http_version = "http1.1" 737 restrictions { 738 geo_restriction { 739 restriction_type = "whitelist" 740 locations = [ "US", "CA", "GB", "DE" ] 741 } 742 } 743 viewer_certificate { 744 cloudfront_default_certificate = true 745 } 746 %s 747 } 748 `, rand.New(rand.NewSource(time.Now().UnixNano())).Int(), testAccAWSCloudFrontDistributionRetainConfig())