|
| 1 | +### |
| 2 | +# Providers |
| 3 | +# |
| 4 | + |
| 5 | +provider "aws" { |
| 6 | + access_key = "${var.aws_access_key}" |
| 7 | + secret_key = "${var.aws_secret_key}" |
| 8 | + region = "${var.region}" |
| 9 | +} |
| 10 | + |
| 11 | +provider "aws" { |
| 12 | + alias = "us-east-1" |
| 13 | + access_key = "${var.aws_access_key}" |
| 14 | + secret_key = "${var.aws_secret_key}" |
| 15 | + region = "us-east-1" |
| 16 | +} |
| 17 | + |
| 18 | +### |
| 19 | +# Modules |
| 20 | +# |
| 21 | + |
| 22 | +module "basic_auth" { |
| 23 | + source = "../../module" |
| 24 | + basic_auth_credentials = "${var.basic_auth_credentials}" |
| 25 | + |
| 26 | + # All Lambda@Edge functions must be put on us-east-1. |
| 27 | + providers = { |
| 28 | + aws = "aws.us-east-1" |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +### |
| 33 | +# S3 |
| 34 | +# |
| 35 | + |
| 36 | +resource "aws_s3_bucket" "test" { |
| 37 | + bucket = "${var.s3_bucket_name}" |
| 38 | + acl = "private" |
| 39 | +} |
| 40 | + |
| 41 | +resource "aws_s3_bucket_object" "test" { |
| 42 | + bucket = "${aws_s3_bucket.test.id}" |
| 43 | + key = "index.html" |
| 44 | + source = "index.html" |
| 45 | + etag = "${md5(file("index.html"))}" |
| 46 | +} |
| 47 | + |
| 48 | +### |
| 49 | +# CloudFront |
| 50 | +# |
| 51 | + |
| 52 | +resource "aws_cloudfront_distribution" "test" { |
| 53 | + origin { |
| 54 | + domain_name = "${aws_s3_bucket.test.bucket_regional_domain_name}" |
| 55 | + origin_id = "S3-${aws_s3_bucket.test.id}" |
| 56 | + } |
| 57 | + |
| 58 | + enabled = true |
| 59 | + is_ipv6_enabled = true |
| 60 | + comment = "aws-lambda-edge-basic-auth-terraform minimal example" |
| 61 | + default_root_object = "index.html" |
| 62 | + |
| 63 | + default_cache_behavior { |
| 64 | + allowed_methods = ["GET", "HEAD"] |
| 65 | + cached_methods = ["GET", "HEAD"] |
| 66 | + target_origin_id = "S3-${aws_s3_bucket.test.id}" |
| 67 | + viewer_protocol_policy = "redirect-to-https" |
| 68 | + min_ttl = 0 |
| 69 | + default_ttl = 3600 |
| 70 | + max_ttl = 86400 |
| 71 | + |
| 72 | + forwarded_values { |
| 73 | + query_string = true |
| 74 | + |
| 75 | + cookies { |
| 76 | + forward = "all" |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + lambda_function_association { |
| 81 | + event_type = "viewer-request" |
| 82 | + lambda_arn = "${module.basic_auth.lambda_arn}" |
| 83 | + include_body = false |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + viewer_certificate { |
| 88 | + cloudfront_default_certificate = true |
| 89 | + } |
| 90 | + |
| 91 | + restrictions { |
| 92 | + geo_restriction { |
| 93 | + restriction_type = "none" |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments