diff --git a/_example/basic_example/.terraform.tfstate.lock.info b/_example/basic_example/.terraform.tfstate.lock.info deleted file mode 100644 index d5aa43d..0000000 --- a/_example/basic_example/.terraform.tfstate.lock.info +++ /dev/null @@ -1 +0,0 @@ -{"ID":"b632fa47-1aa6-d2b5-a5b7-f742fca4bf5f","Operation":"OperationTypeApply","Info":"","Who":"prakash@prakash","Version":"0.15.0","Created":"2021-05-27T15:08:24.304604354Z","Path":"terraform.tfstate"} diff --git a/main.tf b/main.tf index 2885c8f..2628ca6 100644 --- a/main.tf +++ b/main.tf @@ -20,6 +20,27 @@ locals { ebs_iops = var.ebs_volume_type == "io1" ? var.ebs_iops : 0 } +data "aws_ami" "amazon_linux" { + most_recent = true + + owners = ["amazon"] + + filter { + name = "name" + + values = [ + "amzn-ami-hvm-*-x86_64-gp2", + ] + } + + filter { + name = "owner-alias" + + values = [ + "amazon", + ] + } +} #Module : EC2 #Description : Terraform module to create an EC2 resource on AWS with Elastic IP Addresses @@ -27,7 +48,7 @@ locals { resource "aws_instance" "default" { count = var.instance_enabled == true ? var.instance_count : 0 - ami = var.ami + ami = var.ami == "" ? data.aws_ami.amazon_linux.id : var.ami ebs_optimized = var.ebs_optimized instance_type = var.instance_type key_name = var.key_name diff --git a/variables.tf b/variables.tf index 0143add..bccd1ab 100644 --- a/variables.tf +++ b/variables.tf @@ -58,6 +58,7 @@ variable "managedby" { # Description : Terraform EC2 module variables. variable "ami" { type = string + default = "" description = "The AMI to use for the instance." }