Created
January 26, 2018 23:46
-
-
Save duduribeiro/156090f53ddbffb0b34be52e5c690a6d to your computer and use it in GitHub Desktop.
terraform_bastion
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
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" "test" { | |
ami = "${data.aws_ami.ubuntu.id}" | |
instance_type = "t2.micro" | |
subnet_id = "${module.networking.private_subnets_id[0]}" | |
vpc_security_group_ids = ["${module.networking.default_sg_id}"] | |
key_name = "${var.key_name}" | |
tags { | |
Name = "test-private" | |
} | |
} | |
resource "aws_security_group" "bastion" { | |
vpc_id = "${module.networking.vpc_id}" | |
name = "${var.environment}-bastion-host" | |
description = "Allow SSH to bastion host" | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { | |
from_port = 0 | |
to_port = 0 | |
protocol = "-1" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
from_port = 8 | |
to_port = 0 | |
protocol = "icmp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
tags { | |
Name = "${var.environment}-bastion-sg" | |
Environment = "${var.environment}" | |
} | |
} | |
resource "aws_instance" "bastion" { | |
ami = "${data.aws_ami.ubuntu.id}" | |
instance_type = "t2.micro" | |
key_name = "${var.key_name}" | |
monitoring = true | |
vpc_security_group_ids = ["${aws_security_group.bastion.id}"] | |
subnet_id = "${module.networking.public_subnets_id[0]}" | |
associate_public_ip_address = true | |
tags { | |
Name = "${var.environment}-bastion" | |
Environment = "${var.environment}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment