Skip to content

Commit

Permalink
Merge pull request #2 from superluminar-io/feature-flags
Browse files Browse the repository at this point in the history
feat: feature flag lab
  • Loading branch information
HenrikFricke authored May 9, 2022
2 parents ab7223e + ec0c0fa commit 7003e9a
Show file tree
Hide file tree
Showing 65 changed files with 483 additions and 64 deletions.
14 changes: 5 additions & 9 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 @@ -50,11 +52,8 @@ In the first lab, we bootstrapped Terraform and created some resources. Finally,
function_name = "hello-world"
handler = "helloworld.handler"
runtime = "nodejs12.x"
runtime = "nodejs14.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 @@ -109,11 +108,8 @@ So, the Lambda function is in place and we can go to the next component: The API
function_name = "hello-world"
handler = "helloworld.handler"
runtime = "nodejs12.x"
runtime = "nodejs14.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! 👋"
};
};
5 changes: 1 addition & 4 deletions 2-simple-api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ module "lambda_function" {

function_name = "hello-world"
handler = "helloworld.handler"
runtime = "nodejs12.x"
runtime = "nodejs14.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! 👋"
};
};
5 changes: 1 addition & 4 deletions 3-environments/modules/api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ module "lambda_function" {

function_name = "${local.project_name}-${var.environment}"
handler = "helloworld.handler"
runtime = "nodejs12.x"
runtime = "nodejs14.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
12 changes: 12 additions & 0 deletions 4-feature-flags/modules/api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const greetingEnabled = process.env.GREETING_ENABLED === "true";

exports.handler = async (event) => {
let message = "Hello from Lambda! 👋";
const name = event.queryStringParameters?.name;

if (greetingEnabled && name) {
message = `Hello ${name}! 👋`;
}

return { message };
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module "lambda_function" {

function_name = "${local.project_name}-${var.environment}"
handler = "helloworld.handler"
runtime = "nodejs12.x"
runtime = "nodejs14.x"
source_path = "${path.module}/functions"
environment_variables = {
"RESPONSE" = var.lambda_function_response
GREETING_ENABLED = "${var.enable_greeting}"
}

publish = true
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions 4-feature-flags/modules/api/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "environment" {
type = string
description = "Identifier for the environment (e.g. staging, development or prod)"
}

variable "enable_greeting" {
type = bool
description = "Enable greeting feature"
default = false
}
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.
19 changes: 19 additions & 0 deletions 4-feature-flags/prod/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_version = "~> 1.1.7"
}

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

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

environment = "prod"
}

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

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"

environment = "staging"
enable_greeting = true
}
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.

12 changes: 12 additions & 0 deletions 5-remote-backend/modules/api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const greetingEnabled = process.env.GREETING_ENABLED === "true";

exports.handler = async (event) => {
let message = "Hello from Lambda! 👋";
const name = event.queryStringParameters?.name;

if (greetingEnabled && name) {
message = `Hello ${name}! 👋`;
}

return { message };
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module "lambda_function" {

function_name = "${local.project_name}-${var.environment}"
handler = "helloworld.handler"
runtime = "nodejs12.x"
runtime = "nodejs14.x"
source_path = "${path.module}/functions"
environment_variables = {
"RESPONSE" = var.lambda_function_response
GREETING_ENABLED = "${var.enable_greeting}"
}

publish = true
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions 5-remote-backend/modules/api/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "environment" {
type = string
description = "Identifier for the environment (e.g. staging, development or prod)"
}

variable "enable_greeting" {
type = bool
description = "Enable greeting feature"
default = false
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ module "website" {
module "api" {
source = "../modules/api"

lambda_function_response = "Hello from Prod 👋"
environment = "prod"
environment = "prod"
}
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ provider "aws" {

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

environment = "staging"
}

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

lambda_function_response = "Hello from Staging 👋"

environment = "staging"
enable_greeting = true
}
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.

12 changes: 12 additions & 0 deletions 6-terragrunt/modules/api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const greetingEnabled = process.env.GREETING_ENABLED === "true";

exports.handler = async (event) => {
let message = "Hello from Lambda! 👋";
const name = event.queryStringParameters?.name;

if (greetingEnabled && name) {
message = `Hello ${name}! 👋`;
}

return { message };
};
Loading

0 comments on commit 7003e9a

Please sign in to comment.