Skip to content

Commit

Permalink
EC2: Implement automatic detection of the AMI used for instance provi…
Browse files Browse the repository at this point in the history
…sioning.
  • Loading branch information
vulturm authored and Mihai Vultur committed Oct 13, 2017
1 parent 1a5ece2 commit 4d597a1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
28 changes: 2 additions & 26 deletions DevOpsVPC/infrastructure.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,7 @@ vpc_public_subnets = ["10.10.10.0/24"]


#-- EC2
ec2_ami = "ami-6d1c2007"
# TODO - search for AMI
#data "aws_ami" "jenkins" {
# most_recent = true
# owners = ["self"]
# filter {
# name = "tag:OS_Version"
# values = ["Fedora"]
# }
# filter {
# name = "tag:Release"
# values = ["25"]
# }
# filter {
# name = "architecture"
# values = ["x86_64"]
# }
# filter {
# name = "virtualization-type"
# values = ["hvm"]
# }
# filter {
# name = "name"
# values = ["Docker*"]
# }
#}
#-- ami determined automatically
ec2_os = "CentOS Linux 7 x86_64"
ssh_public_key_name = "terraform-ssh-key"
ssh_public_key_file = "~/.ssh/id_rsa.pub"
30 changes: 28 additions & 2 deletions DevOpsVPC/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ variable "ssh_public_key_file" {
}

#-- EC2
variable "ec2_ami" {
description = "Name of the AMI image used for EC2 creation"
variable "ec2_os" {
description = "OS version that will be used to find AMI image for EC2 creation"
type = "string"
}

Expand All @@ -75,6 +75,32 @@ variable "default_tags" {
}
}

#-- Determine latest CentOS AMI by our search criteria
data "aws_ami" "centos" {
most_recent = true
owners = ["679593333241"] # CentOS
filter {
name = "owner-alias"
values = ["aws-marketplace"]
}
filter {
name = "name"
values = ["${var.ec2_os}*"]
}
filter {
name = "state"
values = ["available"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}

# TODO for future
#...

0 comments on commit 4d597a1

Please sign in to comment.