Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Check valid versions on:
source = "cn-terraform/nomad/aws"
version = "2.0.2"

names_prefix = ${terraform.workspace}
name_prefix = ${terraform.workspace}

profile = var.profile
region = var.region
Expand Down Expand Up @@ -55,7 +55,7 @@ Pleas run this command right after cloning the repository.
pre-commit install

For that you may need to install the folowwing tools:
* [Pre-commit](https://pre-commit.com/)
* [Pre-commit](https://pre-commit.com/)
* [Terraform Docs](https://terraform-docs.io/)

In order to run all checks at any point run the following command:
Expand Down Expand Up @@ -131,11 +131,9 @@ No modules.
| <a name="input_consul_address"></a> [consul\_address](#input\_consul\_address) | Consul Address | `any` | n/a | yes |
| <a name="input_consul_version"></a> [consul\_version](#input\_consul\_version) | Consul Version | `string` | `"0.9.2"` | no |
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | Domain Name | `any` | n/a | yes |
| <a name="input_names_prefix"></a> [names\_prefix](#input\_names\_prefix) | prefix for Resources Names | `any` | n/a | yes |
| <a name="input_name_prefix"></a> [name\_prefix](#input\_name\_prefix) | prefix for Resources Names | `any` | n/a | yes |
| <a name="input_nomad_version"></a> [nomad\_version](#input\_nomad\_version) | Nomad Version | `string` | `"0.6.0"` | no |
| <a name="input_ports_to_open_on_elb_security_group"></a> [ports\_to\_open\_on\_elb\_security\_group](#input\_ports\_to\_open\_on\_elb\_security\_group) | Ports to Open on ELB Security Group | `list(any)` | <pre>[<br> "22",<br> "80",<br> "443"<br>]</pre> | no |
| <a name="input_profile"></a> [profile](#input\_profile) | AWS API key credentials to use | `any` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | AWS Region the infrastructure is hosted in | `any` | n/a | yes |
| <a name="input_route53_zone_id"></a> [route53\_zone\_id](#input\_route53\_zone\_id) | Route53 Zone ID to fetch | `any` | n/a | yes |
| <a name="input_server_ami_id"></a> [server\_ami\_id](#input\_server\_ami\_id) | AMI ID to use on servers | `string` | n/a | yes |
| <a name="input_server_asg_desired_capacity"></a> [server\_asg\_desired\_capacity](#input\_server\_asg\_desired\_capacity) | Desired Number of Instances of PAAS Server to Create | `any` | n/a | yes |
Expand Down
38 changes: 38 additions & 0 deletions examples/test/.terraform.lock.hcl

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

121 changes: 121 additions & 0 deletions examples/test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
module "base-network" {
source = "cn-terraform/networking/aws"
name_prefix = "test-networking"
vpc_cidr_block = "192.168.0.0/16"
availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d"]
public_subnets_cidrs_per_availability_zone = ["192.168.0.0/19", "192.168.32.0/19", "192.168.64.0/19", "192.168.96.0/19"]
private_subnets_cidrs_per_availability_zone = ["192.168.128.0/19", "192.168.160.0/19", "192.168.192.0/19", "192.168.224.0/19"]
}

module "nomad" {
source = "../../"
name_prefix = "nomad"
region = "us-east-1"
vpc_id = module.base-network.vpc_id
subnets_ids = module.base-network.private_subnets_ids
}

variable "route53_zone_id" {
description = "Route53 Zone ID to fetch"
}

variable "domain_name" {
description = "Domain Name"
}

variable "ssh_key_name" {
description = "SSH Key Name"
}

#------------------------------------------------------------------------------
# SECURITY GROUP
#------------------------------------------------------------------------------
variable "cidrs_to_open_ports_on_security_groups" {
description = "List of CIDRs to open ports on instances security group"
type = list(any)
}

variable "ports_to_open_on_elb_security_group" {
description = "Ports to Open on ELB Security Group"
type = list(any)
default = ["22", "80", "443"]
}

variable "tcp_ports_to_open_on_instances_security_group" {
description = "TCP Ports to Open on Instances Security Group"
type = list(any)
default = ["22", "4646", "4647", "4648", "8300", "8301", "8302", "8500", "8600"]
}

variable "udp_ports_to_open_on_instances_security_group" {
description = "UDP Ports to Open on Instances Security Group"
type = list(any)
default = ["4648", "8301", "8302", "8600"]
}

#------------------------------------------------------------------------------
# VERSIONS
#------------------------------------------------------------------------------
variable "consul_version" {
description = "Consul Version"
default = "v1.11.4"
}

variable "nomad_version" {
description = "Nomad Version"
default = "v1.2.6"
}

variable "consul_address" {
description = "Consul Address"
}

#------------------------------------------------------------------------------
# SERVER SETTINGS
#------------------------------------------------------------------------------
variable "server_ami_id" {
description = "AMI ID to use on servers"
type = string
}

variable "server_instance_type" {
description = "AWS Instance type to use on servers"
type = string
}

variable "server_asg_min_size" {
description = "Min Number of Instances of PAAS Server to Create"
}

variable "server_asg_desired_capacity" {
description = "Desired Number of Instances of PAAS Server to Create"
}

variable "server_asg_max_size" {
description = "Max Number of Instances of PAAS Server to Create"
}

#------------------------------------------------------------------------------
# NOMAD CLIENT SETTINGS
#------------------------------------------------------------------------------
variable "client_ami_id" {
description = "AMI ID to use on Clients"
type = string
}

variable "client_instance_type" {
description = "AWS Instance type to use on clients"
type = string
}

variable "client_asg_min_size" {
description = "Min Number of Instances of Nomad Client to Create"
}

variable "client_asg_desired_capacity" {
description = "Desired Number of Instances of Nomad Client to Create"
}

variable "client_asg_max_size" {
description = "Max Number of Instances of Nomad Client to Create"
}
19 changes: 19 additions & 0 deletions examples/test/mock_provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_version = ">= 0.13"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4"
}
}
}

provider "aws" {
region = "us-east-1"
skip_credentials_validation = true
skip_requesting_account_id = true
skip_metadata_api_check = true
s3_use_path_style = true
access_key = "mock_access_key"
secret_key = "mock_secret_key"
}
17 changes: 8 additions & 9 deletions iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@

## Create IAM role
resource "aws_iam_role" "ec2_describe_role" {
name = "${var.names_prefix}_ec2_describe_role"
name = "${var.name_prefix}_ec2_describe_role"
assume_role_policy = file("${path.module}/iam_files/iam_role_ec2_describe.json")
}

## Create IAM policy
resource "aws_iam_policy" "ec2_describe_policy" {
name = "${var.names_prefix}_ec2_describe_policy"
name = "${var.name_prefix}_ec2_describe_policy"
description = "Allows EC2 Instances to Describe Other EC2 Instances"
policy = file("${path.module}/iam_files/iam_policy_ec2_describe.json")
}

## Attach the policy to the role
resource "aws_iam_policy_attachment" "ec2_describe_attach_policy" {
name = "${var.names_prefix}_ec2_describe_attach"
name = "${var.name_prefix}_ec2_describe_attach"
roles = [aws_iam_role.ec2_describe_role.name]
policy_arn = aws_iam_policy.ec2_describe_policy.arn
}

## Create the instance profile
resource "aws_iam_instance_profile" "ec2_describe_instance_profile" {
name = "${var.names_prefix}_ec2_describe_instance_profile"
name = "${var.name_prefix}_ec2_describe_instance_profile"
role = aws_iam_role.ec2_describe_role.name
}

Expand All @@ -38,27 +38,26 @@ resource "aws_iam_instance_profile" "ec2_describe_instance_profile" {

## Create IAM role
resource "aws_iam_role" "push_to_ecr_role" {
name = "${var.names_prefix}_push_to_ecr_role"
name = "${var.name_prefix}_push_to_ecr_role"
assume_role_policy = file("${path.module}/iam_files/iam_role_ec2_describe.json")
}

## Create IAM policy to allow the push of docker images to ECR
resource "aws_iam_policy" "push_to_ecr_policy" {
name = "${var.names_prefix}_push_to_ecr_policy"
name = "${var.name_prefix}_push_to_ecr_policy"
description = "Allow EC2 instances to push docker images to ECR registry"
policy = file("${path.module}/iam_files/iam_policy_push_to_ecr.json")
}

## Attach the policy to the role
resource "aws_iam_policy_attachment" "push_to_ecr_attach_policy" {
name = "${var.names_prefix}_push_to_ecr_attach"
name = "${var.name_prefix}_push_to_ecr_attach"
roles = [aws_iam_role.push_to_ecr_role.name]
policy_arn = aws_iam_policy.push_to_ecr_policy.arn
}

## Create an instance profile
resource "aws_iam_instance_profile" "ecr_role_instance_profile" {
name = "${var.names_prefix}_push_to_ecr_instance_profile"
name = "${var.name_prefix}_push_to_ecr_instance_profile"
role = aws_iam_role.push_to_ecr_role.name
}

9 changes: 4 additions & 5 deletions load_balancer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#------------------------------------------------------------------------------
## ELB
resource "aws_elb" "consul_elb" {
name = "${var.names_prefix}-consul-elb"
name = "${var.name_prefix}-consul-elb"
security_groups = [aws_security_group.elb_security_group.id]
subnets = data.aws_subnet.subnets.*.id
internal = true
cross_zone_load_balancing = true
tags = {
Name = "${var.names_prefix}_consul_elb"
Name = "${var.name_prefix}_consul_elb"
}
listener {
instance_port = "8500"
Expand Down Expand Up @@ -37,13 +37,13 @@ resource "aws_route53_record" "consul_elb_dns" {
#------------------------------------------------------------------------------
## ELB
resource "aws_elb" "nomad_elb" {
name = "${var.names_prefix}-nomad-elb"
name = "${var.name_prefix}-nomad-elb"
security_groups = [aws_security_group.elb_security_group.id]
subnets = data.aws_subnet.subnets.*.id
internal = true
cross_zone_load_balancing = true
tags = {
Name = "${var.names_prefix}_nomad_elb"
Name = "${var.name_prefix}_nomad_elb"
}
listener {
instance_port = "4646"
Expand All @@ -65,4 +65,3 @@ resource "aws_route53_record" "nomad_elb_dns" {
evaluate_target_health = true
}
}

9 changes: 0 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#------------------------------------------------------------------------------
# PROVIDER
#------------------------------------------------------------------------------
provider "aws" {
profile = var.profile
region = var.region
}

#------------------------------------------------------------------------------
# Data
#------------------------------------------------------------------------------
Expand All @@ -18,4 +10,3 @@ data "aws_route53_zone" "hosted_zone" {
zone_id = var.route53_zone_id
vpc_id = var.vpc_id
}

7 changes: 3 additions & 4 deletions nomad-client.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resource "aws_launch_configuration" "nomad_client_lc" {
aws_autoscaling_attachment.nomad_asg_attachment,
aws_security_group.instances_security_group,
]
name = "${var.names_prefix}_nomad_client_lc"
name = "${var.name_prefix}_nomad_client_lc"
image_id = var.client_ami_id
instance_type = var.client_instance_type
iam_instance_profile = aws_iam_instance_profile.ecr_role_instance_profile.name
Expand All @@ -34,7 +34,7 @@ resource "aws_launch_configuration" "nomad_client_lc" {
#------------------------------------------------------------------------------
resource "aws_autoscaling_group" "nomad_client_asg" {
depends_on = [aws_launch_configuration.nomad_client_lc]
name = "${var.names_prefix}_nomad_client_asg"
name = "${var.name_prefix}_nomad_client_asg"
launch_configuration = aws_launch_configuration.nomad_client_lc.name
vpc_zone_identifier = var.subnets_ids
min_size = var.client_asg_min_size
Expand All @@ -43,9 +43,8 @@ resource "aws_autoscaling_group" "nomad_client_asg" {
tags = [
{
key = "Name"
value = "${var.names_prefix}_nomad_client_asg"
value = "${var.name_prefix}_nomad_client_asg"
propagate_at_launch = true
},
]
}

9 changes: 4 additions & 5 deletions paas-server.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data "template_file" "server_user_data" {
region = var.region
desired_servers = var.server_asg_desired_capacity
domain = var.domain_name
asg_name = "${var.names_prefix}_server_asg"
asg_name = "${var.name_prefix}_server_asg"
nomad_version = var.nomad_version
}
}
Expand All @@ -21,7 +21,7 @@ resource "aws_launch_configuration" "server_lc" {
aws_security_group.instances_security_group,
aws_iam_instance_profile.ec2_describe_instance_profile,
]
name = "${var.names_prefix}_server_lc"
name = "${var.name_prefix}_server_lc"
image_id = var.server_ami_id
instance_type = var.server_instance_type
iam_instance_profile = aws_iam_instance_profile.ec2_describe_instance_profile.name
Expand All @@ -37,7 +37,7 @@ resource "aws_launch_configuration" "server_lc" {
#------------------------------------------------------------------------------
resource "aws_autoscaling_group" "server_asg" {
depends_on = [aws_launch_configuration.server_lc]
name = "${var.names_prefix}_server_asg"
name = "${var.name_prefix}_server_asg"
launch_configuration = aws_launch_configuration.server_lc.name
vpc_zone_identifier = var.subnets_ids
min_size = var.server_asg_min_size
Expand All @@ -46,7 +46,7 @@ resource "aws_autoscaling_group" "server_asg" {
tags = [
{
key = "Name"
value = "${var.names_prefix}_server_asg"
value = "${var.name_prefix}_server_asg"
propagate_at_launch = true
},
]
Expand All @@ -66,4 +66,3 @@ resource "aws_autoscaling_attachment" "nomad_asg_attachment" {
autoscaling_group_name = aws_autoscaling_group.server_asg.id
elb = aws_elb.nomad_elb.id
}

Loading
Loading