some-waitress-78905
01/15/2019, 2:43 AMundefined
?
let greetingFunction = new gcpFunction.HttpFunction(
"greeting",
postgraphile(
{
user: process.env.DB_USERNAME,
host: `/cloudsql/${process.env.CONNECTION_NAME}`,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
port: 5432,
},
{
graphiql: true,
}
),
{},
// pass params into function as env vars
{
CONNECTION_NAME: sql.instance.connectionName,
DB_USERNAME: sql.user.name,
DB_PASSWORD: sql.user.password,
DB_NAME: sql.database.name
}
);
running that returns the following error:
Error: connect ENOENT /cloudsql/undefined/.s.PGSQL.5432
Error: connect ENOENT /cloudsql/engaged-arcanum-197821:us-central1:fleetgrid-sql-ff25239/.s.PGSQL.5432
white-balloon-205
some-waitress-78905
01/15/2019, 5:13 AMimport * as gcp from "@pulumi/gcp"
import * as config from "./config"
import * as pulumi from "@pulumi/pulumi"
// Provision a database instance for our node.js app.
export const instance = new gcp.sql.DatabaseInstance("fleetgrid-sql", {
databaseVersion: "POSTGRES_9_6",
settings: {
tier: "db-f1-micro",
ipConfiguration: {
authorizedNetworks: [{ value: "0.0.0.0/0" }],
},
},
});
// Create a user with the configured credentials for the node.js app to use.
export const user = new gcp.sql.User("fleetgrid-sql-user", {
instance: instance.name,
name: config.dbUsername,
password: config.dbPassword,
});
// Create a database for our node.js app.
export const database = new gcp.sql.Database("fleetgrid-sql-database", {
instance: instance.name,
name: config.dbName
});
// export const host = pulumi
// .all([ instance.connectionName ])
// .apply(
// ([ name ]) => {
// return `/cloudsql/${name}`
// }
// )
export const host = instance.connectionName.apply(x => `/cloudsql/${x}`)
import * as config from "./config"
import * as sql from "./sql"
import * as gcpFunction from "./gcpFunction"
import * as pulumi from "@pulumi/pulumi"
import postgraphile from 'postgraphile'
// API from /cloudsql/engaged-arcanum-197821:us-central1:fleetgrid-sql-ff25239!
// let apiFunction = new gcpFunction.HttpFunction("api", (req, res) => {
// res.send(`API from ${process.env.PG_HOST}!!!`);
// }, {}, {
// PG_HOST: sql.host,
// });
// `postgres://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@/cloudsql/${process.env.CONNECTION_NAME}/.s.PGSQL.5432/${process.env.DB_NAME}`
let apiFunction = new gcpFunction.HttpFunction(
"api",
postgraphile(
{
user: process.env.PG_USER,
host: '/cloudsql/engaged-arcanum-197821:us-central1:fleetgrid-sql-ff25239', // process.env.PG_HOST,
database: process.env.PG_DATABASE,
password: process.env.PG_PASSWORD,
port: 5432,
},
{
graphiql: true,
}
),
{},
// pass params into function as env vars
{
PG_HOST: sql.host,
PG_USER: sql.user.name,
PG_PASSWORD: sql.user.password,
PG_DATABASE: sql.database.name
}
);
export let url = apiFunction.httpsTriggerUrl;
let apiFunction = new gcpFunction.HttpFunction(
"api",
postgraphile(
'<postgres://fleetgrid:ELa8ETvv32wcjH@35.224.119.123:5432/fleetgrid>', // process.env.CONNECTION_STRING,
'fg',
{
// graphqlRoute: '/',
graphiql: true,
}
),
{},
{
CONNECTION_STRING: sql.connectionString,
}
);
if I try to use the env variable instead of hard coded string by using it like this... process.env.CONNECTION_STRING
then I get this error:
Error: connect ECONNREFUSED 127.0.0.1:5432
Any idea why variables being passed in aren't working?
here is what sql.connection looks like:
export const connectionString = pulumi
.all([ user.name, user.password, instance.ipAddresses, database.name ])
.apply(
([ name, password, host, database ]) => {
return `postgres://${name}:${password}@${host[0].ipAddress}:5432/${database}`
}
)