-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from babbel/initial-version
Initial version
- Loading branch information
Showing
8 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/.terraform | ||
/.terraform.lock.hcl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} |