-
Notifications
You must be signed in to change notification settings - Fork 12
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
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
targets/slideruleearth-aws/terraform/cluster/sliderule-asg-r8g_2xlarge.tf.OPTION
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,97 @@ | ||
resource "aws_launch_template" "sliderule_template" { | ||
name_prefix = "${var.cluster_name}-" | ||
image_id = data.aws_ami.sliderule_cluster_ami.id | ||
instance_type = "r8g.2xlarge" | ||
|
||
block_device_mappings { | ||
device_name = "/dev/xvda" | ||
ebs { | ||
volume_size = var.cluster_volume_size | ||
volume_type = "gp2" | ||
delete_on_termination = true | ||
} | ||
} | ||
|
||
key_name = var.key_pair_name | ||
|
||
network_interfaces { | ||
associate_public_ip_address = true | ||
security_groups = [aws_security_group.sliderule-sg.id] | ||
} | ||
|
||
iam_instance_profile { | ||
name = aws_iam_instance_profile.s3-role.name | ||
} | ||
|
||
user_data = base64encode(<<-EOF | ||
#!/bin/bash | ||
export ENVIRONMENT_VERSION=${var.environment_version} | ||
export IPV4=$(hostname -I | awk '{print $1}') | ||
export CLUSTER=${var.cluster_name} | ||
export IS_PUBLIC=${var.is_public} | ||
export SLIDERULE_IMAGE=${var.container_repo}/sliderule:${var.cluster_version} | ||
export PROVISIONING_SYSTEM="https://ps.${var.domain}" | ||
export CONTAINER_REGISTRY=${var.container_repo} | ||
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin ${var.container_repo} | ||
aws s3 cp s3://sliderule/infrastructure/software/${var.cluster_name}-docker-compose-sliderule.yml ./docker-compose.yml | ||
docker pull ${var.container_repo}/oceaneyes | ||
docker-compose -p cluster up --detach | ||
EOF | ||
) | ||
|
||
tag_specifications { | ||
resource_type = "instance" | ||
tags = { | ||
Name = "${var.cluster_name}-node" | ||
Owner = "SlideRule" | ||
Project = "cluster-${var.cluster_name}" | ||
terraform-base-path = replace(path.cwd, "/^.*?(${local.terraform-git-repo}\\/)/", "$1") | ||
cost-grouping = "${var.cluster_name}" | ||
} | ||
} | ||
} | ||
|
||
resource "aws_autoscaling_group" "sliderule-cluster" { | ||
capacity_rebalance = true | ||
desired_capacity = var.node_asg_desired_capacity | ||
min_size = var.node_asg_min_capacity | ||
max_size = var.node_asg_max_capacity | ||
health_check_type = "EC2" | ||
vpc_zone_identifier = [ aws_subnet.sliderule-subnet.id ] | ||
|
||
launch_template { | ||
id = aws_launch_template.sliderule_template.id | ||
version = "$Latest" | ||
} | ||
|
||
tag { | ||
key = "Name" | ||
value = "${var.cluster_name}-node" | ||
propagate_at_launch = true | ||
} | ||
|
||
# the following match the provider "aws" default tags in providers.tf ... | ||
tag { | ||
key = "Owner" | ||
value = "SlideRule" | ||
propagate_at_launch = true | ||
} | ||
|
||
tag { | ||
key = "Project" | ||
value = "cluster-${var.cluster_name}" | ||
propagate_at_launch = true | ||
} | ||
|
||
tag { | ||
key = "terraform-base-path" | ||
value = replace(path.cwd, "/^.*?(${local.terraform-git-repo}\\/)/", "$1") | ||
propagate_at_launch = true | ||
} | ||
|
||
tag { | ||
key = "cost-grouping" | ||
value = "${var.cluster_name}" | ||
propagate_at_launch = true | ||
} | ||
} |