From b23621fc25972ee67811a7cee9e47eefc1e82db9 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 31 Jul 2018 08:24:28 -0700 Subject: [PATCH] modules/aws/ami: Add a new module to get CoreOS AMIs Centralize this logic, which had previously been copied between three modules. I've also made the AWS region an explicit variable, instead of having the lower level modules reaching up to the tectonic_aws_region global. --- modules/aws/ami/README.md | 27 ++++++++++++++++++++ modules/aws/ami/main.tf | 38 ++++++++++++++++++++++++++++ modules/aws/ami/outputs.tf | 4 +++ modules/aws/ami/variables.tf | 30 ++++++++++++++++++++++ modules/aws/etcd/README.md | 7 ++++- modules/aws/etcd/nodes.tf | 32 ++++------------------- modules/aws/etcd/variables.tf | 9 +++++++ modules/aws/master-asg/master.tf | 29 +++++---------------- modules/aws/master-asg/variables.tf | 9 +++++++ modules/aws/worker-asg/variables.tf | 9 +++++++ modules/aws/worker-asg/worker.tf | 29 +++++---------------- steps/etcd/aws/etcd.tf | 1 + steps/joining_workers/aws/workers.tf | 1 + steps/masters/aws/main.tf | 1 + 14 files changed, 154 insertions(+), 72 deletions(-) create mode 100644 modules/aws/ami/README.md create mode 100644 modules/aws/ami/main.tf create mode 100644 modules/aws/ami/outputs.tf create mode 100644 modules/aws/ami/variables.tf 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 = <