Chris Mague 8 năm trước cách đây
mục cha
commit
970a90caec
2 tập tin đã thay đổi với 32 bổ sung1 xóa
  1. 23 1
      main.tf
  2. 9 0
      variables.tf

+ 23 - 1
main.tf

@@ -12,8 +12,14 @@ resource "docker_container" "postgres" {
   name  = "postgres"
   image = "${docker_image.postgres.latest}"
 
+  ports {
+    internal = 5432
+    external = 5432
+  }
+
   env = [
-    "POSTGRES_PASSWORD=winning",
+    "POSTGRES_PASSWORD=${var.postgres_password}",
+    "POSTGRES_USER=${var.postgres_user}",
     "PGDATA=/postgres_data",
   ]
 
@@ -42,3 +48,19 @@ resource "docker_container" "keycloak" {
     "KEYCLOAK_USER=local",
   ]
 }
+
+provider "postgresql" {
+  host            = "127.0.0.1"
+  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
+}

+ 9 - 0
variables.tf

@@ -0,0 +1,9 @@
+variable "postgres_user" {
+  description = "The Postgres user we want"
+  default     = "psqltest"
+}
+
+variable "postgres_password" {
+  description = "The Postgres password we want"
+  default     = "psqltest"
+}