-
Notifications
You must be signed in to change notification settings - Fork 79
can't run postgresql with docker #28
Comments
This is essentially the same issue as #2 which boils down to an upstream issue. |
@wolf31o2 there are several reasons why this explanationMixing providers in one Things I noticed:
solution
tree ✔ 1757
.
├── mod_docker
│ └── main.tf
├── mod_postgres
│ └── main.tf
├── root.tf With the following contents:
module "docker" {
source = "mod_docker"
name = "postgres"
}
module "postgres" {
source = "mod_postgres"
name = "postgres"
}
variable "name" {
default = "postgres"
}
provider "docker" {
host = "unix:///var/run/docker.sock"
}
resource "docker_image" "postgres" {
name = "postgres:latest"
}
resource "docker_container" "postgres" {
image = "${docker_image.postgres.latest}"
name = "${var.name}"
restart = "always"
hostname = "${var.name}"
ports = {
internal = "5432"
external = "5432"
}
}
variable "name" {
default = "postgres"
}
provider "postgresql" {
alias = "pg1"
# host = "${var.name}" // will not work because 'postgres' is only resolved within the docker dns
host = "localhost"
port = 5432
username = "postgres"
password = ""
sslmode = "disable"
connect_timeout = 15
}
resource "postgresql_database" "mutualfunds" {
provider = "postgresql.pg1"
name = "mutualfunds"
}
Then call the modules in the right order from the terraform init
terraform apply -target=module.docker
terraform apply -target=module.postgres Eh voilà, there is your setup: psql -h localhost -p5432 -U postgres
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+------------+------------+-----------------------
mutualfunds | postgres | UTF8 | C | C |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows) HTH |
I'm not the OP. 🙂 |
True :) My bad => //ping @sugizo |
As mentioned: duplicate of #2 and closing due to inactivity. |
Terraform Version
Terraform Configuration Files
Expected Behavior
postgresql can run alongside with docker and create new database name testnewdb
Actual Behavior
docker with postgresql image is not downloaded or running and receive an error during
./terraform plan
using configuration
host = "localhost"
error
using configuration
host = "${docker_container.postgres.name}"
error
Steps to Reproduce
The text was updated successfully, but these errors were encountered: