resource "docker_image" "postgres" { name = "postgres:9.6" keep_locally = true } resource "docker_image" "keycloak" { name = "jboss/keycloak-postgres" keep_locally = true } resource "docker_container" "postgres" { name = "postgres" image = "${docker_image.postgres.latest}" ports { internal = 5432 external = 5432 } env = [ "POSTGRES_PASSWORD=${var.postgres_password}", "POSTGRES_USER=${var.postgres_user}", "PGDATA=/postgres_data", ] volumes { container_path = "/postgres_data" host_path = "${path.module}/postgres_data" } } resource "docker_container" "keycloak" { name = "keycloak" image = "${docker_image.keycloak.latest}" ports { internal = 8080 external = 8080 } links = [ "${docker_container.postgres.name}", ] env = [ "POSTGRES_DATABASE=local", "POSTGRES_PORT_5432_TCP_ADDR=${docker_container.postgres.name}", "KEYCLOAK_USER=local", ] } provider "postgresql" { host = "172.18.5.3" port = 5432 database = "postgres" username = "${var.postgres_user}" password = "${var.postgres_password}" sslmode = "disable" connect_timeout = 15 } resource "postgresql_database" "mydb" { name = "mydb" connection_limit = -1 allow_connections = true }