Skip to content

Instantly share code, notes, and snippets.

@OlegGorj
Created March 20, 2018 23:07
Show Gist options
  • Save OlegGorj/45f69c6acccc1dc252fce1ec4f1ae5ff to your computer and use it in GitHub Desktop.
Save OlegGorj/45f69c6acccc1dc252fce1ec4f1ae5ff to your computer and use it in GitHub Desktop.

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
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment