Skip to content

Commit

Permalink
feat: add more labs
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikFricke committed May 3, 2022
1 parent 17d0241 commit 6a8ad32
Show file tree
Hide file tree
Showing 53 changed files with 1,092 additions and 15 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Common
.DS_Store

# Terraform
.terraform
*.tfstate*
terraform.tfvars

# Lambda Function Builds
builds
.DS_Store

# Terragrunt (auto-generated)
.terragrunt-cache
1 change: 1 addition & 0 deletions .terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.1.9
File renamed without changes.
5 changes: 0 additions & 5 deletions 0-bootstrap/README.md → 1-bootstrap/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Bootstrap

## Prerequisites

- [Terraform CLI](https://learn.hashicorp.com/tutorials/terraform/install-cli)
- [AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)

## Goals
- Set up Terraform
- Create first resource and deploy it
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
57 changes: 57 additions & 0 deletions 2-hello-world/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
terraform {
required_version = "~> 1.1.7"
}

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

data "aws_iam_policy" "admin" {
name = "AdministratorAccess"
}

resource "aws_iam_user" "ci" {
name = "CI"
}

resource "aws_iam_user_policy_attachment" "ci" {
user = aws_iam_user.ci.name
policy_arn = data.aws_iam_policy.admin.arn
}

variable "lambda_function_response" {
type = string
description = "Body response of the hello world lambda function"
default = "Hello World :)"
}

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

function_name = "hello-world"
handler = "helloworld.handler"
runtime = "nodejs12.x"
source_path = "./functions"
environment_variables = {
"RESPONSE" = var.lambda_function_response
}

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

resource "aws_apigatewayv2_api" "hello_world" {
name = "hello-world"
protocol_type = "HTTP"
target = module.lambda_function.lambda_function_arn
}

output "endpoint" {
description = "Hello World API URL"
value = aws_apigatewayv2_api.hello_world.api_endpoint
}
82 changes: 82 additions & 0 deletions 3-code-structure/.terraform.lock.hcl

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

3 changes: 3 additions & 0 deletions 3-code-structure/functions/helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.handler = async () => {
return process.env.RESPONSE;
};
9 changes: 0 additions & 9 deletions 1-hello-world/main.tf → 3-code-structure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ resource "aws_iam_user_policy_attachment" "ci" {
policy_arn = data.aws_iam_policy.admin.arn
}

variable "lambda_function_response" {
type = string
default = "Hello World :)"
}

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

Expand All @@ -49,7 +44,3 @@ resource "aws_apigatewayv2_api" "hello_world" {
protocol_type = "HTTP"
target = module.lambda_function.lambda_function_arn
}

output "endpoint" {
value = aws_apigatewayv2_api.hello_world.api_endpoint
}
4 changes: 4 additions & 0 deletions 3-code-structure/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "endpoint" {
description = "Hello World API URL"
value = aws_apigatewayv2_api.hello_world.api_endpoint
}
5 changes: 5 additions & 0 deletions 3-code-structure/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "lambda_function_response" {
type = string
description = "Body response of the hello world lambda function"
default = "Hello World :)"
}
21 changes: 21 additions & 0 deletions 4-environments/environments/mgmt/.terraform.lock.hcl

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

11 changes: 11 additions & 0 deletions 4-environments/environments/mgmt/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
required_version = "~> 1.1.7"
}

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

module "mgmt" {
source = "../../modules/mgmt"
}
82 changes: 82 additions & 0 deletions 4-environments/environments/prod/.terraform.lock.hcl

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

14 changes: 14 additions & 0 deletions 4-environments/environments/prod/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = "~> 1.1.7"
}

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

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

lambda_function_response = "Hello from Prod 👋"
environment = "prod"
}
4 changes: 4 additions & 0 deletions 4-environments/environments/prod/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "endpoint" {
description = "Hello World API URL"
value = module.api.endpoint
}
Loading

0 comments on commit 6a8ad32

Please sign in to comment.