Skip to content

Commit

Permalink
Pass instance IP around instead of ID
Browse files Browse the repository at this point in the history
  • Loading branch information
camjackson committed Nov 4, 2017
1 parent dba0e4d commit 8255d8c
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 15 deletions.
11 changes: 9 additions & 2 deletions terraform/apps/core.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module "core_app" {
name = "core"
docker_image = "rabblerouser/core"
port = "${var.app_ports["core"]}"
aws_instance_id = "${var.aws_instance_id}"
aws_instance_ip = "${var.aws_instance_ip}"
alb_listener_arn = "${var.alb_listener_arn}"
alb_listener_rule_priority = "1"
docker_credentials = "${var.docker_credentials}"
Expand All @@ -14,10 +14,17 @@ module "core_app" {
env = ["SESSION_SECRET=${random_id.session_secret.hex}"]
}

data "aws_instance" "instance" {
filter {
name = "ip-address"
values = ["${var.aws_instance_ip}"]
}
}

resource "random_id" "session_secret" {
keepers = {
# Generate a new session secret when instance ID changes
ec2_instance_id = "${var.aws_instance_id}"
ec2_instance_id = "${data.aws_instance.instance.id}"
}
byte_length = 32
}
5 changes: 4 additions & 1 deletion terraform/apps/docker-node-app/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ data "aws_vpc" "default_vpc" {
}

data "aws_instance" "instance" {
instance_id = "${var.aws_instance_id}"
filter {
name = "ip-address"
values = ["${var.aws_instance_ip}"]
}
}

data "aws_lb_listener" "alb_listener" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/apps/docker-node-app/docker.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
provider "docker" {
version = "~> 0.1.0"
host = "tcp://${data.aws_instance.instance.public_ip}:2376"
host = "tcp://${var.aws_instance_ip}:2376"
key_material = "${var.docker_credentials["key"]}"
ca_material = "${var.docker_credentials["ca"]}"
cert_material = "${var.docker_credentials["cert"]}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data "aws_s3_bucket_object" "event_forwarder_zip" {

resource "random_id" "auth_token" {
keepers = {
# Generate a new token when the lambda code updates or the EC2 instance changes
# Generate a new token when the lambda code updates
lambda_zip_version = "${data.aws_s3_bucket_object.event_forwarder_zip.version_id}"
}

Expand Down
2 changes: 1 addition & 1 deletion terraform/apps/docker-node-app/networking.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ resource "aws_lb_target_group" "alb_target_group" {

resource "aws_lb_target_group_attachment" "alb_target_attachment" {
target_group_arn = "${aws_lb_target_group.alb_target_group.arn}"
target_id = "${var.aws_instance_id}"
target_id = "${data.aws_instance.instance.id}"
}
4 changes: 2 additions & 2 deletions terraform/apps/docker-node-app/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ variable "env" {
default = []
}

variable "aws_instance_id" {
description = "The ID of the EC2 instance where the app should be deployed"
variable "aws_instance_ip" {
description = "The public IP address of the EC2 instance where this app should be deployed"
type = "string"
}

Expand Down
2 changes: 1 addition & 1 deletion terraform/apps/group-mailer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module "group_mailer_app" {
name = "group-mailer"
docker_image = "rabblerouser/group-mailer"
port = "${var.app_ports["group_mailer"]}"
aws_instance_id = "${var.aws_instance_id}"
aws_instance_ip = "${var.aws_instance_ip}"
alb_listener_arn = "${var.alb_listener_arn}"
alb_listener_rule_priority = "3"
docker_credentials = "${var.docker_credentials}"
Expand Down
2 changes: 1 addition & 1 deletion terraform/apps/mailer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module "mailer_app" {
name = "mailer"
docker_image = "rabblerouser/mailer"
port = "${var.app_ports["mailer"]}"
aws_instance_id = "${var.aws_instance_id}"
aws_instance_ip = "${var.aws_instance_ip}"
alb_listener_arn = "${var.alb_listener_arn}"
alb_listener_rule_priority = "2"
docker_credentials = "${var.docker_credentials}"
Expand Down
4 changes: 2 additions & 2 deletions terraform/apps/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ variable "app_ports" {
type = "map"
}

variable "aws_instance_id" {
description = "The ID of the EC2 instance where this app should be deployed"
variable "aws_instance_ip" {
description = "The public IP address of the EC2 instance where this app should be deployed"
type = "string"
}

Expand Down
4 changes: 2 additions & 2 deletions terraform/base/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ output "host_ip" {
value = "${aws_instance.web.public_ip}"
}

output "aws_instance_id" {
value = "${aws_instance.web.id}"
output "aws_instance_ip" {
value = "${aws_instance.web.public_ip}"
}

output "alb_listener_arn" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module apps {
route53_zone_id = "${local.route53_zone_id}"

app_ports = "${local.app_ports}"
aws_instance_id = "${module.base.aws_instance_id}"
aws_instance_ip = "${module.base.aws_instance_ip}"
alb_listener_arn = "${module.base.alb_listener_arn}"
docker_credentials = "${module.base.docker_credentials}"
stream_name = "${module.base.stream_name}"
Expand Down

0 comments on commit 8255d8c

Please sign in to comment.