Created
January 6, 2019 16:36
-
-
Save picatz/28b4643e0e163ea01ea043a8e58c3ed3 to your computer and use it in GitHub Desktop.
A consul development server example using terraform and docker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find consul image. | |
resource "docker_image" "consul" { | |
name = "consul" | |
} | |
# Basically doing the following command: | |
# docker run -d --name=consul-server-1 -p 8500:8500 consul agent -dev -client=0.0.0.0 -bind=0.0.0.0 | |
resource "docker_container" "consul-bootstrap-server" { | |
count = 1 | |
name = "consul-server-1" | |
image = "${docker_image.consul.latest}" | |
command = ["consul", "agent", "-dev", "-client=0.0.0.0", "-bind=0.0.0.0"] | |
ports { | |
internal = 8500 | |
external = 8500 | |
} | |
} | |
# Basically doing the following commands: | |
# IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' c1); echo $IP | |
# docker run -d --name consul-server-2 consul agent -dev -bind=0.0.0.0 -join=$IP | |
# docker run -d --name consul-server-3 consul agent -dev -bind=0.0.0.0 -join=$IP | |
resource "docker_container" "other-consul-servers" { | |
depends_on = ["docker_container.consul-bootstrap-server"] | |
count = 2 | |
name = "consul-server-${count.index+2}" | |
image = "${docker_image.consul.latest}" | |
command = ["consul", "agent", "-dev", "-bind=0.0.0.0", "-join=${docker_container.consul-bootstrap-server.ip_address}"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment