Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 024818d

Browse files
✨ add example: minimal
1 parent 54c5184 commit 024818d

File tree

9 files changed

+152
-11
lines changed

9 files changed

+152
-11
lines changed

‎.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
node_modules/
22
.terraform/
3+
terraform.tfstate
4+
terraform.tfstate.backup
5+
terraform.tfvars

‎examples/minimal/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Minimal - aws-lambda-edge-basic-auth-terraform</title>
6+
</head>
7+
<body>
8+
<h1>Minimal - aws-lambda-edge-basic-auth-terraform</h1>
9+
<p>If you saw user/password prompt before you see this page, it's working!</p>
10+
</body>
11+
</html>

‎examples/minimal/main.tf

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
}

‎examples/minimal/outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "url" {
2+
value = "${format("https://%s", "${aws_cloudfront_distribution.test.domain_name}")}"
3+
}

‎examples/minimal/variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
variable "aws_access_key" {
2+
type = "string"
3+
description = "AWS Access Key"
4+
}
5+
6+
variable "aws_secret_key" {
7+
type = "string"
8+
description = "AWS Secret Key"
9+
}
10+
11+
variable "region" {
12+
type = "string"
13+
description = "AWS Region"
14+
}
15+
16+
variable "s3_bucket_name" {
17+
type = "string"
18+
description = "AWS S3 Bucket name for static web hosting"
19+
}
20+
21+
variable "basic_auth_credentials" {
22+
type = "map"
23+
description = "Credentials for Basic Authentication. Pass a map composed of 'user' and 'password'."
24+
}
383 Bytes
Binary file not shown.

‎module/main.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ EOF
3030
#
3131

3232
resource "aws_iam_role_policy" "lambda" {
33-
role = "${aws_iam_role.lambda}"
33+
role = "${aws_iam_role.lambda.id}"
3434

3535
policy = <<EOF
3636
{
@@ -55,13 +55,13 @@ EOF
5555
#
5656

5757
resource "aws_lambda_function" "basic_auth" {
58-
filename = "${path.module}/functions/lambda-edge-basic-auth-function.zip"
59-
function_name = "${var.function_name}"
60-
role = "${aws_iam_role.lambda}"
61-
handler = "basic-auth.handler"
58+
filename = "${path.module}/functions/lambda-edge-basic-auth-function.zip"
59+
function_name = "${var.function_name}"
60+
role = "${aws_iam_role.lambda.arn}"
61+
handler = "basic-auth.handler"
6262
source_code_hash = "${base64sha256(file("${path.module}/functions/lambda-edge-basic-auth-function.zip"))}"
63-
runtime = "nodejs8.10"
64-
description = "Protect CloudFront distributions with Basic Authentication"
63+
runtime = "nodejs8.10"
64+
description = "Protect CloudFront distributions with Basic Authentication"
6565
}
6666

6767
###
@@ -74,6 +74,6 @@ resource "aws_secretsmanager_secret" "basic_auth_credentials" {
7474
}
7575

7676
resource "aws_secretsmanager_secret_version" "basic_auth_credentials" {
77-
secret_id = "${aws_secretsmanager_secret.basic_auth_credentials.id}"
77+
secret_id = "${aws_secretsmanager_secret.basic_auth_credentials.id}"
7878
secret_string = "${jsonencode(var.basic_auth_credentials)}"
7979
}

‎module/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "lambda_arn" {
2+
value = "${aws_lambda_function.basic_auth.arn}"
3+
description = "Lambda function ARN"
4+
}

‎module/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
variable "function_name" {
2-
type = "string"
3-
default = "basicAuth"
2+
type = "string"
3+
default = "basicAuth"
44
description = "Lambda function name"
55
}
66

77
variable "basic_auth_credentials" {
8-
type = "map"
8+
type = "map"
99
description = "Credentials for Basic Authentication. Pass a map composed of 'user' and 'password'."
1010
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /