Skip to content

Commit

Permalink
demo-18
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Jun 15, 2018
1 parent af380f0 commit a192d0b
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 0 deletions.
29 changes: 29 additions & 0 deletions demo-18/instance.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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" "example" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.micro"

# the VPC subnet
subnet_id = "${var.ENV == "prod" ? module.vpc-prod.public_subnets[0] : module.vpc-dev.public_subnets[0] }"

# the security group
vpc_security_group_ids = ["${var.ENV == "prod" ? aws_security_group.allow-ssh-prod.id : aws_security_group.allow-ssh-dev.id }"]

# the public SSH key
key_name = "${aws_key_pair.mykeypair.key_name}"
}
4 changes: 4 additions & 0 deletions demo-18/key.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "aws_key_pair" "mykeypair" {
key_name = "mykeypair"
public_key = "${file("${var.PATH_TO_PUBLIC_KEY}")}"
}
3 changes: 3 additions & 0 deletions demo-18/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "${var.AWS_REGION}"
}
47 changes: 47 additions & 0 deletions demo-18/securitygroup.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
resource "aws_security_group" "allow-ssh-prod" {
vpc_id = "${module.vpc-prod.vpc_id}"
name = "allow-ssh"
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"
}
}

resource "aws_security_group" "allow-ssh-dev" {
vpc_id = "${module.vpc-dev.vpc_id}"
name = "allow-ssh"
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"
}
}
15 changes: 15 additions & 0 deletions demo-18/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
variable "AWS_REGION" {
default = "eu-west-1"
}

variable "PATH_TO_PRIVATE_KEY" {
default = "mykey"
}

variable "PATH_TO_PUBLIC_KEY" {
default = "mykey.pub"
}

variable "ENV" {
default = "prod"
}
37 changes: 37 additions & 0 deletions demo-18/vpc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module "vpc-prod" {
source = "terraform-aws-modules/vpc/aws"

name = "vpc-prod"
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 = "prod"
}
}

module "vpc-dev" {
source = "terraform-aws-modules/vpc/aws"

name = "vpc-dev"
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 = "dev"
}
}

0 comments on commit a192d0b

Please sign in to comment.