-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 03b2c14
Showing
11 changed files
with
579 additions
and
0 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,23 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
# Uses editorconfig to maintain consistent coding styles | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 80 | ||
trim_trailing_whitespace = true | ||
|
||
[*.{tf,tfvars}] | ||
indent_size = 2 | ||
indent_style = space | ||
|
||
[*.md] | ||
max_line_length = 0 | ||
trim_trailing_whitespace = false |
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,4 @@ | ||
.terraform | ||
terraform.tfstate | ||
*.tfstate* | ||
terraform.tfvars |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 cytopia | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Terraform module: AWS ELB | ||
|
||
This Terraform module creates an ELB with optionally a public and/or private Route53 DNS record attached to it. | ||
Additionally it provides the option to attach the created ELB to an autoscaling group by name. | ||
|
||
|
||
## Usage | ||
|
||
```hcl | ||
module "elb" { | ||
source = "github.com/cytopia/terraform-aws-elb?ref=v0.1.0" | ||
name = "my-elb" | ||
vpc_id = "vpc-12345" | ||
subnet_ids = ["subnet-1234", "subnet-5677"] | ||
# Attach the ELB to an ASG by this name | ||
asg_name = "my-service" | ||
# Listener | ||
lb_port = "443" | ||
instance_port = "80" | ||
# Security | ||
inbound_cidr_blocks = ["0.0.0.0/0"] | ||
# Create this route53 public DNS record | ||
public_dns_name = "my-service.example.com" | ||
} | ||
``` | ||
|
||
## Examples | ||
|
||
* [Complete ELB](examples/complete/) | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|:----:|:-----:|:-----:| | ||
| vpc_id | ID of the VPC to add this ELB to. | string | - | yes | | ||
| subnet_ids | List of subnet ids to place the ELB into. | list | - | yes | | ||
| asg_name | Name of the auto scaling group to attach to. If this value is empty, no attachment will be done and is be left to the end-user via custom 'aws_autoscaling_group' or 'aws_autoscaling_attachment' definitions. | string | `` | no | | ||
| inbound_cidr_blocks | List of CIDR's that are allowed to access the ELB. | list | - | yes | | ||
| internal | If true, ELB will be an internal ELB. | string | `false` | no | | ||
| cross_zone_load_balancing | Enable cross-zone load balancing. | string | `true` | no | | ||
| idle_timeout | The time in seconds that the connection is allowed to be idle. | string | `60` | no | | ||
| connection_draining | Boolean to enable connection draining. | string | `false` | no | | ||
| connection_draining_timeout | The time in seconds to allow for connections to drain | string | `300` | no | | ||
| lb_port | On what port do you want to access the ELB. | string | - | yes | | ||
| instance_port | On what port does the ELB access the instances. | string | - | yes | | ||
| lb_protocol | On what protocol should the load balancer respond. | string | `TCP` | no | | ||
| instance_protocol | On what protocol does the instance respond. | string | `TCP` | no | | ||
| healthy_threshold | The number of checks before the instance is declared healthy. | string | `10` | no | | ||
| unhealthy_threshold | The number of checks before the instance is declared unhealthy. | string | `2` | no | | ||
| target | The target of the check. If unset, will default to 'instance_protocol:instance_port' for TCP/SLL and 'instance_protocol:instance_port/' for HTTP/HTTPS. | string | `` | no | | ||
| interval | The interval between checks. | string | `30` | no | | ||
| timeout | The length of time before the check times out. | string | `5` | no | | ||
| name | Name of the ELB and security group resources. | string | - | yes | | ||
| tags | Tags to apply to all resources. | map | `<map>` | no | | ||
| sg_name_suffix_elb | Name suffix to append to the ELB security group. | string | `-elb` | no | | ||
| route53_public_dns_name | If set, the ELB will be assigned this public DNS name via Route53. | string | `` | no | | ||
| route53_private_dns_name | If set, the ELB will be assigned this private DNS name via Route53. | string | `` | no | | ||
| public_dns_evaluate_target_health | Set to true if you want Route 53 to determine whether to respond to DNS queries using this resource record set by checking the health of the resource record set. | string | `true` | no | | ||
| private_dns_evaluate_target_health | Set to true if you want Route 53 to determine whether to respond to DNS queries using this resource record set by checking the health of the resource record set. | string | `true` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| security_group_id | The ID of the ELB security group to attach the the LC/ASG/EC2 instance in order to be accessable by the ELB. | | ||
| id | The name of the ELB | | ||
| name | The name of the ELB | | ||
| fqdn | The auto-generated FQDN of the ELB. | | ||
| route53_public_dns_name | The route53 public dns name of the ELB if set. | | ||
| route53_private_dns_name | The route53 private dns name of the ELB if set. | | ||
|
||
## Authors | ||
|
||
Module managed by [cytopia](https://github.com/cytopia). | ||
|
||
## License | ||
|
||
[MIT License](LICENSE) | ||
|
||
Copyright (c) 2018 [cytopia](https://github.com/cytopia) |
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,22 @@ | ||
# Complete ELB example | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run terraform destroy when you don't need these resources. | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|:----:|:-----:|:-----:| | ||
| key_name | Name of SSH key on AWS | string | `` | no | | ||
| name | The name(-prefix) to prepend/apply to all Name tags on all VPC resources | string | `elb-complete` | no | | ||
| private_subnet_tags | A map of additional tags to apply to all private subnets | map | `<map>` | no | | ||
| public_subnet_tags | A map of additional tags to apply to all public subnets | map | `<map>` | no | |
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,93 @@ | ||
# ------------------------------------------------------------------------------------------------- | ||
# VPC Resources | ||
# ------------------------------------------------------------------------------------------------- | ||
module "aws_vpc" { | ||
source = "github.com/terraform-aws-modules/terraform-aws-vpc?ref=v1.46.0" | ||
|
||
cidr = "14.0.0.0/16" | ||
azs = ["eu-central-1a", "eu-central-1b", "eu-central-1c"] | ||
private_subnets = ["14.0.10.0/24", "14.0.11.0/24", "14.0.12.0/24"] | ||
public_subnets = ["14.0.20.0/24", "14.0.21.0/24", "14.0.22.0/24"] | ||
|
||
enable_nat_gateway = true | ||
enable_vpn_gateway = false | ||
|
||
name = "${var.name}" | ||
public_subnet_tags = "${var.public_subnet_tags}" | ||
private_subnet_tags = "${var.private_subnet_tags}" | ||
} | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# ELB for Bastion Host | ||
# ------------------------------------------------------------------------------------------------- | ||
module "elb" { | ||
source = "../../" | ||
|
||
name = "${var.name}" | ||
vpc_id = "${module.aws_vpc.vpc_id}" | ||
subnet_ids = "${module.aws_vpc.public_subnets}" | ||
|
||
# Attach to ASG by name | ||
asg_name = "${var.name}" | ||
|
||
# Listener | ||
lb_port = "22" | ||
instance_port = "22" | ||
|
||
# Security | ||
inbound_cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# Bastion Host | ||
# ------------------------------------------------------------------------------------------------- | ||
data "aws_ami" "bastion" { | ||
most_recent = true | ||
|
||
filter { | ||
name = "owner-alias" | ||
values = ["amazon"] | ||
} | ||
|
||
filter { | ||
name = "virtualization-type" | ||
values = ["hvm"] | ||
} | ||
|
||
filter { | ||
name = "name" | ||
values = ["amzn2-ami-hvm*"] | ||
} | ||
} | ||
|
||
resource "aws_launch_configuration" "bastion" { | ||
name_prefix = "${var.name}" | ||
image_id = "${data.aws_ami.bastion.image_id}" | ||
instance_type = "t2.micro" | ||
security_groups = ["${module.elb.security_group_id}"] | ||
key_name = "${var.key_name}" | ||
|
||
associate_public_ip_address = false | ||
|
||
root_block_device { | ||
volume_size = "8" | ||
} | ||
} | ||
|
||
resource "aws_autoscaling_group" "bastion" { | ||
name = "${var.name}" | ||
|
||
# ASG needs to go into the private subnets, as it would get a public IP address otherwise | ||
# this is nonetheless if associate_public_ip_address is set to false. | ||
# We have a public ELB anyway that routes to this bastion host. | ||
vpc_zone_identifier = ["${module.aws_vpc.private_subnets}"] | ||
|
||
desired_capacity = 1 | ||
min_size = 1 | ||
max_size = 1 | ||
health_check_grace_period = "60" | ||
health_check_type = "EC2" | ||
force_delete = false | ||
wait_for_capacity_timeout = 0 | ||
launch_configuration = "${aws_launch_configuration.bastion.name}" | ||
} |
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,27 @@ | ||
variable "name" { | ||
description = "The name(-prefix) to prepend/apply to all Name tags on all VPC resources" | ||
default = "elb-complete" | ||
} | ||
|
||
variable "public_subnet_tags" { | ||
description = "A map of additional tags to apply to all public subnets" | ||
type = "map" | ||
|
||
default = { | ||
Visibility = "public" | ||
} | ||
} | ||
|
||
variable "private_subnet_tags" { | ||
description = "A map of additional tags to apply to all private subnets" | ||
type = "map" | ||
|
||
default = { | ||
Visibility = "private" | ||
} | ||
} | ||
|
||
variable "key_name" { | ||
description = "Name of SSH key on AWS" | ||
default = "" | ||
} |
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,4 @@ | ||
locals { | ||
health_check_path = "${contains(list("HTTP", "HTTPS"), var.instance_protocol) ? "/" : ""}" | ||
health_check_target = "${var.target == "" ? "${var.instance_protocol}:${var.instance_port}${local.health_check_path}" : var.target}" | ||
} |
Oops, something went wrong.