diff --git a/modules/aws/ami/README.md b/modules/aws/ami/README.md new file mode 100644 index 00000000000..61f43f421e8 --- /dev/null +++ b/modules/aws/ami/README.md @@ -0,0 +1,27 @@ +# Container Linux AMI Module + +This [Terraform][] [module][] supports `latest` versions for [Container Linux][container-linux] release channels and returns an appropriate [AMI][]. + +## Example + +From the module directory: + +```console +$ terraform init +$ terraform apply --var region=us-east-1 +$ terraform output id +ami-ab6963d4 +$ terraform apply --var region=us-east-1 --var release_channel=alpha +$ terraform output id +ami-985953e7 +$ terraform apply --var region=us-east-2 --var release_channel=alpha --var release_version=1814.0.0 +$ terraform output id +ami-c25f66a7 +``` + +When you're done, clean up by removing the `.terraform` directory created by `init` and the `terraform.tfstate*` files created by `apply`. + +[AMI]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html +[container-linux]: https://coreos.com/os/docs/latest/ +[module]: https://www.terraform.io/docs/modules/ +[Terraform]: https://www.terraform.io/ diff --git a/modules/aws/ami/main.tf b/modules/aws/ami/main.tf new file mode 100644 index 00000000000..1593457145e --- /dev/null +++ b/modules/aws/ami/main.tf @@ -0,0 +1,38 @@ +provider "aws" { + region = "${var.region}" + version = "1.8.0" +} + +locals { + ami_owner = "595879546273" + arn = "aws" +} + +module "container_linux" { + source = "../../container_linux" + + release_channel = "${var.release_channel}" + release_version = "${var.release_version}" +} + +data "aws_ami" "coreos_ami" { + filter { + name = "name" + values = ["CoreOS-${var.release_channel}-${module.container_linux.version}-*"] + } + + filter { + name = "architecture" + values = ["x86_64"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + filter { + name = "owner-id" + values = ["${local.ami_owner}"] + } +} diff --git a/modules/aws/ami/outputs.tf b/modules/aws/ami/outputs.tf new file mode 100644 index 00000000000..b6ed23ce383 --- /dev/null +++ b/modules/aws/ami/outputs.tf @@ -0,0 +1,4 @@ +output "id" { + value = "${data.aws_ami.coreos_ami.image_id}" + description = "The selected CoreOS Container Linux AMI ID." +} diff --git a/modules/aws/ami/variables.tf b/modules/aws/ami/variables.tf new file mode 100644 index 00000000000..5b84b10cdd5 --- /dev/null +++ b/modules/aws/ami/variables.tf @@ -0,0 +1,30 @@ +variable "region" { + type = "string" + + description = <