Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra connection host with default value as host #489

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion postgresql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ type ClientCertificateConfig struct {
type Config struct {
Scheme string
Host string
ConnectionHost string
Port int
Username string
Password string
Expand Down Expand Up @@ -248,7 +249,10 @@ func (c *Config) connParams() []string {
}

func (c *Config) connStr(database string) string {
host := c.Host
host := c.ConnectionHost
if host == "" {
host = c.Host
}
// For GCP, support both project/region/instance and project:region:instance
// (The second one allows to use the output of google_sql_database_instance as host
if c.Scheme == "gcppostgres" {
Expand Down
15 changes: 14 additions & 1 deletion postgresql/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package postgresql
import (
"context"
"fmt"
"os"

"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/sts"
"os"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
Expand Down Expand Up @@ -40,6 +41,12 @@ func Provider() *schema.Provider {
}, false),
},
"host": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("PGHOST", nil),
Description: "Name of PostgreSQL server address",
},
"connection_host": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("PGHOST", nil),
Expand Down Expand Up @@ -343,6 +350,11 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
port := d.Get("port").(int)
username := d.Get("username").(string)

connectionHost := d.Get("connection_host").(string)
if connectionHost == "" {
connectionHost = host
}

var password string
if d.Get("aws_rds_iam_auth").(bool) {
profile := d.Get("aws_rds_iam_profile").(string)
Expand Down Expand Up @@ -370,6 +382,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
Scheme: d.Get("scheme").(string),
Host: host,
ConnectionHost: connectionHost,
Port: port,
Username: username,
Password: password,
Expand Down
Loading