Skip to content

Commit

Permalink
Merge pull request #1 from babbel/initial-version
Browse files Browse the repository at this point in the history
Initial version
  • Loading branch information
fmasuhr authored Feb 11, 2021
2 parents ae08692 + 690fe98 commit 6b1f4cf
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Validate

on: push

env:
AWS_REGION: local

jobs:
validate:
runs-on: ubuntu-20.04
steps:
- uses: actions/[email protected]
- uses: hashicorp/[email protected]
with:
terraform_version: 0.14.5
- run: terraform init
- run: terraform validate
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.terraform
/.terraform.lock.hcl
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## v1.0.0

- [Initial version](https://github.com/babbel/terraform-aws-alb-for-vpc-internal-requests/pull/1)
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2021 Lesson Nine GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# terraform-aws-alb-for-vpc-internal-requests
Terraform module creating a private ALB for VPC-internal requests
# Application Load Balancer (ALB) for VPC-Internal Requests

This module creates a private ALB, a default ALB listener (with HTTP protocol), and a security group for service-2-service requests within a VPC.

## Example Usage

```tf
module "alb" {
source = "babbel/alb-for-vpc-internal-requests/aws"
version = "~> 1.0"
name = "example"
vpc = aws_vpc.this
subnets = [aws_subnet.private_a, aws_subnet.private_b]
ingress_security_groups = {
some-service = aws_security_group.some_service
}
target_group = aws_lb_target_group.example
tags = {
app = "example"
env = "production"
}
}
```
72 changes: 72 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Security Group

resource "aws_security_group" "this" {
vpc_id = var.vpc.id

name = "lb-${var.name}"
description = "LB: ${var.name}"

tags = merge({
Name = "LB: ${var.name}"
}, var.tags)

lifecycle {
create_before_destroy = true
}
}

resource "aws_security_group_rule" "ingress" {
for_each = var.ingress_security_groups

security_group_id = aws_security_group.this.id

type = "ingress"
source_security_group_id = each.value.id
protocol = "tcp"
from_port = var.ingress_port
to_port = var.ingress_port

lifecycle {
create_before_destroy = true
}
}

resource "aws_security_group_rule" "egress" {
security_group_id = aws_security_group.this.id

type = "egress"
cidr_blocks = ["0.0.0.0/0"]
protocol = "-1"
from_port = 0
to_port = 0

lifecycle {
create_before_destroy = true
}
}

# ALB

resource "aws_lb" "this" {
name = var.name

load_balancer_type = "application"

internal = true
subnets = var.subnets[*].id
security_groups = [aws_security_group.this.id]

tags = var.tags
}

resource "aws_lb_listener" "this" {
load_balancer_arn = aws_lb.this.arn

protocol = "HTTP"
port = var.ingress_port

default_action {
target_group_arn = var.target_group.arn
type = "forward"
}
}
9 changes: 9 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "security_group" {
description = "Security group used by the ALB"
value = aws_security_group.this
}

output "this" {
description = "ALB"
value = aws_lb.this
}
54 changes: 54 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
variable "ingress_port" {
description = "The port the ALB will listen to"

type = number
default = 80
}

variable "ingress_security_groups" {
description = "Map of security groups the ALB will receive requests from"

type = map(
object({
id = string
})
)
}

variable "name" {
description = "Name of the ALB"

type = string
}

variable "subnets" {
description = "List of subnets the ALB will be created in"

type = list(
object({
id = string
})
)
}

variable "tags" {
description = "Map of tags to assign to all resources supporting tags (in addition to the `Name` tag)"

type = map(string)
}

variable "target_group" {
description = "Target group all requests to the ALB will be forwarded to"

type = object({
arn = string
})
}

variable "vpc" {
description = "VPC the ALB and the security group will be created in"

type = object({
id = string
})
}

0 comments on commit 6b1f4cf

Please sign in to comment.