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

r/sagemaker_domain - add GenAI block #37139

Merged
merged 4 commits into from
Jun 24, 2024
Merged
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
7 changes: 7 additions & 0 deletions .changelog/37139.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_sagemaker_domain: Add `default_user_settings.canvas_app_settings.generative_ai_settings` configuration block
```

```release-note:enhancement
resource/aws_sagemaker_user_profile: Add `user_settings.canvas_app_settings.generative_ai_settings` configuration block
```
46 changes: 46 additions & 0 deletions internal/service/sagemaker/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@ func ResourceDomain() *schema.Resource {
},
},
},
"generative_ai_settings": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"amazon_bedrock_role_arn": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidARN,
},
},
},
},
"identity_provider_oauth_settings": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1623,6 +1637,9 @@ func expandCanvasAppSettings(l []interface{}) *sagemaker.CanvasAppSettings {
if v, ok := m["direct_deploy_settings"].([]interface{}); ok {
config.DirectDeploySettings = expandDirectDeploySettings(v)
}
if v, ok := m["generative_ai_settings"].([]interface{}); ok {
config.GenerativeAiSettings = expandGenerativeAiSettings(v)
}
if v, ok := m["identity_provider_oauth_settings"].([]interface{}); ok {
config.IdentityProviderOAuthSettings = expandIdentityProviderOAuthSettings(v)
}
Expand Down Expand Up @@ -1674,6 +1691,22 @@ func expandDirectDeploySettings(l []interface{}) *sagemaker.DirectDeploySettings
return config
}

func expandGenerativeAiSettings(l []interface{}) *sagemaker.GenerativeAiSettings {
if len(l) == 0 || l[0] == nil {
return nil
}

m := l[0].(map[string]interface{})

config := &sagemaker.GenerativeAiSettings{}

if v, ok := m["amazon_bedrock_role_arn"].(string); ok && v != "" {
config.AmazonBedrockRoleArn = aws.String(v)
}

return config
}

func expandIdentityProviderOAuthSettings(l []interface{}) []*sagemaker.IdentityProviderOAuthSetting {
providers := make([]*sagemaker.IdentityProviderOAuthSetting, 0, len(l))

Expand Down Expand Up @@ -2104,6 +2137,7 @@ func flattenCanvasAppSettings(config *sagemaker.CanvasAppSettings) []map[string]

m := map[string]interface{}{
"direct_deploy_settings": flattenDirectDeploySettings(config.DirectDeploySettings),
"generative_ai_settings": flattenGenerativeAiSettings(config.GenerativeAiSettings),
"identity_provider_oauth_settings": flattenIdentityProviderOAuthSettings(config.IdentityProviderOAuthSettings),
"kendra_settings": flattenKendraSettings(config.KendraSettings),
"time_series_forecasting_settings": flattenTimeSeriesForecastingSettings(config.TimeSeriesForecastingSettings),
Expand All @@ -2126,6 +2160,18 @@ func flattenDirectDeploySettings(config *sagemaker.DirectDeploySettings) []map[s
return []map[string]interface{}{m}
}

func flattenGenerativeAiSettings(config *sagemaker.GenerativeAiSettings) []map[string]interface{} {
if config == nil {
return []map[string]interface{}{}
}

m := map[string]interface{}{
"amazon_bedrock_role_arn": aws.StringValue(config.AmazonBedrockRoleArn),
}

return []map[string]interface{}{m}
}

func flattenKendraSettings(config *sagemaker.KendraSettings) []map[string]interface{} {
if config == nil {
return []map[string]interface{}{}
Expand Down
57 changes: 57 additions & 0 deletions internal/service/sagemaker/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,38 @@ func testAccDomain_modelRegisterSettings(t *testing.T) {
})
}

func testAccDomain_generativeAiSettings(t *testing.T) {
ctx := acctest.Context(t)
var domain sagemaker.DescribeDomainOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_sagemaker_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.SageMakerServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccDomainConfig_generativeAiSettings(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName, &domain),
resource.TestCheckResourceAttr(resourceName, "default_user_settings.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "default_user_settings.0.canvas_app_settings.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "default_user_settings.0.canvas_app_settings.0.generative_ai_settings.#", acctest.Ct1),
resource.TestCheckResourceAttrPair(resourceName, "default_user_settings.0.canvas_app_settings.0.generative_ai_settings.0.amazon_bedrock_role_arn", "aws_iam_role.test", names.AttrARN),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_policy"},
},
},
})
}

func testAccDomain_kendraSettings(t *testing.T) {
ctx := acctest.Context(t)
var domain sagemaker.DescribeDomainOutput
Expand Down Expand Up @@ -1543,6 +1575,31 @@ resource "aws_sagemaker_domain" "test" {
`, rName))
}

func testAccDomainConfig_generativeAiSettings(rName string) string {
return acctest.ConfigCompose(testAccDomainConfig_base(rName), fmt.Sprintf(`
resource "aws_sagemaker_domain" "test" {
domain_name = %[1]q
auth_mode = "IAM"
vpc_id = aws_vpc.test.id
subnet_ids = aws_subnet.test[*].id

default_user_settings {
execution_role = aws_iam_role.test.arn

canvas_app_settings {
generative_ai_settings {
amazon_bedrock_role_arn = aws_iam_role.test.arn
}
}
}

retention_policy {
home_efs_file_system = "Delete"
}
}
`, rName))
}

func testAccDomainConfig_kendraSettings(rName string) string {
return acctest.ConfigCompose(testAccDomainConfig_base(rName), fmt.Sprintf(`
resource "aws_sagemaker_domain" "test" {
Expand Down
1 change: 1 addition & 0 deletions internal/service/sagemaker/sagemaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestAccSageMaker_serial(t *testing.T) {
"defaultUserSettingsUpdated": testAccDomain_defaultUserSettingsUpdated,
"canvas": testAccDomain_canvasAppSettings,
"modelRegisterSettings": testAccDomain_modelRegisterSettings,
"generativeAi": testAccDomain_generativeAiSettings,
"identityProviderOauthSettings": testAccDomain_identityProviderOAuthSettings,
"directDeploySettings": testAccDomain_directDeploySettings,
"kendraSettings": testAccDomain_kendraSettings,
Expand Down
14 changes: 14 additions & 0 deletions internal/service/sagemaker/user_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ func ResourceUserProfile() *schema.Resource {
},
},
},
"generative_ai_settings": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"amazon_bedrock_role_arn": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidARN,
},
},
},
},
"identity_provider_oauth_settings": {
Type: schema.TypeList,
Optional: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ The following arguments are optional:
#### `canvas_app_settings` Block

* `direct_deploy_settings` - (Optional) The model deployment settings for the SageMaker Canvas application. See [`direct_deploy_settings` Block](#direct_deploy_settings-block) below.
* `generative_ai_settings` - (Optional) The generative AI settings for the SageMaker Canvas application. See [`generative_ai_settings` Block](#generative_ai_settings-block) below.
* `identity_provider_oauth_settings` - (Optional) The settings for connecting to an external data source with OAuth. See [`identity_provider_oauth_settings` Block](#identity_provider_oauth_settings-block) below.
* `kendra_settings` - (Optional) The settings for document querying. See [`kendra_settings` Block](#kendra_settings-block) below.
* `model_register_settings` - (Optional) The model registry settings for the SageMaker Canvas application. See [`model_register_settings` Block](#model_register_settings-block) below.
Expand All @@ -199,7 +200,11 @@ The following arguments are optional:

##### `direct_deploy_settings` Block

* `status` - (Optional)Describes whether model deployment permissions are enabled or disabled in the Canvas application. Valid values are `ENABLED` and `DISABLED`.
* `status` - (Optional) Describes whether model deployment permissions are enabled or disabled in the Canvas application. Valid values are `ENABLED` and `DISABLED`.

##### `generative_ai_settings` Block

* `amazon_bedrock_role_arn` - (Optional) The ARN of an Amazon Web Services IAM role that allows fine-tuning of large language models (LLMs) in Amazon Bedrock. The IAM role should have Amazon S3 read and write permissions, as well as a trust relationship that establishes bedrock.amazonaws.com as a service principal.

##### `kendra_settings` Block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ This resource supports the following arguments:
#### canvas_app_settings

* `direct_deploy_settings` - (Optional)The model deployment settings for the SageMaker Canvas application. See [Direct Deploy Settings](#direct_deploy_settings) below.
* `generative_ai_settings` - (Optional) The generative AI settings for the SageMaker Canvas application. See [Generative AI Settings](#generative_ai_settings) below.
* `identity_provider_oauth_settings` - (Optional) The settings for connecting to an external data source with OAuth. See [Identity Provider OAuth Settings](#identity_provider_oauth_settings) below.
* `kendra_settings` - (Optional) The settings for document querying. See [Kendra Settings](#kendra_settings) below.
* `model_register_settings` - (Optional) The model registry settings for the SageMaker Canvas application. See [Model Register Settings](#model_register_settings) below.
Expand All @@ -159,7 +160,11 @@ This resource supports the following arguments:

##### direct_deploy_settings

* `status` - (Optional)Describes whether model deployment permissions are enabled or disabled in the Canvas application. Valid values are `ENABLED` and `DISABLED`.
* `status` - (Optional) Describes whether model deployment permissions are enabled or disabled in the Canvas application. Valid values are `ENABLED` and `DISABLED`.

##### generative_ai_settings

* `amazon_bedrock_role_arn` - (Optional) The ARN of an Amazon Web Services IAM role that allows fine-tuning of large language models (LLMs) in Amazon Bedrock. The IAM role should have Amazon S3 read and write permissions, as well as a trust relationship that establishes bedrock.amazonaws.com as a service principal.

##### kendra_settings

Expand Down
Loading