Skip to content

Commit

Permalink
Merge pull request #11 from tablexi/ec2_ami
Browse files Browse the repository at this point in the history
UPDATE data ami resource to be optional
  • Loading branch information
phoolish authored Nov 18, 2017
2 parents 6c7c735 + 0ccb72f commit cf305a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ec2/example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ module "ec2-test1" {
subnets = ["ec2-test1"]
vpc_security_group_ids = ["ec2-test1"]
}

module "ec2-test2" {
source = "../"

ami = "ec2-test2"
key_name = "ec2-test2"
name = "ec2-test2"
subnets = ["ec2-test2"]
vpc_security_group_ids = ["ec2-test2"]
}
3 changes: 2 additions & 1 deletion ec2/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
data "aws_ami" "mod" {
count = "${var.ami == "" ? 1 : 0}"
most_recent = true

filter {
Expand All @@ -11,7 +12,7 @@ data "aws_ami" "mod" {

resource "aws_instance" "mod" {
count = "${var.count}"
ami = "${var.ami != "" ? var.ami : data.aws_ami.mod.id}"
ami = "${var.ami != "" ? var.ami : element(concat(data.aws_ami.mod.*.id, list("")), 0)}"
instance_type = "${var.type}"
key_name = "${var.key_name}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
Expand Down

0 comments on commit cf305a5

Please sign in to comment.