main.tf 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. resource "docker_image" "postgres" {
  2. name = "postgres:9.6"
  3. keep_locally = true
  4. }
  5. resource "docker_image" "keycloak" {
  6. name = "jboss/keycloak-postgres"
  7. keep_locally = true
  8. }
  9. resource "docker_container" "postgres" {
  10. name = "postgres"
  11. image = "${docker_image.postgres.latest}"
  12. ports {
  13. internal = 5432
  14. external = 5432
  15. }
  16. env = [
  17. "POSTGRES_PASSWORD=${var.postgres_password}",
  18. "POSTGRES_USER=${var.postgres_user}",
  19. "PGDATA=/postgres_data",
  20. ]
  21. volumes {
  22. container_path = "/postgres_data"
  23. host_path = "${path.module}/postgres_data"
  24. }
  25. }
  26. resource "docker_container" "keycloak" {
  27. name = "keycloak"
  28. image = "${docker_image.keycloak.latest}"
  29. ports {
  30. internal = 8080
  31. external = 8080
  32. }
  33. links = [
  34. "${docker_container.postgres.name}",
  35. ]
  36. env = [
  37. "POSTGRES_DATABASE=local",
  38. "POSTGRES_PORT_5432_TCP_ADDR=${docker_container.postgres.name}",
  39. "KEYCLOAK_USER=local",
  40. ]
  41. }
  42. provider "postgresql" {
  43. host = "172.18.5.3"
  44. port = 5432
  45. database = "postgres"
  46. username = "${var.postgres_user}"
  47. password = "${var.postgres_password}"
  48. sslmode = "disable"
  49. connect_timeout = 15
  50. }
  51. resource "postgresql_database" "mydb" {
  52. name = "mydb"
  53. connection_limit = -1
  54. allow_connections = true
  55. }