Skip to content

Commit

Permalink
Fix brainly#113 Allow setting of a AWS profile when creating the SDK …
Browse files Browse the repository at this point in the history
…config
  • Loading branch information
pwhittlesea committed Jul 21, 2023
1 parent 785455d commit bea48b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Optional:
- **db_groups** (Set of String) A list of the names of existing database groups that the user will join for the current session, in addition to any group memberships for an existing user. If not specified, a new user is added only to PUBLIC.
- **duration_seconds** (Number) The number of seconds until the returned temporary password expires.
- **region** (String) The AWS region where the Redshift cluster is located.
- **profile** (String) The AWS profile to use when requesting temporary credentials.

<a id="nestedblock--temporary_credentials--assume_role"></a>
### Nested Schema for `temporary_credentials.assume_role`
Expand Down
13 changes: 12 additions & 1 deletion redshift/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func Provider() *schema.Provider {
Optional: true,
Description: "The AWS region where the Redshift cluster is located.",
},
"profile": {
Type: schema.TypeString,
Optional: true,
Description: "The AWS profile to use when requesting temporary credentials.",
},
"auto_create_user": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -232,7 +237,13 @@ func temporaryCredentials(username string, d *schema.ResourceData) (string, stri
}

func redshiftSdkClient(d *schema.ResourceData) (*redshift.Client, error) {
cfg, err := config.LoadDefaultConfig(context.TODO())
loadOptions := []func(*config.LoadOptions) error{}

if profile := d.Get("temporary_credentials.0.profile").(string); profile != "" {
loadOptions = append(loadOptions, config.WithSharedConfigProfile(profile))
}

cfg, err := config.LoadDefaultConfig(context.TODO(), loadOptions...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit bea48b2

Please sign in to comment.