Skip to content

Commit

Permalink
Fix terraform marking callback and logout URLs as changed when empty
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaei committed Oct 17, 2022
1 parent 2524a56 commit c98d2b7
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions internal/provider/app_client_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,19 @@ func (ac appClientResourceData) toDomain(domain *central_cognito.AppClient) {
domain.Name = ac.Name.Value
domain.Scopes = ac.Scopes
domain.Type = ac.Type.Value
domain.CallbackUrls = ac.CallbackUrls
domain.LogoutUrls = ac.LogoutUrls

// The remote expects it to always be a list.
if ac.CallbackUrls == nil {
domain.CallbackUrls = []string{}
} else {
domain.CallbackUrls = ac.CallbackUrls
}

if ac.LogoutUrls == nil {
domain.LogoutUrls = []string{}
} else {
domain.LogoutUrls = ac.LogoutUrls
}

if !ac.GenerateSecret.Null {
domain.GenerateSecret = &ac.GenerateSecret.Value
Expand All @@ -165,8 +176,20 @@ func appClientResourceDataFromDomain(domain central_cognito.AppClient, state *ap
state.Name.Value = domain.Name
state.Scopes = domain.Scopes
state.Type.Value = domain.Type
state.CallbackUrls = domain.CallbackUrls
state.LogoutUrls = domain.LogoutUrls

// If the config is empty on our side, terraform expects a null, not an empty list.
// There is probably a better way to handle this, but I can't find anything in the docs.
if len(domain.CallbackUrls) == 0 {
state.CallbackUrls = nil
} else {
state.CallbackUrls = domain.CallbackUrls
}

if len(domain.LogoutUrls) == 0 {
state.LogoutUrls = nil
} else {
state.LogoutUrls = domain.LogoutUrls
}

if domain.GenerateSecret != nil {
state.GenerateSecret.Value = *domain.GenerateSecret
Expand Down Expand Up @@ -244,7 +267,8 @@ func (r appClientResource) Read(ctx context.Context, req tfsdk.ReadResourceReque
return
}

appClientResourceDataFromDomain(server, &data)
var newState appClientResourceData
appClientResourceDataFromDomain(server, &newState)

diags = resp.State.Set(ctx, &data)
resp.Diagnostics.Append(diags...)
Expand Down

0 comments on commit c98d2b7

Please sign in to comment.