From f8e87689441497a578e595ae61833f0e80421aef Mon Sep 17 00:00:00 2001 From: Ryan Malloy Date: Sun, 10 Nov 2024 03:41:59 -0700 Subject: [PATCH] add prefix/suffix and disk size --- main.tf | 14 ++++++++++++-- variables.tf | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index bb61bc8..a9b82ae 100644 --- a/main.tf +++ b/main.tf @@ -60,7 +60,7 @@ resource "local_file" "public_key" { } resource "aws_key_pair" "deployer" { - key_name = "ubuntu_ssh_key" + key_name = "${var.name_prefix}-key-${var.name_suffix}" public_key = tls_private_key.ssh_key.public_key_openssh } @@ -130,18 +130,28 @@ data "aws_ami" "ubuntu" { resource "aws_instance" "ubuntu_instance" { ami = data.aws_ami.ubuntu.id - # Ubuntu "ami-0a0e5d9c7acc336f1" # ami = data.aws_ami.latest_ecs.ami # Amazon Linux instance_type = var.instance_size subnet_id = aws_subnet.public_subnet.id vpc_security_group_ids = [aws_security_group.allow_ssh_http_https.id] key_name = aws_key_pair.deployer.key_name associate_public_ip_address = true + name_prefix = var.name_prefix + resource_tag = var.name_suffix depends_on = [ aws_security_group.allow_ssh_http_https, aws_internet_gateway.igw ] + lifecycle { + ignore_changes = [ami] + } + + root_block_device { + volume_size = var.disk_size + delete_on_termination = true + } + user_data = var.user_data } diff --git a/variables.tf b/variables.tf index 3c60b75..1dbd87b 100644 --- a/variables.tf +++ b/variables.tf @@ -62,3 +62,8 @@ variable "name_suffix" { description = "The suffix for all your resources, suggest generating a unique value for each deployment" type = string } + +variable "disk_size" { + description = "Size of instance disk in Gigabytes" + default = 10 +}