Skip to content

Commit

Permalink
feat(feature flag): greeting feature
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikFricke committed May 9, 2022
1 parent 9da951c commit ec0c0fa
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 33 deletions.
4 changes: 2 additions & 2 deletions 2-simple-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ 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"
}
```
Expand Down Expand Up @@ -108,7 +108,7 @@ 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"
publish = true
Expand Down
2 changes: 1 addition & 1 deletion 2-simple-api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module "lambda_function" {

function_name = "hello-world"
handler = "helloworld.handler"
runtime = "nodejs12.x"
runtime = "nodejs14.x"
source_path = "./functions"

publish = true
Expand Down
2 changes: 1 addition & 1 deletion 3-environments/modules/api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module "lambda_function" {

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

publish = true
Expand Down
15 changes: 11 additions & 4 deletions 4-feature-flags/modules/api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
exports.handler = async () => {
return {
message: "Hello from Lambda! 👋"
};
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 };
};
5 changes: 4 additions & 1 deletion 4-feature-flags/modules/api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ 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 = {
GREETING_ENABLED = "${var.enable_greeting}"
}

publish = true
allowed_triggers = {
Expand Down
6 changes: 6 additions & 0 deletions 4-feature-flags/modules/api/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ 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
}
5 changes: 2 additions & 3 deletions 4-feature-flags/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ provider "aws" {

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

environment = "prod"
}

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

lambda_function_response = "Hello from Prod 👋"

environment = "prod"
}
6 changes: 3 additions & 3 deletions 4-feature-flags/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,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
}
15 changes: 11 additions & 4 deletions 5-remote-backend/modules/api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
exports.handler = async () => {
return {
message: "Hello from Lambda! 👋"
};
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 };
};
5 changes: 4 additions & 1 deletion 5-remote-backend/modules/api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ 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 = {
GREETING_ENABLED = "${var.enable_greeting}"
}

publish = true
allowed_triggers = {
Expand Down
6 changes: 6 additions & 0 deletions 5-remote-backend/modules/api/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ 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
}
3 changes: 1 addition & 2 deletions 5-remote-backend/prod/main.tf
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"
}
6 changes: 3 additions & 3 deletions 5-remote-backend/staging/main.tf
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
}
15 changes: 11 additions & 4 deletions 6-terragrunt/modules/api/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
exports.handler = async () => {
return {
message: "Hello from Lambda! 👋"
};
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 };
};
5 changes: 4 additions & 1 deletion 6-terragrunt/modules/api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ 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 = {
GREETING_ENABLED = "${var.enable_greeting}"
}

publish = true
allowed_triggers = {
Expand Down
8 changes: 7 additions & 1 deletion 6-terragrunt/modules/api/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
variable "environment" {
type = string
type = string
description = "Identifier for the environment (e.g. staging, development or prod)"
}

variable "enable_greeting" {
type = bool
description = "Enable greeting feature"
default = false
}
1 change: 0 additions & 1 deletion 6-terragrunt/prod/api/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ terraform {
}

inputs = {
lambda_function_response = "Hello from Prod 👋"
environment = "prod"
}
2 changes: 1 addition & 1 deletion 6-terragrunt/staging/api/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ terraform {
}

inputs = {
lambda_function_response = "Hello from Staging 👋"
environment = "staging"
enable_greeting = true
}

0 comments on commit ec0c0fa

Please sign in to comment.