AWS EC2

The current AMIs for all Flatcar Container Linux channels and EC2 regions are listed below and updated frequently. Using CloudFormation is the easiest way to launch a cluster, but it is also possible to follow the manual steps at the end of the article. Questions can be directed to the Flatcar Container Linux Discord server or user mailing list .

At the end of the document there are instructions for deploying with Terraform.

Release retention time

After publishing, releases will remain available as public AMIs on AWS for 9 months. AMIs older than 9 months will be un-published in regular garbage collection sweeps. Please note that this will not impact existing AWS instances that use those releases. However, deploying new instances (e.g. in autoscaling groups pinned to a specific AMI) will not be possible after the AMI was un-published.

Choosing a channel

Flatcar Container Linux is designed to be updated automatically with different schedules per channel. You can disable this feature , although we don’t recommend it. Read the release notes for specific features and bug fixes.

The Stable channel should be used by production clusters. Versions of Flatcar Container Linux are battle-tested within the Beta and Alpha channels before being promoted. The current version is Flatcar Container Linux 4757.2.3.

View as json feed: amd64 arm64
EC2 Region AMI Type AMI ID CloudFormation
af-south-1 HVM (amd64) ami-0430a72d88c5ca71c Launch Stack
HVM (arm64) ami-0ef331579536ab3b8 Launch Stack
ap-east-1 HVM (amd64) ami-098bda79491d27f4d Launch Stack
HVM (arm64) ami-0fc3905a5fc061b0f Launch Stack
ap-northeast-1 HVM (amd64) ami-04c41a20ea1b07bf9 Launch Stack
HVM (arm64) ami-0cd6ee371169c3b8a Launch Stack
ap-northeast-2 HVM (amd64) ami-054045c246d08c802 Launch Stack
HVM (arm64) ami-0ed999d38e4947643 Launch Stack
ap-south-1 HVM (amd64) ami-02eacd7e2bc68c071 Launch Stack
HVM (arm64) ami-0370424a49f8022d0 Launch Stack
ap-southeast-1 HVM (amd64) ami-0b033f21410ef992f Launch Stack
HVM (arm64) ami-0d5caaaad66c3ecf9 Launch Stack
ap-southeast-2 HVM (amd64) ami-0412e7b4de9218dd2 Launch Stack
HVM (arm64) ami-024fa487b085a24d6 Launch Stack
ap-southeast-3 HVM (amd64) ami-056115e7e656b9faa Launch Stack
HVM (arm64) ami-001f59c3eadd15290 Launch Stack
ca-central-1 HVM (amd64) ami-0f87584654943f802 Launch Stack
HVM (arm64) ami-06896e6cf180bccd3 Launch Stack
eu-central-1 HVM (amd64) ami-09343c04023176231 Launch Stack
HVM (arm64) ami-0b01e7029ad78719b Launch Stack
eu-north-1 HVM (amd64) ami-061249663131c5e60 Launch Stack
HVM (arm64) ami-067d9002c063417ad Launch Stack
eu-south-1 HVM (amd64) ami-04fc68aa5028ea74d Launch Stack
HVM (arm64) ami-01db7461584f546a5 Launch Stack
eu-west-1 HVM (amd64) ami-0aba004ab079dee30 Launch Stack
HVM (arm64) ami-026d0ef72e8d45e0a Launch Stack
eu-west-2 HVM (amd64) ami-00ad783931676ef90 Launch Stack
HVM (arm64) ami-020393134881a88f1 Launch Stack
eu-west-3 HVM (amd64) ami-00dce8a25f1e0af9e Launch Stack
HVM (arm64) ami-0c84f6966b49b1f86 Launch Stack
sa-east-1 HVM (amd64) ami-00acf87b401754ebb Launch Stack
HVM (arm64) ami-0351a1c043dfd3a7c Launch Stack
us-east-1 HVM (amd64) ami-0d483f3bf93a02c94 Launch Stack
HVM (arm64) ami-03beeda7a89fffbed Launch Stack
us-east-2 HVM (amd64) ami-0bfc09f7778d53e24 Launch Stack
HVM (arm64) ami-0990458ded155d063 Launch Stack
us-west-1 HVM (amd64) ami-022db385aeec62079 Launch Stack
HVM (arm64) ami-0b4c3502e85bbcb36 Launch Stack
us-west-2 HVM (amd64) ami-0e0eb85f1ae388871 Launch Stack
HVM (arm64) ami-060928960204a3733 Launch Stack

The Beta channel consists of promoted Alpha releases. The current version is Flatcar Container Linux 4820.1.1.

View as json feed: amd64 arm64
EC2 Region AMI Type AMI ID CloudFormation
af-south-1 HVM (amd64) ami-0afe197b7f8957c82 Launch Stack
HVM (arm64) ami-0be4496306021035a Launch Stack
ap-east-1 HVM (amd64) ami-02e1fdf8020baa816 Launch Stack
HVM (arm64) ami-0a0d694c37ca440c1 Launch Stack
ap-east-2 HVM (amd64) ami-0bcc63217f7a02cd0 Launch Stack
HVM (arm64) ami-0c3cd82c6bd4d07ef Launch Stack
ap-northeast-1 HVM (amd64) ami-00c19688313c00c3d Launch Stack
HVM (arm64) ami-0f1d0c99e88667b69 Launch Stack
ap-northeast-2 HVM (amd64) ami-0c8af6ed80436a67b Launch Stack
HVM (arm64) ami-0f087e6664cd254a6 Launch Stack
ap-south-1 HVM (amd64) ami-05b6d4c3c9cb159cf Launch Stack
HVM (arm64) ami-01ce49576be68b29d Launch Stack
ap-south-2 HVM (amd64) ami-071b6eaa43cd8be1c Launch Stack
HVM (arm64) ami-0c3aa498ddd9a9815 Launch Stack
ap-southeast-1 HVM (amd64) ami-0431be9ef1e27b0b1 Launch Stack
HVM (arm64) ami-07d147307e0b955cd Launch Stack
ap-southeast-2 HVM (amd64) ami-0e08dfd5de83a4d0a Launch Stack
HVM (arm64) ami-032011ffdcfe24f6b Launch Stack
ap-southeast-3 HVM (amd64) ami-08a8c3838bd24cbb3 Launch Stack
HVM (arm64) ami-093674ecc0038af8a Launch Stack
ap-southeast-4 HVM (amd64) ami-0d7bf3cd561d8a8c2 Launch Stack
HVM (arm64) ami-0d83d637e473814d3 Launch Stack
ap-southeast-5 HVM (amd64) ami-07a08d8e35715796c Launch Stack
HVM (arm64) ami-0cbed0730a2113bc9 Launch Stack
ap-southeast-6 HVM (amd64) ami-0c29c45720bf04c29 Launch Stack
HVM (arm64) ami-0482b1df306380009 Launch Stack
ap-southeast-7 HVM (amd64) ami-09b978901a49c4577 Launch Stack
HVM (arm64) ami-09e85f03dbcef0aae Launch Stack
ca-central-1 HVM (amd64) ami-05e7ed4eae8bb1699 Launch Stack
HVM (arm64) ami-07dad6dc4896939f7 Launch Stack
ca-west-1 HVM (amd64) ami-0fb54f255759d5da6 Launch Stack
HVM (arm64) ami-00d3a93dc2aa7f9d0 Launch Stack
eu-central-1 HVM (amd64) ami-0c97dc679b345da54 Launch Stack
HVM (arm64) ami-0f440b05de5d7290c Launch Stack
eu-central-2 HVM (amd64) ami-059756170542ddce5 Launch Stack
HVM (arm64) ami-03e5e790a1348b4fe Launch Stack
eu-north-1 HVM (amd64) ami-0ea9588e021ba6c30 Launch Stack
HVM (arm64) ami-0bc79a7c87d94ebfc Launch Stack
eu-south-1 HVM (amd64) ami-0f06cbd60a4f6b3c7 Launch Stack
HVM (arm64) ami-0bdadff4a4f5fde91 Launch Stack
eu-south-2 HVM (amd64) ami-0b1bfaa1e6f365e78 Launch Stack
HVM (arm64) ami-0888b49e52754577f Launch Stack
eu-west-1 HVM (amd64) ami-05d46badfceb1e3e7 Launch Stack
HVM (arm64) ami-0ed04f5d147cea2a5 Launch Stack
eu-west-2 HVM (amd64) ami-0a35238e8c448be58 Launch Stack
HVM (arm64) ami-080eb090fbb52f382 Launch Stack
eu-west-3 HVM (amd64) ami-073d275bc22c3e95f Launch Stack
HVM (arm64) ami-01311e5577a6570dd Launch Stack
il-central-1 HVM (amd64) ami-094b482d35a8c341a Launch Stack
HVM (arm64) ami-03a77aba41df6b2ed Launch Stack
mx-central-1 HVM (amd64) ami-036965c8002cae4d7 Launch Stack
HVM (arm64) ami-03f361feceafcbbd9 Launch Stack
sa-east-1 HVM (amd64) ami-0ff90c25b35e04ce7 Launch Stack
HVM (arm64) ami-04ba1ae53c97c7b0b Launch Stack
us-east-1 HVM (amd64) ami-06c70fc368daab3ec Launch Stack
HVM (arm64) ami-0c88bd10a4b28b606 Launch Stack
us-east-2 HVM (amd64) ami-0215fc9b8ec81930d Launch Stack
HVM (arm64) ami-07bfbf255feda298e Launch Stack
us-west-1 HVM (amd64) ami-08fe6da8790bdc206 Launch Stack
HVM (arm64) ami-018cfa740cbd06bbf Launch Stack
us-west-2 HVM (amd64) ami-0d08b96cd6cf17f86 Launch Stack
HVM (arm64) ami-03b43ca7057b2acb4 Launch Stack

The Alpha channel closely tracks master and is released frequently. The newest versions of system libraries and utilities will be available for testing. The current version is Flatcar Container Linux 4865.0.0.

View as json feed: amd64 arm64
EC2 Region AMI Type AMI ID CloudFormation
af-south-1 HVM (amd64) ami-0d471540c9b62538d Launch Stack
HVM (arm64) ami-0f4b5096a080b8365 Launch Stack
ap-east-1 HVM (amd64) ami-04a633b7ef63028dc Launch Stack
HVM (arm64) ami-0bc52622384a1e19c Launch Stack
ap-northeast-1 HVM (amd64) ami-046ed152bad8e9dec Launch Stack
HVM (arm64) ami-0aab3217d799ca4f1 Launch Stack
ap-northeast-2 HVM (amd64) ami-05e7ec5d26974ca5d Launch Stack
HVM (arm64) ami-0d261b89691ca0aab Launch Stack
ap-south-1 HVM (amd64) ami-00bf97204921ab309 Launch Stack
HVM (arm64) ami-0985e539ac2e96cc6 Launch Stack
ap-southeast-1 HVM (amd64) ami-04bd051e489962f56 Launch Stack
HVM (arm64) ami-0936ab431ba84686b Launch Stack
ap-southeast-2 HVM (amd64) ami-0ec5c4753f5f2cafb Launch Stack
HVM (arm64) ami-0d69847acd22c4892 Launch Stack
ap-southeast-3 HVM (amd64) ami-01263f021bbae0af0 Launch Stack
HVM (arm64) ami-0bcdd2229ef3184c6 Launch Stack
ca-central-1 HVM (amd64) ami-039c8ff48467d9949 Launch Stack
HVM (arm64) ami-0c6e8dc8c21a04222 Launch Stack
eu-central-1 HVM (amd64) ami-0162e00cd649bb28c Launch Stack
HVM (arm64) ami-0fb87660651fae27e Launch Stack
eu-north-1 HVM (amd64) ami-00de519bde83069d7 Launch Stack
HVM (arm64) ami-02cb549faf8ec87b4 Launch Stack
eu-south-1 HVM (amd64) ami-08ca5331ea9c9291c Launch Stack
HVM (arm64) ami-0c40e8024268d3d1d Launch Stack
eu-west-1 HVM (amd64) ami-0e4bc16977fd19689 Launch Stack
HVM (arm64) ami-03db5e46cb52b514a Launch Stack
eu-west-2 HVM (amd64) ami-0c4f5221dce88623d Launch Stack
HVM (arm64) ami-04a39d99c16fd5226 Launch Stack
eu-west-3 HVM (amd64) ami-0d39dfd745cf4f148 Launch Stack
HVM (arm64) ami-06b1a73dc07cd1dcf Launch Stack
sa-east-1 HVM (amd64) ami-0bab51422599627b5 Launch Stack
HVM (arm64) ami-0224c5d107d78dda9 Launch Stack
us-east-1 HVM (amd64) ami-0d621daa0dadf89f4 Launch Stack
HVM (arm64) ami-00222591f7c22751a Launch Stack
us-east-2 HVM (amd64) ami-0e4efd5cd133c87f3 Launch Stack
HVM (arm64) ami-03bf93fba32717276 Launch Stack
us-west-1 HVM (amd64) ami-0b6834685033dfba6 Launch Stack
HVM (arm64) ami-04f01f881b3ae6e55 Launch Stack
us-west-2 HVM (amd64) ami-0494ae13261eaf0cc Launch Stack
HVM (arm64) ami-0e5a89a21fe9313f6 Launch Stack

LTS release streams are maintained for an extended lifetime of 18 months. The yearly LTS streams have an overlap of 6 months. The current version is Flatcar Container Linux 4081.3.12.

View as json feed: amd64 arm64
EC2 Region AMI Type AMI ID CloudFormation
af-south-1 HVM (amd64) ami-05c7dad08473657eb Launch Stack
HVM (arm64) ami-09e7173f3466cab38 Launch Stack
ap-east-1 HVM (amd64) ami-0be573b183502c56e Launch Stack
HVM (arm64) ami-0ed2072bf26af65d9 Launch Stack
ap-east-2 HVM (amd64) ami-0588ecb5b20c7f006 Launch Stack
HVM (arm64) ami-008e4e2a11b5cdf4b Launch Stack
ap-northeast-1 HVM (amd64) ami-042e16ae885601400 Launch Stack
HVM (arm64) ami-0037c77578bea2582 Launch Stack
ap-northeast-2 HVM (amd64) ami-026047898a460e626 Launch Stack
HVM (arm64) ami-0fb69fa994391d04f Launch Stack
ap-south-1 HVM (amd64) ami-0d67944faba0d6334 Launch Stack
HVM (arm64) ami-04c7ba54cb4526670 Launch Stack
ap-south-2 HVM (amd64) ami-0ff32cd91ac850f2d Launch Stack
HVM (arm64) ami-0c0b07339004b1f03 Launch Stack
ap-southeast-1 HVM (amd64) ami-0fef36320a713314c Launch Stack
HVM (arm64) ami-0c7475652f2fd5d00 Launch Stack
ap-southeast-2 HVM (amd64) ami-00dbb4cd30a5f6e29 Launch Stack
HVM (arm64) ami-0d12804b3dea6b55d Launch Stack
ap-southeast-3 HVM (amd64) ami-0f01720e7699dc4a1 Launch Stack
HVM (arm64) ami-082d65a56d8d4e50f Launch Stack
ap-southeast-4 HVM (amd64) ami-0dc4c79b7e4078ca8 Launch Stack
HVM (arm64) ami-06c441a0cbe8fb845 Launch Stack
ap-southeast-5 HVM (amd64) ami-08a73b3ae59d9bc9e Launch Stack
HVM (arm64) ami-09128023f6f84644b Launch Stack
ap-southeast-6 HVM (amd64) ami-0f415c78b68d3e70f Launch Stack
HVM (arm64) ami-0dcb882ab54bfb7e8 Launch Stack
ap-southeast-7 HVM (amd64) ami-05607fbbb80d8862b Launch Stack
HVM (arm64) ami-0337821c23185eea1 Launch Stack
ca-central-1 HVM (amd64) ami-0efc520994159d8c2 Launch Stack
HVM (arm64) ami-0bef7e828aea6e5f4 Launch Stack
ca-west-1 HVM (amd64) ami-0897184fd86f517e2 Launch Stack
HVM (arm64) ami-0a4e8803cc613994c Launch Stack
eu-central-1 HVM (amd64) ami-071ee4b8bc2930f5b Launch Stack
HVM (arm64) ami-01c83f4a79ae61dd8 Launch Stack
eu-central-2 HVM (amd64) ami-07b964605bc0001aa Launch Stack
HVM (arm64) ami-00c26a930a91e81ad Launch Stack
eu-north-1 HVM (amd64) ami-0b93a8ff4a403d687 Launch Stack
HVM (arm64) ami-07473ec7223d65989 Launch Stack
eu-south-1 HVM (amd64) ami-0aed3b30470724aca Launch Stack
HVM (arm64) ami-0b2c1c728d0a149f5 Launch Stack
eu-south-2 HVM (amd64) ami-049d8df6097540f1b Launch Stack
HVM (arm64) ami-0f013c4e95ee6017f Launch Stack
eu-west-1 HVM (amd64) ami-03d018bc84a430069 Launch Stack
HVM (arm64) ami-04c4a276fb2c285d8 Launch Stack
eu-west-2 HVM (amd64) ami-06c1688b65ea28141 Launch Stack
HVM (arm64) ami-0c071f961f253c3e6 Launch Stack
eu-west-3 HVM (amd64) ami-0cc417faaa2063939 Launch Stack
HVM (arm64) ami-0d36f912ec64b55b9 Launch Stack
il-central-1 HVM (amd64) ami-004d2d5f7e981edf8 Launch Stack
HVM (arm64) ami-021345d750a2b8647 Launch Stack
mx-central-1 HVM (amd64) ami-0919337aa87c89e07 Launch Stack
HVM (arm64) ami-01841ed8437d902d8 Launch Stack
sa-east-1 HVM (amd64) ami-0d93f2e62d3fb2495 Launch Stack
HVM (arm64) ami-067b65ff5274d513d Launch Stack
us-east-1 HVM (amd64) ami-0ccab97d3dc47cdeb Launch Stack
HVM (arm64) ami-0d86c874f0fb5ae1a Launch Stack
us-east-2 HVM (amd64) ami-048f5f43a0dd395aa Launch Stack
HVM (arm64) ami-03333d0f14c28d70b Launch Stack
us-west-1 HVM (amd64) ami-09a83fb0ee2409ff8 Launch Stack
HVM (arm64) ami-02d08cfeaa26ff588 Launch Stack
us-west-2 HVM (amd64) ami-0702908be8960f47f Launch Stack
HVM (arm64) ami-05ac55ba07568a852 Launch Stack

Butane Configs

Flatcar Container Linux allows you to configure machine parameters, configure networking, launch systemd units on startup, and more via Butane Configs. These configs are then transpiled into Ignition configs and given to booting machines. Head over to the docs to learn about the supported features .

You can provide a raw Ignition JSON config to Flatcar Container Linux via the Amazon web console or via the EC2 API .

As an example, this Butane YAML config will start an NGINX Docker container:

variant: flatcar
version: 1.0.0
systemd:
  units:
    - name: nginx.service
      enabled: true
      contents: |
        [Unit]
        Description=NGINX example
        After=docker.service
        Requires=docker.service
        [Service]
        TimeoutStartSec=0
        ExecStartPre=-/usr/bin/docker rm --force nginx1
        ExecStart=/usr/bin/docker run --name nginx1 --pull always --log-driver=journald --net host docker.io/nginx:1
        ExecStop=/usr/bin/docker stop nginx1
        Restart=always
        RestartSec=5s
        [Install]
        WantedBy=multi-user.target

Transpile it to Ignition JSON:

cat cl.yaml | docker run --rm -i quay.io/coreos/butane:latest > ignition.json

Instance storage

Ephemeral disks and additional EBS volumes attached to instances can be mounted with a .mount unit. Amazon’s block storage devices are attached differently depending on the instance type . Here’s the Butane Config to format and mount the first ephemeral disk, xvdb, on most instance types:

variant: flatcar
version: 1.0.0
storage:
  filesystems:
    - device: /dev/xvdb
      format: ext4
      wipe_filesystem: true
      label: ephemeral
systemd:
  units:
    - name: media-ephemeral.mount
      enabled: true
      contents: |
        [Mount]
        What=/dev/disk/by-label/ephemeral
        Where=/media/ephemeral
        Type=ext4

        [Install]
        RequiredBy=local-fs.target

For more information about mounting storage, Amazon’s own documentation is the best source. You can also read about mounting storage on Flatcar Container Linux .

Adding more machines

To add more instances to the cluster, just launch more with the same Butane Config, the appropriate security group and the AMI for that region. New instances will join the cluster regardless of region if the security groups are configured correctly.

SSH to your instances

Flatcar Container Linux is set up to be a little more secure than other cloud images. By default, it uses the core user instead of root and doesn’t use a password for authentication. You’ll need to add an SSH key(s) via the AWS console or add keys/passwords via your Butane Config in order to log in.

To connect to an instance after it’s created, run:

ssh core@<ip address>

Multiple clusters

If you would like to create multiple clusters you will need to change the “Stack Name”. You can find the direct template file on S3 .

Manual setup

TL;DR: launch three instances of ami-0d621daa0dadf89f4 (amd64) in us-east-1 with a security group that has open port 22, 2379, 2380, 4001, and 7001 and the same “User Data” of each host. SSH uses the core user and you have etcd and Docker to play with.

Creating the security group

You need open port 2379, 2380, 7001 and 4001 between servers in the etcd cluster. Step by step instructions below.

Note: This step is only needed once

First we need to create a security group to allow Flatcar Container Linux instances to communicate with one another.

  1. Go to the security group page in the EC2 console.
  2. Click “Create Security Group”
    • Name: flatcar-testing
    • Description: Flatcar Container Linux instances
    • VPC: No VPC
    • Click: “Yes, Create”
  3. In the details of the security group, click the Inbound tab
  4. First, create a security group rule for SSH
    • Create a new rule: SSH
    • Source: 0.0.0.0/0
    • Click: “Add Rule”
  5. Add two security group rules for etcd communication
    • Create a new rule: Custom TCP rule
    • Port range: 2379
    • Source: type “flatcar-testing” until your security group auto-completes. Should be something like “sg-8d4feabc”
    • Click: “Add Rule”
    • Repeat this process for port range 2380, 4001 and 7001 as well
  6. Click “Apply Rule Changes”

Launching a test cluster

We will be launching three instances, with a few parameters in the User Data, and selecting our security group.

  • Open the quick launch wizard to boot: Alpha ami-0d621daa0dadf89f4 (amd64), Beta ami-06c70fc368daab3ec (amd64), or Stable ami-0d483f3bf93a02c94 (amd64)
  • On the second page of the wizard, launch 3 servers to test our clustering
    • Number of instances: 3, “Continue”
  • Paste your Ignition JSON config in the EC2 dashboard into the “User Data” field, “Continue”
  • Storage Configuration, “Continue”
  • Tags, “Continue”
  • Create Key Pair: Choose a key of your choice, it will be added in addition to the one in the gist, “Continue”
  • Choose one or more of your existing Security Groups: “flatcar-testing” as above, “Continue”
  • Launch!

Installation from a VMDK image

One of the possible ways of installation is to import the generated VMDK Flatcar image as a snapshot. The image file will be in https://${CHANNEL}.release.flatcar-linux.net/${ARCH}-usr/${VERSION}/flatcar_production_ami_vmdk_image.vmdk.bz2. Make sure you download the signature (it’s available in https://${CHANNEL}.release.flatcar-linux.net/${ARCH}-usr/${VERSION}/flatcar_production_ami_vmdk_image.vmdk.bz2.sig) and check it before proceeding.

$ wget https://alpha.release.flatcar-linux.net/amd64-usr/current/flatcar_production_ami_vmdk_image.vmdk.bz2
$ wget https://alpha.release.flatcar-linux.net/amd64-usr/current/flatcar_production_ami_vmdk_image.vmdk.bz2.sig
$ gpg --verify flatcar_production_ami_vmdk_image.vmdk.bz2.sig
gpg: assuming signed data in 'flatcar_production_ami_vmdk_image.vmdk.bz2'
gpg: Signature made Thu 15 Mar 2018 10:27:57 AM CET
gpg:                using RSA key A621F1DA96C93C639506832D603443A1D0FC498C
gpg: Good signature from "Flatcar Buildbot (Official Builds) <[email protected]>" [ultimate]

Then, follow the instructions in Importing a Disk as a Snapshot Using VM Import/Export . You’ll need to upload the uncompressed vmdk file to S3.

After the snapshot is imported, you can go to “Snapshots” in the EC2 dashboard, and generate an AMI image from it. To make it work, use /dev/sda2 as the “Root device name” and you probably want to select “Hardware-assisted virtualization” as “Virtualization type”.

Using Flatcar Container Linux

Now that you have a machine booted it is time to play around. Check out the Flatcar Container Linux Quickstart guide or dig into more specific topics .

Terraform

The aws Terraform Provider allows to deploy machines in a declarative way. Read more about using Terraform and Flatcar here .

The following Terraform v0.13 module may serve as a base for your own setup. It will also take care of registering your SSH key at AWS EC2 and managing the network environment with Terraform.

You can clone the setup from the Flatcar Terraform examples repository or create the files manually as we go through them and explain each one.

git clone https://github.com/flatcar/flatcar-terraform.git
# From here on you could directly run it, TLDR:
cd aws
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
terraform init
# Edit the server configs or just go ahead with the default example
terraform plan
terraform apply

Start with a aws-ec2-machines.tf file that contains the main declarations:

terraform {
  required_version = ">= 0.13"
  required_providers {
    ct = {
      source  = "poseidon/ct"
      version = "0.7.1"
    }
    template = {
      source  = "hashicorp/template"
      version = "~> 2.2.0"
    }
    null = {
      source  = "hashicorp/null"
      version = "~> 3.0.0"
    }
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.19.0"
    }
  }
}

provider "aws" {
  region = var.aws_region
}

resource "aws_vpc" "network" {
  cidr_block = var.vpc_cidr

  tags = {
    Name = var.cluster_name
  }
}

resource "aws_subnet" "subnet" {
  vpc_id     = aws_vpc.network.id
  cidr_block = var.subnet_cidr

  tags = {
    Name = var.cluster_name
  }
}

resource "aws_internet_gateway" "gateway" {
  vpc_id = aws_vpc.network.id

  tags = {
    Name = var.cluster_name
  }
}

resource "aws_route_table" "default" {
  vpc_id = aws_vpc.network.id

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.gateway.id
  }

  tags = {
    Name = var.cluster_name
  }
}

resource "aws_route_table_association" "public" {
  route_table_id = aws_route_table.default.id
  subnet_id      = aws_subnet.subnet.id
}

resource "aws_security_group" "securitygroup" {
  vpc_id = aws_vpc.network.id

  tags = {
    Name = var.cluster_name
  }
}

resource "aws_security_group_rule" "outgoing_any" {
  security_group_id = aws_security_group.securitygroup.id
  type              = "egress"
  from_port         = 0
  to_port           = 0
  protocol          = "-1"
  cidr_blocks       = ["0.0.0.0/0"]
}

resource "aws_security_group_rule" "incoming_any" {
  security_group_id = aws_security_group.securitygroup.id
  type              = "ingress"
  from_port         = 0
  to_port           = 0
  protocol          = "-1"
  cidr_blocks       = ["0.0.0.0/0"]
}

resource "aws_key_pair" "ssh" {
  key_name   = var.cluster_name
  public_key = var.ssh_keys.0
}

data "aws_ami" "flatcar_stable_latest" {
  most_recent = true
  owners      = ["aws-marketplace"]

  filter {
    name   = "architecture"
    values = ["x86_64"]
  }

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

  filter {
    name   = "name"
    values = ["Flatcar-stable-*"]
  }
}

resource "aws_instance" "machine" {
  for_each      = toset(var.machines)
  instance_type = var.instance_type
  user_data     = data.ct_config.machine-ignitions[each.key].rendered
  ami           = data.aws_ami.flatcar_stable_latest.image_id
  key_name      = aws_key_pair.ssh.key_name

  associate_public_ip_address = true
  subnet_id                   = aws_subnet.subnet.id
  vpc_security_group_ids      = [aws_security_group.securitygroup.id]

  tags = {
    Name = "${var.cluster_name}-${each.key}"
  }
}

data "ct_config" "machine-ignitions" {
  for_each = toset(var.machines)
  content  = data.template_file.machine-configs[each.key].rendered
}

data "template_file" "machine-configs" {
  for_each = toset(var.machines)
  template = file("${path.module}/cl/machine-${each.key}.yaml.tmpl")

  vars = {
    ssh_keys = jsonencode(var.ssh_keys)
    name     = each.key
  }
}

Create a variables.tf file that declares the variables used above:

variable "machines" {
  type        = list(string)
  description = "Machine names, corresponding to cl/machine-NAME.yaml.tmpl files"
}

variable "cluster_name" {
  type        = string
  description = "Cluster name used as prefix for the machine names"
}

variable "ssh_keys" {
  type        = list(string)
  description = "SSH public keys for user 'core'"
}

variable "aws_region" {
  type        = string
  default     = "us-east-2"
  description = "AWS Region to use for running the machine"
}

variable "instance_type" {
  type        = string
  default     = "t3.medium"
  description = "Instance type for the machine"
}

variable "vpc_cidr" {
  type    = string
  default = "172.16.0.0/16"
}

variable "subnet_cidr" {
  type    = string
  default = "172.16.10.0/24"
}

An outputs.tf file shows the resulting IP addresses:

output "ip-addresses" {
  value = {
    for key in var.machines :
    "${var.cluster_name}-${key}" => aws_instance.machine[key].public_ip
  }
}

Now you can use the module by declaring the variables and a Container Linux Configuration for a machine. First create a terraform.tfvars file with your settings:

cluster_name           = "mycluster"
machines               = ["mynode"]
ssh_keys               = ["ssh-rsa AA... [email protected]"]

The machine name listed in the machines variable is used to retrieve the corresponding Container Linux Config . For each machine in the list, you should have a machine-NAME.yaml.tmpl file with a corresponding name.

For example, create the configuration for mynode in the file machine-mynode.yaml.tmpl (The SSH key used there is not really necessary since we already set it as VM attribute):

---
passwd:
  users:
    - name: core
      ssh_authorized_keys:
        - ${ssh_keys}
storage:
  files:
    - path: /home/core/works
      filesystem: root
      mode: 0755
      contents:
        inline: |
          #!/bin/bash
          set -euo pipefail
           # This script demonstrates how templating and variable substitution works when using Terraform templates for Container Linux Configs.
          hostname="$(hostname)"
          echo My name is ${name} and the hostname is $${hostname}

Finally, run Terraform v0.13 as follows to create the machine:

export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
terraform init
terraform apply

Log in via ssh core@IPADDRESS with the printed IP address (maybe add -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null).

When you make a change to machine-mynode.yaml.tmpl and run terraform apply again, the machine will be replaced.

You can find this Terraform module in the repository for Flatcar Terraform examples .