carlessanagustin
9/23/2015 - 11:07 AM

HashiCorp Terraform AWS and DOCKER up-n-running

HashiCorp Terraform AWS and DOCKER up-n-running

variable "access_key" {
    default = "lalalalalalalalalala"
}
variable "secret_key" {
    default = "lalalalalalalalalala"
}
############ AWS ############

provider "aws" {
    access_key = "${var.access_key}"
    secret_key = "${var.secret_key}"
#    access_key = "lalalalalalalalalala"
#    secret_key = "lalalalalalalalalala"
    region = "us-east-1"
}

resource "aws_instance" "example1" {
    ami = "ami-d05e75b8"
    instance_type = "t2.micro"

    subnet_id = "subnet-XXXXX"
    security_groups = ["sg-XXXXX"]
    private_ip = "10.0.0.10"

    tags {
        Name = "example1"
        Description = "Ubuntu Server 14.04 LTS (HVM), SSD Volume Type"
        SO = "Ubuntu"
        Usage = "testing"
        Unit = "1"
    }
}

output "example1_ip" {
    value = "${aws_instance.example1.public_ip}"
}

# to retrieve output information...
# $ terraform output example1_ip

############ DOCKER ############

# example command...
# $ docker run 
# --name some-nginx
# -v /vagrant:/usr/share/nginx/html:ro
# -p 8080:80
# -d nginx

resource "docker_image" "nginx" {
    name = "nginx:latest"
}

resource "docker_container" "example4" {
    image = "${docker_image.nginx.latest}"
    name = "example4"
    hostname = "some-nginx"
    volumes {
        container_path = "/usr/share/nginx/html"
        host_path = "/vagrant"
        read_only = "true"
    }
    ports {
        internal = 80
        external = 8080
    }
}