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/cognito_resource_server allow name change without ForceNew #41702

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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/41702.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_cognito_resource_server: Allow changes to `name` attribute without deleting and recreating.
```
1 change: 0 additions & 1 deletion internal/service/cognitoidp/resource_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func resourceResourceServer() *schema.Resource {
names.AttrName: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
names.AttrScope: {
Type: schema.TypeSet,
Expand Down
45 changes: 45 additions & 0 deletions internal/service/cognitoidp/resource_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,37 @@ func TestAccCognitoIDPResourceServer_scope(t *testing.T) {
})
}

func TestAccCognitoIDPResourceServer_nameChange(t *testing.T) {
ctx := acctest.Context(t)
var resourceServer awstypes.ResourceServerType
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
identifier := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_cognito_resource_server.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckIdentityProvider(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.CognitoIDPServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckResourceServerDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccResourceServerConfig_basic(identifier, rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckResourceServerExists(ctx, resourceName, &resourceServer),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
),
},
{
Config: testAccResourceServerConfig_nameUpdate(identifier, rName),
Check: resource.ComposeAggregateTestCheckFunc(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not able to find a good example to follow for asserting that the resource is not deleted and recreated by terraform.

The examples I did find all used some unique attribute in the AWS api response, like a creation date, to make the assertion, but there is no such attribute available for this resource. The only option I can think of would be to add an assertion on the Plan, but I don't know how to do that, and I'm not sure if it's necessary.

testAccCheckResourceServerExists(ctx, resourceName, &resourceServer),
resource.TestCheckResourceAttr(resourceName, names.AttrName, fmt.Sprintf(`%s updated`, rName)),
),
},
},
})
}

func testAccCheckResourceServerExists(ctx context.Context, n string, v *awstypes.ResourceServerType) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -184,6 +215,20 @@ resource "aws_cognito_user_pool" "test" {
`, identifier, rName)
}

func testAccResourceServerConfig_nameUpdate(identifier, rName string) string {
return fmt.Sprintf(`
resource "aws_cognito_resource_server" "test" {
identifier = %[1]q
name = "%[2]s updated"
user_pool_id = aws_cognito_user_pool.test.id
}

resource "aws_cognito_user_pool" "test" {
name = %[2]q
}
`, identifier, rName)
}

func testAccResourceServerConfig_scope(identifier, rName string) string {
return fmt.Sprintf(`
resource "aws_cognito_resource_server" "test" {
Expand Down
Loading