GoogleCloudPlatform / cloud-sql-go-connector

A Go library for connecting securely to your Cloud SQL instances
Apache License 2.0
109 stars 29 forks source link

feat: Support configure connections using DNS #843

Closed hessjcg closed 1 month ago

hessjcg commented 2 months ago

The dialer may be configured to use a DNS name to look up the instance name instead of configuring the connector with the instance name directly.

Add a DNS TXT record for the Cloud SQL instance to a private DNS server or a private Google Cloud DNS Zone used by your application. For example:

Configure the dialer with the cloudsqlconn.WithDNSResolver() option.

Open a database connection using the DNS name:

db, err := sql.Open(
    "cloudsql-mysql",
    "myuser:mypass@cloudsql-mysql(prod-db.mycompany.example.com)/mydb",
)

Part of #842