@@ -78,6 +78,13 @@ func Provider() *schema.Provider {
78
78
Description : "AWS profile to use for IAM auth" ,
79
79
},
80
80
81
+ "aws_rds_iam_region" : {
82
+ Type : schema .TypeString ,
83
+ Optional : true ,
84
+ Default : "" ,
85
+ Description : "AWS region to use for IAM auth" ,
86
+ },
87
+
81
88
// Conection username can be different than database username with user name mapas (e.g.: in Azure)
82
89
// See https://www.postgresql.org/docs/current/auth-username-maps.html
83
90
"database_username" : {
@@ -179,7 +186,7 @@ func validateExpectedVersion(v interface{}, key string) (warnings []string, erro
179
186
return
180
187
}
181
188
182
- func getRDSAuthToken (profile string , username string , host string , port int ) (string , error ) {
189
+ func getRDSAuthToken (region string , profile string , username string , host string , port int ) (string , error ) {
183
190
endpoint := fmt .Sprintf ("%s:%d" , host , port )
184
191
185
192
ctx := context .Background ()
@@ -189,6 +196,8 @@ func getRDSAuthToken(profile string, username string, host string, port int) (st
189
196
190
197
if profile != "" {
191
198
awscfg , err = awsConfig .LoadDefaultConfig (ctx , awsConfig .WithSharedConfigProfile (profile ))
199
+ } else if region != "" {
200
+ awscfg , err = awsConfig .LoadDefaultConfig (ctx , awsConfig .WithRegion (region ))
192
201
} else {
193
202
awscfg , err = awsConfig .LoadDefaultConfig (ctx )
194
203
}
@@ -221,8 +230,9 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
221
230
var password string
222
231
if d .Get ("aws_rds_iam_auth" ).(bool ) {
223
232
profile := d .Get ("aws_rds_iam_profile" ).(string )
233
+ region := d .Get ("aws_rds_iam_region" ).(string )
224
234
var err error
225
- password , err = getRDSAuthToken (profile , username , host , port )
235
+ password , err = getRDSAuthToken (region , profile , username , host , port )
226
236
if err != nil {
227
237
return nil , err
228
238
}
0 commit comments