Quick snippet of the code to create node and spawn up docker container on it
resource "aws_instance" "docker" {
connection {
user = "ubuntu"
key_file = "${lookup(var.key_path, var.aws_region)}"
}
count = "${var.docker_instance_count}"
ami = "${lookup(var.aws_amis, var.aws_region)}"
instance_type = "${var.instance_type}"
key_name = "${lookup(var.key_name, var.aws_region)}"
security_groups = ["${aws_security_group.composable.name}"]
tags {
realm = "experimental"
purpose = "docker-container"
created-by = "Terraform"
}
}
provider "docker" {
host = "tcp://${aws_instance.docker.public_ip}:2375/"
}
resource "docker_image" "nginx" {
image = "nginx"
keep_updated = true
}
resource "docker_container" "nginx" {
image = "${docker_image.nginx.latest}"
name = "nginx"
hostname = "nginx"
must_run = true
ports {
internal = 80
external = 80
}
}