From bea48b2027fa6cb4e4f1d5cbcd401e7b49e4ad33 Mon Sep 17 00:00:00 2001 From: Phillip Whittlesea-Clark Date: Fri, 21 Jul 2023 10:46:14 +0100 Subject: [PATCH] Fix #113 Allow setting of a AWS profile when creating the SDK config --- docs/index.md | 1 + redshift/provider.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 79f59aa..2ed43c4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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. ### Nested Schema for `temporary_credentials.assume_role` diff --git a/redshift/provider.go b/redshift/provider.go index b9a1c87..c39b15e 100644 --- a/redshift/provider.go +++ b/redshift/provider.go @@ -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, @@ -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 }