farmer
farmer copied to clipboard
Capturing the host name of a postgresql instance.
If this is not the appropriate place for questions, let me know where I should post them :).
How do I go about creating a setting my myApp
that contains my database's hostname/endpoint?
I notice that this is done in the COSMOS-BACKED WEB APP tutorial.
let pgDb = postgreSQL {
name "dbName"
admin_username "dbAdmin"
add_database "db"
}
let myApp = webApp {
name "myApp"
depends_on pgDb
setting "DB_NAME" pgDb.Databases.Head.Name
setting "DB_USER" pgDb.AdministratorCredentials.UserName
setting "DB_PASSWORD" pgDb.AdministratorCredentials.Password.Value
// I'd like to do something like the following:
setting "DB_HOST" pgDb.Endpoint
}
Would this be possible? Thanks for any and all information.
It is possible to reference properties of the newly provisioned Postgres resource and pass them to your webapp by creating a reference to that resource and then retrieving properties from that reference. We usually try to bake those into the builders themselves to simplify your code, but if one is not there, something like the following should work as a stop gap.
// ID of the database itself
let dbId = Farmer.Arm.DBforPostgreSQL.databases.resourceId(ResourceName "dbserver", ResourceName "db")
// Using that ID, generate an ARM expression for the 'name' property
let dbName = ArmExpression.create($"reference({dbId.ArmExpression.Value}).name").Eval()
// Then you can use that expression in your webApp settings:
setting "DB_NAME" dbName
Does that do what you need?
@kurt-mueller-osumc can you please review #1020 that adds a FullyQualifiedDomainName
member? This serves the same purpose as Endpoint
in the other resource, but it matches with the property name used in the docs for the Postgres resource.
@kurt-mueller-osumc the fix is available in the 1.7.19 release now available on nuget.
Awesome, thanks for your help on this. I'll have to check this out soon :).