-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 970440e
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.terraform | ||
terraform* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
terraform-aws-ami-ids | ||
================ | ||
|
||
Terraform module to lookup AMI IDs for use in other resources | ||
|
||
Usage | ||
----- | ||
|
||
```hcl | ||
module "ami_id" { | ||
source = | ||
distribution = "ecs" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Lookups on marketplace seem slower than others | ||
|
||
locals { | ||
names = "amazonlinux,ecs,ubuntu1604" | ||
|
||
owners = "${join(",", list( | ||
var.ami_owners["amazon"], | ||
var.ami_owners["amazon"], | ||
var.ami_owners["canonical"] | ||
))}" | ||
|
||
patterns = "${join(",", list( | ||
"amzn-ami-hvm-*-x86_64-gp2", | ||
"amzn-ami-${var.ami_version_ecs}-amazon-ecs-optimized", | ||
"ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*" | ||
))}" | ||
} | ||
|
||
# CentOS: CentOS Linux 7 x86_64 HVM EBS* | ||
# Fedora: Fedora-Cloud-Base-27-1.6.x86_64-us-west-2-HVM-gp2-0 | ||
|
||
data "aws_ami" "ami" { | ||
count = "${length(split(",", local.names))}" | ||
most_recent = true | ||
owners = ["${element(split(",", local.owners),count.index)}"] | ||
|
||
filter { | ||
name = "name" | ||
values = ["${element(split(",", local.patterns),count.index)}"] | ||
} | ||
|
||
filter { | ||
name = "architecture" | ||
values = ["x86_64"] | ||
} | ||
|
||
filter { | ||
name = "virtualization-type" | ||
values = ["hvm"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "ami_id" { | ||
description = "AMI ID for Linux distribution" | ||
value = "${element(data.aws_ami.ami.*.id, index(split(",", local.names), var.distribution))}" | ||
} | ||
|
||
output "ami_ids" { | ||
description = "All AMI IDs" | ||
value = "${data.aws_ami.ami.*.id}" | ||
} | ||
|
||
output "ami_names" { | ||
description = "All AMI Names" | ||
value = "${data.aws_ami.ami.*.name}" | ||
} | ||
|
||
output "distro_names" { | ||
description = "All distribution names. Can be used to index the other lists" | ||
value = "${split(",", local.names)}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
variable "ami_owners" { | ||
description = "AMI Owner IDs" | ||
type = "map" | ||
|
||
default = { | ||
amazon = "amazon" | ||
centos = "679593333241" # Marketplace | ||
canonical = "099720109477" | ||
fedora = "125523088429" | ||
} | ||
} | ||
|
||
variable "ami_version_ecs" { | ||
description = "Amazon ECS Optimized version to get" | ||
default = "*" | ||
} | ||
|
||
variable "distribution" { | ||
description = "Linux distribution for AWS AMI, supported: amazonlinux, ecs, ubuntu1604" | ||
} |