Skip to content

Commit

Permalink
feat: introduce feature flag lab
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikFricke committed May 9, 2022
1 parent ab7223e commit 9da951c
Show file tree
Hide file tree
Showing 65 changed files with 429 additions and 55 deletions.
10 changes: 3 additions & 7 deletions 2-simple-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ In the first lab, we bootstrapped Terraform and created some resources. Finally,
3. Add the following lines to the JS file:
```js
exports.handler = async () => {
return { "message": process.env.RESPONSE };
return {
message: "Hello from Lambda! 👋"
};
};
```
4. Now, go back to the `main.tf` file and replace it:
Expand Down Expand Up @@ -52,9 +54,6 @@ In the first lab, we bootstrapped Terraform and created some resources. Finally,
handler = "helloworld.handler"
runtime = "nodejs12.x"
source_path = "./functions"
environment_variables = {
"RESPONSE" = "Hello from Lambda! 👋"
}
}
```
5. Run `terraform init`, then `terraform apply`, and confirm the changes with `yes`.
Expand Down Expand Up @@ -111,9 +110,6 @@ So, the Lambda function is in place and we can go to the next component: The API
handler = "helloworld.handler"
runtime = "nodejs12.x"
source_path = "./functions"
environment_variables = {
"RESPONSE" = "Hello from Lambda! 👋"
}
publish = true
allowed_triggers = {
Expand Down
4 changes: 3 additions & 1 deletion 2-simple-api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
exports.handler = async () => {
return { "message": process.env.RESPONSE };
return {
message: "Hello from Lambda! 👋"
};
};
3 changes: 0 additions & 3 deletions 2-simple-api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ module "lambda_function" {
handler = "helloworld.handler"
runtime = "nodejs12.x"
source_path = "./functions"
environment_variables = {
"RESPONSE" = "Hello from Lambda! 👋"
}

publish = true
allowed_triggers = {
Expand Down
4 changes: 3 additions & 1 deletion 3-environments/modules/api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
exports.handler = async () => {
return { "message": process.env.RESPONSE };
return {
message: "Hello from Lambda! 👋"
};
};
3 changes: 0 additions & 3 deletions 3-environments/modules/api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ module "lambda_function" {
handler = "helloworld.handler"
runtime = "nodejs12.x"
source_path = "${path.module}/functions"
environment_variables = {
"RESPONSE" = var.lambda_function_response
}

publish = true
allowed_triggers = {
Expand Down
6 changes: 0 additions & 6 deletions 3-environments/modules/api/variables.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
variable "lambda_function_response" {
type = string
description = "Body response of the hello world lambda function"
default = "Hello World :)"
}

variable "environment" {
type = string
description = "Identifier for the environment (e.g. staging, development or prod)"
Expand Down
5 changes: 5 additions & 0 deletions 4-feature-flags/modules/api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.handler = async () => {
return {
message: "Hello from Lambda! 👋"
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ module "lambda_function" {
handler = "helloworld.handler"
runtime = "nodejs12.x"
source_path = "${path.module}/functions"
environment_variables = {
"RESPONSE" = var.lambda_function_response
}

publish = true
allowed_triggers = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions 4-feature-flags/modules/website/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
data "aws_caller_identity" "current" {}

resource "aws_s3_bucket" "website" {
bucket = "hello-world-website-${data.aws_caller_identity.current.account_id}-${var.environment}"
force_destroy = true
}

resource "aws_s3_object" "startpage" {
bucket = aws_s3_bucket.website.id
key = "index.html"
source = "${path.module}/index.html"
acl = "public-read"
content_type = "text/html"
}

resource "aws_s3_bucket_website_configuration" "website" {
bucket = aws_s3_bucket.website.bucket

index_document {
suffix = "index.html"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions 4-feature-flags/prod/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_version = "~> 1.1.7"
}

provider "aws" {
region = "eu-west-1"
}

module "website" {
source = "../modules/website"

environment = "prod"
}

module "api" {
source = "../modules/api"

lambda_function_response = "Hello from Prod 👋"
environment = "prod"
}
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions 4-feature-flags/staging/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_version = "~> 1.1.7"
}

provider "aws" {
region = "eu-west-1"
}

module "website" {
source = "../modules/website"

environment = "staging"
}

module "api" {
source = "../modules/api"

lambda_function_response = "Hello from Staging 👋"
environment = "staging"
}
File renamed without changes.
3 changes: 0 additions & 3 deletions 4-remote-backend/modules/api/functions/helloworld.js

This file was deleted.

10 changes: 0 additions & 10 deletions 4-remote-backend/modules/api/variables.tf

This file was deleted.

5 changes: 5 additions & 0 deletions 5-remote-backend/modules/api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.handler = async () => {
return {
message: "Hello from Lambda! 👋"
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ module "lambda_function" {
handler = "helloworld.handler"
runtime = "nodejs12.x"
source_path = "${path.module}/functions"
environment_variables = {
"RESPONSE" = var.lambda_function_response
}

publish = true
allowed_triggers = {
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions 5-remote-backend/modules/api/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "environment" {
type = string
description = "Identifier for the environment (e.g. staging, development or prod)"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions 5-remote-backend/modules/website/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "environment" {
type = string
description = "Identifier for the environment (e.g. staging, development or prod)"
}
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions 5-remote-backend/prod/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "api_url" {
description = "Hello World API URL"
value = module.api.url
}

output "website_url" {
description = "Static Website URL"
value = module.website.url
}
File renamed without changes.
9 changes: 9 additions & 0 deletions 5-remote-backend/staging/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "api_url" {
description = "Hello World API URL"
value = module.api.url
}

output "website_url" {
description = "Static Website URL"
value = module.website.url
}
3 changes: 0 additions & 3 deletions 5-terragrunt/modules/api/functions/helloworld.js

This file was deleted.

10 changes: 0 additions & 10 deletions 5-terragrunt/modules/api/variables.tf

This file was deleted.

82 changes: 82 additions & 0 deletions 6-terragrunt/modules/api/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions 6-terragrunt/modules/api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.handler = async () => {
return {
message: "Hello from Lambda! 👋"
};
};
26 changes: 26 additions & 0 deletions 6-terragrunt/modules/api/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
locals {
project_name = "hello-world"
}

module "lambda_function" {
source = "terraform-aws-modules/lambda/aws"

function_name = "${local.project_name}-${var.environment}"
handler = "helloworld.handler"
runtime = "nodejs12.x"
source_path = "${path.module}/functions"

publish = true
allowed_triggers = {
AllowExecutionFromAPIGateway = {
service = "apigateway"
source_arn = "${aws_apigatewayv2_api.hello_world.execution_arn}/*/*"
}
}
}

resource "aws_apigatewayv2_api" "hello_world" {
name = "${local.project_name}-${var.environment}"
protocol_type = "HTTP"
target = module.lambda_function.lambda_function_arn
}
4 changes: 4 additions & 0 deletions 6-terragrunt/modules/api/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "url" {
description = "Hello World API URL"
value = aws_apigatewayv2_api.hello_world.api_endpoint
}
File renamed without changes.
4 changes: 4 additions & 0 deletions 6-terragrunt/modules/api/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "environment" {
type = string
description = "Identifier for the environment (e.g. staging, development or prod)"
}
6 changes: 6 additions & 0 deletions 6-terragrunt/modules/website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<h1>Hello World :)</h1>
</body>
</html>
File renamed without changes.
3 changes: 3 additions & 0 deletions 6-terragrunt/modules/website/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "url" {
value = "http://${aws_s3_bucket_website_configuration.website.website_endpoint}"
}
File renamed without changes.
4 changes: 4 additions & 0 deletions 6-terragrunt/modules/website/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "environment" {
type = string
description = "Identifier for the environment (e.g. staging, development or prod)"
}
Loading

0 comments on commit 9da951c

Please sign in to comment.