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

resource/aws_sagemaker_workteam: Fix workforce_name: WorkforceName is misconfigured as Required. #39630

Merged
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
3 changes: 3 additions & 0 deletions .changelog/39630.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_sagemaker_workteam: Mark `workforce_name` as Optional
```
1 change: 1 addition & 0 deletions internal/service/sagemaker/sagemaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func TestAccSageMaker_serial(t *testing.T) {
acctest.CtDisappears: testAccWorkteam_disappears,
"tags": testAccWorkteam_tags,
"CognitoConfig": testAccWorkteam_cognitoConfig,
"CognitoOmitWorkforceName": testAccWorkteam_cognitoOmitWorkforceName,
"NotificationConfig": testAccWorkteam_notificationConfig,
"WorkerAccessConfiguration": testAccWorkteam_workerAccessConfiguration,
"OidcConfig": testAccWorkteam_oidcConfig,
Expand Down
9 changes: 5 additions & 4 deletions internal/service/sagemaker/workteam.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func resourceWorkteam() *schema.Resource {
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"workforce_name": {
Type: schema.TypeString,
Required: true,
Optional: true,
ForceNew: true,
},
"workteam_name": {
Expand All @@ -191,7 +191,6 @@ func resourceWorkteamCreate(ctx context.Context, d *schema.ResourceData, meta in
name := d.Get("workteam_name").(string)
input := &sagemaker.CreateWorkteamInput{
WorkteamName: aws.String(name),
WorkforceName: aws.String(d.Get("workforce_name").(string)),
Description: aws.String(d.Get(names.AttrDescription).(string)),
MemberDefinitions: expandWorkteamMemberDefinition(d.Get("member_definition").([]interface{})),
Tags: getTagsIn(ctx),
Expand All @@ -205,7 +204,10 @@ func resourceWorkteamCreate(ctx context.Context, d *schema.ResourceData, meta in
input.WorkerAccessConfiguration = expandWorkerAccessConfiguration(v.([]interface{}))
}

log.Printf("[DEBUG] Updating SageMaker Workteam: %#v", input)
if v, ok := d.GetOk("workforce_name"); ok {
input.WorkforceName = aws.String(v.(string))
}

_, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, 2*time.Minute, func() (interface{}, error) {
return conn.CreateWorkteam(ctx, input)
}, ErrCodeValidationException)
Expand Down Expand Up @@ -277,7 +279,6 @@ func resourceWorkteamUpdate(ctx context.Context, d *schema.ResourceData, meta in
input.WorkerAccessConfiguration = expandWorkerAccessConfiguration(d.Get("worker_access_configuration").([]interface{}))
}

log.Printf("[DEBUG] Updating SageMaker Workteam: %#v", input)
_, err := conn.UpdateWorkteam(ctx, input)

if err != nil {
Expand Down
69 changes: 69 additions & 0 deletions internal/service/sagemaker/workteam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,38 @@ func testAccWorkteam_cognitoConfig(t *testing.T) {
})
}

func testAccWorkteam_cognitoOmitWorkforceName(t *testing.T) {
ctx := acctest.Context(t)
var workteam awstypes.Workteam
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_sagemaker_workteam.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.SageMakerServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckWorkteamDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccWorkteamConfig_omitWorkforceName(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckWorkteamExists(ctx, resourceName, &workteam),
resource.TestCheckResourceAttr(resourceName, "workteam_name", rName),
acctest.MatchResourceAttrRegionalARN(resourceName, names.AttrARN, "sagemaker", regexache.MustCompile(`workteam/.+`)),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, rName),
resource.TestCheckResourceAttr(resourceName, "member_definition.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "member_definition.0.cognito_member_definition.#", acctest.Ct1),
resource.TestCheckResourceAttrPair(resourceName, "member_definition.0.cognito_member_definition.0.client_id", "aws_cognito_user_pool_client.test", names.AttrID),
resource.TestCheckResourceAttrPair(resourceName, "member_definition.0.cognito_member_definition.0.user_pool", "aws_cognito_user_pool.test", names.AttrID),
resource.TestCheckResourceAttrPair(resourceName, "member_definition.0.cognito_member_definition.0.user_group", "aws_cognito_user_group.test", names.AttrID),
resource.TestCheckResourceAttrSet(resourceName, "subdomain"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct0),
),
},
},
})
}

func testAccWorkteam_oidcConfig(t *testing.T) {
ctx := acctest.Context(t)
var workteam awstypes.Workteam
Expand Down Expand Up @@ -425,6 +457,43 @@ resource "aws_sagemaker_workteam" "test" {
`, rName))
}

func testAccWorkteamConfig_omitWorkforceName(rName string) string {
return fmt.Sprintf(`
resource "aws_cognito_user_pool" "test" {
name = %[1]q
}

resource "aws_cognito_user_pool_client" "test" {
name = %[1]q
generate_secret = true
user_pool_id = aws_cognito_user_pool.test.id
}

resource "aws_cognito_user_pool_domain" "test" {
domain = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
}

resource "aws_cognito_user_group" "test" {
name = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
}

resource "aws_sagemaker_workteam" "test" {
workteam_name = %[1]q
description = %[1]q

member_definition {
cognito_member_definition {
client_id = aws_cognito_user_pool_client.test.id
user_pool = aws_cognito_user_pool_domain.test.user_pool_id
user_group = aws_cognito_user_group.test.id
}
}
}
`, rName)
}

func testAccWorkteamConfig_cognitoUpdated(rName string) string {
return acctest.ConfigCompose(testAccWorkteamCognitoBaseConfig(rName), fmt.Sprintf(`
resource "aws_cognito_user_group" "test2" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/sagemaker_workteam.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resource "aws_sagemaker_workteam" "example" {
This resource supports the following arguments:

* `description` - (Required) A description of the work team.
* `workforce_name` - (Required) The name of the workforce.
* `workforce_name` - (Optional) The name of the workforce.
* `workteam_name` - (Required) The name of the Workteam (must be unique).
* `member_definition` - (Required) A list of Member Definitions that contains objects that identify the workers that make up the work team. Workforces can be created using Amazon Cognito or your own OIDC Identity Provider (IdP). For private workforces created using Amazon Cognito use `cognito_member_definition`. For workforces created using your own OIDC identity provider (IdP) use `oidc_member_definition`. Do not provide input for both of these parameters in a single request. see [Member Definition](#member-definition) details below.
* `notification_configuration` - (Optional) Configures notification of workers regarding available or expiring work items. see [Notification Configuration](#notification-configuration) details below.
Expand Down
Loading