mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
Commit finalized Terraform configuration
Commit finalized Terraform configuration using CentOS and CentOS Atomic Host images for working with an SSH bastion host Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org>
This commit is contained in:
parent
44500f14a3
commit
b115a5c624
6 changed files with 42 additions and 30 deletions
|
|
@ -1,13 +1,25 @@
|
|||
data "aws_ami" "atomic_ami" {
|
||||
most_recent = true
|
||||
owners = ["410186602215"]
|
||||
filter {
|
||||
name = "name"
|
||||
values = ["*CentOS Atomic*1701*"]
|
||||
values = ["CentOS Atomic Host 7*"]
|
||||
}
|
||||
filter {
|
||||
name = "virtualization-type"
|
||||
values = ["hvm"]
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_ami" "centos_ami" {
|
||||
most_recent = true
|
||||
owners = ["410186602215"]
|
||||
filter {
|
||||
name = "name"
|
||||
values = ["*CentOS 7.3.1611*"]
|
||||
values = ["CentOS Linux 7*"]
|
||||
}
|
||||
filter {
|
||||
name = "virtualization-type"
|
||||
values = ["hvm"]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,22 +7,24 @@ resource "aws_instance" "bastion" {
|
|||
subnet_id = "${aws_subnet.bastion_net.id}"
|
||||
depends_on = ["aws_internet_gateway.bastion_gw"]
|
||||
tags {
|
||||
Name = "bastion"
|
||||
tool = "terraform"
|
||||
demo = "bastion-aws"
|
||||
area = "instances"
|
||||
}
|
||||
}
|
||||
|
||||
# Launch a second CentOS instance to serve as a remote host
|
||||
resource "aws_instance" "remote" {
|
||||
ami = "${data.aws_ami.centos_ami.id}"
|
||||
# Launch a CentOS Atomic Host instance to serve as a private host
|
||||
resource "aws_instance" "private" {
|
||||
ami = "${data.aws_ami.atomic_ami.id}"
|
||||
instance_type = "${var.flavor}"
|
||||
key_name = "${var.keypair}"
|
||||
vpc_security_group_ids = ["${aws_security_group.remote_sg.id}"]
|
||||
subnet_id = "${aws_subnet.bastion_net.id}"
|
||||
vpc_security_group_ids = ["${aws_security_group.private_sg.id}"]
|
||||
subnet_id = "${aws_subnet.private_net.id}"
|
||||
depends_on = ["aws_internet_gateway.bastion_gw"]
|
||||
associate_public_ip_address = false
|
||||
tags {
|
||||
Name = "private"
|
||||
tool = "terraform"
|
||||
demo = "bastion-aws"
|
||||
area = "instances"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# Create a new VPC
|
||||
resource "aws_vpc" "bastion_vpc" {
|
||||
cidr_block = "10.2.0.0/16"
|
||||
enable_dns_hostnames = "true"
|
||||
enable_dns_support = "true"
|
||||
enable_dns_hostnames = true
|
||||
enable_dns_support = true
|
||||
tags {
|
||||
tool = "terraform"
|
||||
demo = "bastion-aws"
|
||||
|
|
@ -14,7 +14,19 @@ resource "aws_vpc" "bastion_vpc" {
|
|||
resource "aws_subnet" "bastion_net" {
|
||||
vpc_id = "${aws_vpc.bastion_vpc.id}"
|
||||
cidr_block = "10.2.1.0/24"
|
||||
map_public_ip_on_launch = "true"
|
||||
map_public_ip_on_launch = true
|
||||
tags {
|
||||
tool = "terraform"
|
||||
demo = "bastion-aws"
|
||||
area = "networking"
|
||||
}
|
||||
}
|
||||
|
||||
# Create a private subnet in the new VPC
|
||||
resource "aws_subnet" "private_net" {
|
||||
vpc_id = "${aws_vpc.bastion_vpc.id}"
|
||||
cidr_block = "10.2.2.0/24"
|
||||
map_public_ip_on_launch = false
|
||||
tags {
|
||||
tool = "terraform"
|
||||
demo = "bastion-aws"
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ output "bastion_priv_ip" {
|
|||
}
|
||||
|
||||
output "remote_priv_ip" {
|
||||
value = ["${aws_instance.remote.private_ip}"]
|
||||
value = ["${aws_instance.private.private_ip}"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,13 @@
|
|||
# Create a security group to allow web traffic to remote host
|
||||
resource "aws_security_group" "remote_sg" {
|
||||
# Create a security group to allow SSH traffic to private host(s) only from bastion
|
||||
resource "aws_security_group" "private_sg" {
|
||||
vpc_id = "${aws_vpc.bastion_vpc.id}"
|
||||
name = "remote-sg"
|
||||
description = "Security group for web traffic to remote hosts"
|
||||
ingress {
|
||||
from_port = "80"
|
||||
to_port = "80"
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
ingress {
|
||||
from_port = "443"
|
||||
to_port = "443"
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
name = "private-sg"
|
||||
description = "Security group for web traffic to private hosts"
|
||||
ingress {
|
||||
from_port = "22"
|
||||
to_port = "22"
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["${aws_vpc.bastion_vpc.cidr_block}"]
|
||||
cidr_blocks = ["10.2.1.0/24"]
|
||||
}
|
||||
egress {
|
||||
from_port = "0"
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
variable "keypair" {
|
||||
type = "string"
|
||||
description = "AWS SSH keypair to use to connect to instances"
|
||||
default = "aws_rsa"
|
||||
}
|
||||
|
||||
variable "flavor" {
|
||||
type = "string"
|
||||
description = "AWS type to use when creating instances"
|
||||
default = "t2.micro"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue