make DB hosts use the same VPC as the EB env

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-11-03 18:02:27 +01:00
parent 7b9b37389a
commit 4d940e0b6b
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
6 changed files with 47 additions and 5 deletions

4
dev.tf
View File

@ -45,6 +45,10 @@ module "dev_db" {
domain = var.public_domain
open_ports = [27017] /* mongodb */
/* Network */
vpc_id = module.dev_env.vpc_id
subnet_id = module.dev_env.subnet_ids[0]
sec_group = module.dev_env.security_group_id
/* Plumbing */
keypair_name = aws_key_pair.admin.key_name
gandi_zone_id = gandi_zone.dap_ps_zone.id

View File

@ -23,3 +23,15 @@ output "elb_names" {
output "elb_fqdns" {
value = [for elb in data.aws_elb.main: elb.dns_name]
}
output "vpc_id" {
value = module.vpc.vpc_id
}
output "subnet_ids" {
value = module.subnets.public_subnet_ids
}
output "security_group_id" {
value = module.vpc.vpc_default_security_group_id
}

View File

@ -30,8 +30,8 @@ variable "keypair_name" {
variable "max_availability_zones" {
description = "Maximum number of availability zones that can be used in Subnet."
default = "2"
type = string
default = 2
type = number
}
variable "env_vars" {

View File

@ -19,6 +19,9 @@ resource "aws_security_group" "main" {
name = "default-${var.zone}-${var.env}-${var.stage}"
description = "Allow SSH and other ports. (Terraform)"
/* needs to exist in VPC of the instance */
vpc_id = var.vpc_id
/* unrestricted outging traffic */
egress {
from_port = 0
@ -47,6 +50,7 @@ resource "aws_security_group" "main" {
}
}
resource "aws_instance" "main" {
instance_type = var.instance_type
availability_zone = var.zone
@ -55,9 +59,10 @@ resource "aws_instance" "main" {
/* necessary for SSH access */
associate_public_ip_address = true
ami = data.aws_ami.ubuntu.id
key_name = var.keypair_name
security_groups = [aws_security_group.main.name]
ami = data.aws_ami.ubuntu.id
key_name = var.keypair_name
subnet_id = var.subnet_id
vpc_security_group_ids = [var.sec_group, aws_security_group.main.id]
tags = {
Name = "node-${format("%02d", count.index+1)}.${local.host_suffix}"

View File

@ -46,6 +46,23 @@ variable "keypair_name" {
type = string
}
/* NETWORK --------------------------------------*/
variable "vpc_id" {
description = "ID of VPC for the instance."
type = string
}
variable "subnet_id" {
description = "ID of the subnet to use for the instance."
type = string
}
variable "sec_group" {
description = "ID of the VPC security group for the instance."
type = string
}
/* DNS ------------------------------------------*/
variable "gandi_zone_id" {

View File

@ -49,6 +49,10 @@ module "prod_db" {
domain = var.public_domain
open_ports = [27017] /* mongodb */
/* Network */
vpc_id = module.prod_env.vpc_id
subnet_id = module.prod_env.subnet_ids[0]
sec_group = module.prod_env.security_group_id
/* Plumbing */
keypair_name = aws_key_pair.admin.key_name
gandi_zone_id = gandi_zone.dap_ps_zone.id