This commit is contained in:
Edward Viaene
2018-06-18 08:36:34 +00:00
parent e4ae2ee048
commit 938ba0bfd0
8 changed files with 141 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
module "main-vpc" {
source = "../modules/vpc"
ENV = "dev"
AWS_REGION = "${var.AWS_REGION}"
}
module "instances" {
source = "../modules/instances"
ENV = "dev"
VPC_ID = "${module.main-vpc.vpc_id}"
PUBLIC_SUBNETS = ["${module.main-vpc.public_subnets}"]
}
+3
View File
@@ -0,0 +1,3 @@
provider "aws" {
region = "${var.AWS_REGION}"
}
+3
View File
@@ -0,0 +1,3 @@
variable "AWS_REGION" {
default = "eu-west-1"
}
+70
View File
@@ -0,0 +1,70 @@
variable "ENV" {}
variable "INSTANCE_TYPE" { default = "t2.micro" }
variable "PUBLIC_SUBNETS" { type = "list" }
variable "VPC_ID" {}
variable "PATH_TO_PUBLIC_KEY" { default = "mykey.pub" }
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "instance" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "${var.INSTANCE_TYPE}"
# the VPC subnet
subnet_id = "${var.PUBLIC_SUBNETS[0]}"
# the security group
vpc_security_group_ids = ["${aws_security_group.allow-ssh.id}"]
# the public SSH key
key_name = "${aws_key_pair.mykeypair.key_name}"
tags {
Name = "instance-${var.ENV}"
Environmnent = "${var.ENV}"
}
}
resource "aws_security_group" "allow-ssh" {
vpc_id = "${var.VPC_ID}"
name = "allow-ssh-${var.ENV}"
description = "security group that allows ssh and all egress traffic"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags {
Name = "allow-ssh"
Environmnent = "${var.ENV}"
}
}
resource "aws_key_pair" "mykeypair" {
key_name = "mykeypair-${var.ENV}"
public_key = "${file("${path.root}/${var.PATH_TO_PUBLIC_KEY}")}"
}
+35
View File
@@ -0,0 +1,35 @@
variable "ENV" {}
variable "AWS_REGION" {}
module "main-vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "vpc-prod-${var.ENV}"
cidr = "10.0.0.0/16"
azs = ["${var.AWS_REGION}a", "${var.AWS_REGION}b", "${var.AWS_REGION}c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
enable_nat_gateway = false
enable_vpn_gateway = false
tags = {
Terraform = "true"
Environment = "${var.ENV}"
}
}
output "vpc_id" {
description = "The ID of the VPC"
value = "${module.main-vpc.vpc_id}"
}
output "private_subnets" {
description = "List of IDs of private subnets"
value = ["${module.main-vpc.private_subnets}"]
}
output "public_subnets" {
description = "List of IDs of public subnets"
value = ["${module.main-vpc.public_subnets}"]
}
+12
View File
@@ -0,0 +1,12 @@
module "main-vpc" {
source = "../modules/vpc"
ENV = "prod"
AWS_REGION = "${var.AWS_REGION}"
}
module "instances" {
source = "../modules/instances"
ENV = "prod"
VPC_ID = "${module.main-vpc.vpc_id}"
PUBLIC_SUBNETS = ["${module.main-vpc.public_subnets}"]
}
+3
View File
@@ -0,0 +1,3 @@
provider "aws" {
region = "${var.AWS_REGION}"
}
+3
View File
@@ -0,0 +1,3 @@
variable "AWS_REGION" {
default = "eu-west-1"
}