Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules/aws/ami: Add a new module to get CoreOS AMIs #84

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions modules/aws/ami/README.md
Original file line number Diff line number Diff line change
@@ -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/
38 changes: 38 additions & 0 deletions modules/aws/ami/main.tf
Original file line number Diff line number Diff line change
@@ -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}"]
}
}
4 changes: 4 additions & 0 deletions modules/aws/ami/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "id" {
value = "${data.aws_ami.coreos_ami.image_id}"
description = "The selected CoreOS Container Linux AMI ID."
}
30 changes: 30 additions & 0 deletions modules/aws/ami/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
variable "region" {
type = "string"

description = <<EOF
This is the AWS region.
It is passed through to the Terraform aws provider: https://www.terraform.io/docs/providers/aws/#region
EOF
}

variable "release_channel" {
type = "string"
default = "stable"

description = <<EOF
The Container Linux update channel.

Examples: `stable`, `beta`, `alpha`
EOF
}

variable "release_version" {
type = "string"
default = "latest"

description = <<EOF
The Container Linux version to use. Set to `latest` to select the latest available version for the selected update channel.

Examples: `latest`, `1465.6.0`
EOF
}
7 changes: 6 additions & 1 deletion modules/aws/etcd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ Read the [etcd recommended hardware guide][hardware] for best performance.
## Example

```hcl
provider "aws" {
locals {
region = "us-east-1"
}

provider "aws" {
region = "${local.region}"
}

resource "aws_s3_bucket" "etcd_ignition" {
}

Expand Down Expand Up @@ -50,6 +54,7 @@ module "etcd" {
cluster_id = "123"
cluster_name = "my-cluster"
instance_count = "3"
region = "${local.region}"
s3_bucket = "${aws_s3_bucket.etcd_ignition.id}"
sg_ids = ["${aws_security_group.etcd.id}"]
subnets = ["${aws_subnet.example.id}"]
Expand Down
32 changes: 5 additions & 27 deletions modules/aws/etcd/nodes.tf
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
locals {
ami_owner = "595879546273"
arn = "aws"
arn = "aws"
}

module "container_linux" {
source = "../../container_linux"
module "ami" {
source = "../ami"

region = "${var.region}"
release_channel = "${var.container_linux_channel}"
release_version = "${var.container_linux_version}"
}

data "aws_ami" "coreos_ami" {
filter {
name = "name"
values = ["CoreOS-${var.container_linux_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}"]
}
}

resource "aws_iam_instance_profile" "etcd" {
name = "${var.cluster_name}-etcd-profile"

Expand Down Expand Up @@ -106,7 +84,7 @@ EOF

resource "aws_instance" "etcd_node" {
count = "${var.instance_count}"
ami = "${coalesce(var.ec2_ami, data.aws_ami.coreos_ami.image_id)}"
ami = "${coalesce(var.ec2_ami, module.ami.id)}"

iam_instance_profile = "${aws_iam_instance_profile.etcd.name}"
instance_type = "${var.ec2_type}"
Expand Down
9 changes: 9 additions & 0 deletions modules/aws/etcd/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ variable "instance_count" {
default = "3"
}

variable "region" {
type = "string"

description = <<EOF
This is the AWS region.
It is passed through to the Terraform aws provider: https://www.terraform.io/docs/providers/aws/#region
EOF
}

variable "ssh_key" {
type = "string"
default = ""
Expand Down
29 changes: 7 additions & 22 deletions modules/aws/master-asg/master.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
locals {
ami_owner = "595879546273"
arn = "aws"
arn = "aws"
}

data "aws_ami" "coreos_ami" {
filter {
name = "name"
values = ["CoreOS-${var.container_linux_channel}-${var.container_linux_version}-*"]
}

filter {
name = "architecture"
values = ["x86_64"]
}
module "ami" {
source = "../ami"

filter {
name = "virtualization-type"
values = ["hvm"]
}

filter {
name = "owner-id"
values = ["${local.ami_owner}"]
}
region = "${var.region}"
release_channel = "${var.container_linux_channel}"
release_version = "${var.container_linux_version}"
}

resource "aws_autoscaling_group" "masters" {
Expand Down Expand Up @@ -61,7 +46,7 @@ resource "aws_autoscaling_group" "masters" {

resource "aws_launch_configuration" "master_conf" {
instance_type = "${var.ec2_type}"
image_id = "${coalesce(var.ec2_ami, data.aws_ami.coreos_ami.image_id)}"
image_id = "${coalesce(var.ec2_ami, module.ami.id)}"
name_prefix = "${var.cluster_name}-master-"
key_name = "${var.ssh_key}"
security_groups = ["${var.master_sg_ids}"]
Expand Down
9 changes: 9 additions & 0 deletions modules/aws/master-asg/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ variable "aws_lbs" {
default = []
}

variable "region" {
type = "string"

description = <<EOF
This is the AWS region.
It is passed through to the Terraform aws provider: https://www.terraform.io/docs/providers/aws/#region
EOF
}

variable "root_volume_iops" {
type = "string"
default = "100"
Expand Down
9 changes: 9 additions & 0 deletions modules/aws/worker-asg/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ variable "autoscaling_group_extra_tags" {
default = []
}

variable "region" {
type = "string"

description = <<EOF
This is the AWS region.
It is passed through to the Terraform aws provider: https://www.terraform.io/docs/providers/aws/#region
EOF
}

variable "root_volume_type" {
type = "string"
description = "The type of volume for the root block device."
Expand Down
29 changes: 7 additions & 22 deletions modules/aws/worker-asg/worker.tf
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
locals {
ami_owner = "595879546273"
arn = "aws"
arn = "aws"
}

data "aws_ami" "coreos_ami" {
filter {
name = "name"
values = ["CoreOS-${var.container_linux_channel}-${var.container_linux_version}-*"]
}

filter {
name = "architecture"
values = ["x86_64"]
}
module "ami" {
source = "../ami"

filter {
name = "virtualization-type"
values = ["hvm"]
}

filter {
name = "owner-id"
values = ["${local.ami_owner}"]
}
region = "${var.region}"
release_channel = "${var.container_linux_channel}"
release_version = "${var.container_linux_version}"
}

resource "aws_launch_configuration" "worker_conf" {
instance_type = "${var.ec2_type}"
image_id = "${coalesce(var.ec2_ami, data.aws_ami.coreos_ami.image_id)}"
image_id = "${coalesce(var.ec2_ami, module.ami.id)}"
name_prefix = "${var.cluster_name}-worker-"
key_name = "${var.ssh_key}"
security_groups = ["${var.sg_ids}"]
Expand Down
1 change: 1 addition & 0 deletions steps/etcd/aws/etcd.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module "etcd" {
ec2_type = "${var.tectonic_aws_etcd_ec2_type}"
extra_tags = "${var.tectonic_aws_extra_tags}"
instance_count = "${length(data.template_file.etcd_hostname_list.*.id)}"
region = "${var.tectonic_aws_region}"
root_volume_iops = "${var.tectonic_aws_etcd_root_volume_iops}"
root_volume_size = "${var.tectonic_aws_etcd_root_volume_size}"
root_volume_type = "${var.tectonic_aws_etcd_root_volume_type}"
Expand Down
1 change: 1 addition & 0 deletions steps/joining_workers/aws/workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module "workers" {
extra_tags = "${var.tectonic_aws_extra_tags}"
instance_count = "${var.tectonic_worker_count}"
load_balancers = "${var.tectonic_aws_worker_load_balancers}"
region = "${var.tectonic_aws_region}"
root_volume_iops = "${var.tectonic_aws_worker_root_volume_iops}"
root_volume_size = "${var.tectonic_aws_worker_root_volume_size}"
root_volume_type = "${var.tectonic_aws_worker_root_volume_type}"
Expand Down
1 change: 1 addition & 0 deletions steps/masters/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module "masters" {
master_sg_ids = "${concat(var.tectonic_aws_master_extra_sg_ids, list(local.sg_id))}"
private_endpoints = "${local.private_endpoints}"
public_endpoints = "${local.public_endpoints}"
region = "${var.tectonic_aws_region}"
root_volume_iops = "${var.tectonic_aws_master_root_volume_iops}"
root_volume_size = "${var.tectonic_aws_master_root_volume_size}"
root_volume_type = "${var.tectonic_aws_master_root_volume_type}"
Expand Down