Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 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
AWSIAMDBAuthTokenHost string
Port int
Username string
Password string
Expand Down Expand Up @@ -248,7 +249,7 @@ func (c *Config) connParams() []string {
}

func (c *Config) connStr(database string) string {
host := c.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
20 changes: 17 additions & 3 deletions 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 @@ -43,7 +44,7 @@ func Provider() *schema.Provider {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("PGHOST", nil),
Description: "Name of PostgreSQL server address to connect to",
Description: "Name of PostgreSQL server address",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would revert this change, I feel "to connect to" is useful in distinguishing the difference between the options

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

},
"port": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -99,6 +100,13 @@ func Provider() *schema.Provider {
Description: "AWS IAM role to assume for IAM auth",
},

"aws_rds_iam_token_host": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("PGHOST", nil),
Description: "Name of PostgreSQL server address for AWS RDS IAM to get token",
},

"azure_identity_auth": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -345,11 +353,16 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {

var password string
if d.Get("aws_rds_iam_auth").(bool) {
awsIAMTokenHost := d.Get("aws_rds_iam_token_host").(string)
if awsIAMTokenHost == "" {
awsIAMTokenHost = host
}

profile := d.Get("aws_rds_iam_profile").(string)
region := d.Get("aws_rds_iam_region").(string)
role := d.Get("aws_rds_iam_provider_role_arn").(string)
var err error
password, err = getRDSAuthToken(region, profile, role, username, host, port)
password, err = getRDSAuthToken(region, profile, role, username, awsIAMTokenHost, port)
if err != nil {
return nil, err
}
Expand All @@ -370,6 +383,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
Scheme: d.Get("scheme").(string),
Host: host,
AWSIAMDBAuthTokenHost: awsIAMTokenHost,
Port: port,
Username: username,
Password: password,
Expand Down