Skip to content

Commit 39901a2

Browse files
committed
Add 'TestAccCognitoIDPManagedLoginBranding_updateFromBasic'.
1 parent 50dcc80 commit 39901a2

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

internal/service/cognitoidp/managed_login_branding.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/hashicorp/terraform-plugin-framework/path"
1818
"github.com/hashicorp/terraform-plugin-framework/resource"
1919
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
20-
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
2120
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
2221
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
2322
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
@@ -78,11 +77,9 @@ func (r *managedLoginBrandingResource) Schema(ctx context.Context, request resou
7877
Validators: []validator.Bool{
7978
boolvalidator.ExactlyOneOf(
8079
path.MatchRoot("settings"),
80+
path.MatchRoot("use_cognito_provided_values"),
8181
),
8282
},
83-
PlanModifiers: []planmodifier.Bool{
84-
boolplanmodifier.UseStateForUnknown(),
85-
},
8683
},
8784
names.AttrUserPoolID: schema.StringAttribute{
8885
Required: true,
@@ -316,13 +313,20 @@ func (r *managedLoginBrandingResource) Update(ctx context.Context, request resou
316313
}
317314

318315
// Updated settings work in a PATCH model: https://docs.aws.amazon.com/cognito/latest/developerguide/managed-login-brandingeditor.html#branding-designer-api.
319-
oldSettings, newSettings := fwflex.StringValueFromFramework(ctx, old.Settings), fwflex.StringValueFromFramework(ctx, new.Settings)
320-
patch, err := tfjson.CreateMergePatchFromStrings(oldSettings, newSettings)
316+
var patch string
317+
var err error
318+
if oldSettings, newSettings := fwflex.StringValueFromFramework(ctx, old.Settings), fwflex.StringValueFromFramework(ctx, new.Settings); oldSettings != "" {
319+
patch, err = tfjson.CreateMergePatchFromStrings(oldSettings, newSettings)
321320

322-
if err != nil {
323-
response.Diagnostics.AddError("creating JSON merge patch", err.Error())
321+
if err != nil {
322+
response.Diagnostics.AddError("creating JSON merge patch", err.Error())
324323

325-
return
324+
return
325+
}
326+
input.UseCognitoProvidedValues = false
327+
} else if newSettings != "" {
328+
patch = newSettings
329+
input.UseCognitoProvidedValues = false
326330
}
327331

328332
input.Settings, err = tfsmithy.DocumentFromJSONString(patch, document.NewLazyDocument)
@@ -356,6 +360,7 @@ func (r *managedLoginBrandingResource) Update(ctx context.Context, request resou
356360
return
357361
}
358362
new.SettingsAll = settingsAll
363+
new.UseCognitoProvidedValues = fwflex.BoolValueToFramework(ctx, mlb.UseCognitoProvidedValues)
359364

360365
response.Diagnostics.Append(response.State.Set(ctx, &new)...)
361366
}

internal/service/cognitoidp/managed_login_branding_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,52 @@ func TestAccCognitoIDPManagedLoginBranding_settings(t *testing.T) {
163163
})
164164
}
165165

166+
func TestAccCognitoIDPManagedLoginBranding_updateFromBasic(t *testing.T) {
167+
ctx := acctest.Context(t)
168+
var v awstypes.ManagedLoginBrandingType
169+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
170+
resourceName := "aws_cognito_managed_login_branding.test"
171+
172+
resource.ParallelTest(t, resource.TestCase{
173+
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckIdentityProvider(ctx, t) },
174+
ErrorCheck: acctest.ErrorCheck(t, names.CognitoIDPServiceID),
175+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
176+
CheckDestroy: testAccCheckManagedLoginBrandingDestroy(ctx),
177+
Steps: []resource.TestStep{
178+
{
179+
Config: testAccManagedLoginBrandingConfig_basic(rName),
180+
Check: resource.ComposeAggregateTestCheckFunc(
181+
testAccCheckManagedLoginBrandingExists(ctx, resourceName, &v),
182+
),
183+
ConfigPlanChecks: resource.ConfigPlanChecks{
184+
PreApply: []plancheck.PlanCheck{
185+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
186+
},
187+
},
188+
ConfigStateChecks: []statecheck.StateCheck{
189+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("settings"), knownvalue.Null()),
190+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("use_cognito_provided_values"), knownvalue.Bool(true)),
191+
},
192+
},
193+
{
194+
Config: testAccManagedLoginBrandingConfig_settings(rName),
195+
Check: resource.ComposeAggregateTestCheckFunc(
196+
testAccCheckManagedLoginBrandingExists(ctx, resourceName, &v),
197+
),
198+
ConfigPlanChecks: resource.ConfigPlanChecks{
199+
PreApply: []plancheck.PlanCheck{
200+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
201+
},
202+
},
203+
ConfigStateChecks: []statecheck.StateCheck{
204+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("settings"), knownvalue.NotNull()),
205+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("use_cognito_provided_values"), knownvalue.Bool(false)),
206+
},
207+
},
208+
},
209+
})
210+
}
211+
166212
func testAccCheckManagedLoginBrandingDestroy(ctx context.Context) resource.TestCheckFunc {
167213
return func(s *terraform.State) error {
168214
conn := acctest.Provider.Meta().(*conns.AWSClient).CognitoIDPClient(ctx)

0 commit comments

Comments
 (0)