Skip to content

Instantly share code, notes, and snippets.

@Gunisalvo
Created June 19, 2018 10:26
Show Gist options
  • Save Gunisalvo/6e14670ea441f9052c9b10a2265e828d to your computer and use it in GitHub Desktop.
Save Gunisalvo/6e14670ea441f9052c9b10a2265e828d to your computer and use it in GitHub Desktop.
UoL: Cloud Computing week 3 (storage)
variable "student_name" {
default = "STUDENT_NAME" #fix me!
}
variable "region" {
default = "us-east-2"
}
provider "aws" {
region = "${var.region}"
}
resource "aws_security_group" "uol_security" {
name = "CKIT523-Group-${var.student_name}"
description = "Uol Security"
ingress {
from_port = 22
to_port = 22
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_ebs_volume" "uol_storage" {
availability_zone = "${var.region}a"
size = 1
tags {
Name = "ebs_wk3_${var.student_name}"
}
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "uol_ec2" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.medium"
key_name = "CKIT523Key-${var.student_name}"
availability_zone = "${var.region}a"
security_groups = [
"${aws_security_group.uol_security.name}"
]
tags {
Name = "CKIT523-${var.student_name}"
}
}
resource "aws_volume_attachment" "ebs_mapping" {
device_name = "/dev/sdh"
volume_id = "${aws_ebs_volume.uol_storage.id}"
instance_id = "${aws_instance.uol_ec2.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment