Skip to content

Commit

Permalink
Merge branch 'add-default-value' into 'master'
Browse files Browse the repository at this point in the history
default value {} assigned to group_selection, login_spi & mobile_settings

See merge request cidaas-management/terraform!110
  • Loading branch information
Tujit Bora committed Aug 29, 2024
2 parents fa6bd00 + 6b3df49 commit 03d3566
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/resources/custom_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Optional:
- `picture` (String)
- `preferred_username` (String)
- `profile` (String)
- `sub` (String)
- `updated_at` (String)
- `website` (String)
- `zoneinfo` (String)
Expand Down
11 changes: 7 additions & 4 deletions internal/resources/app_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,8 @@ func updateStateModel(res cidaas.AppResponse, state, config *AppConfig, operatio
}
}

if res.Data.LoginSpi != nil {
if res.Data.LoginSpi != nil && (((operation == CREATE || operation == UPDATE) && !config.LoginSpi.IsNull()) ||
operation == IMPORT || operation == READ) {
oauthClientID := util.StringValueOrNull(&res.Data.LoginSpi.OauthClientID)
spiURL := util.StringValueOrNull(&res.Data.LoginSpi.SpiURL)
if !state.LoginSpi.IsNull() && !state.LoginSpi.IsUnknown() && state.loginSpi != nil {
Expand Down Expand Up @@ -1107,8 +1108,9 @@ func updateStateModel(res cidaas.AppResponse, state, config *AppConfig, operatio
state.LoginSpi = loginSpi
}

if res.Data.GroupSelection != nil {

if res.Data.GroupSelection != nil &&
(((operation == CREATE || operation == UPDATE) && !config.GroupSelection.IsNull()) ||
operation == IMPORT || operation == READ) {
alwaysShowGroupSelection := util.BoolValueOrNull(res.Data.GroupSelection.AlwaysShowGroupSelection)
selectableGroups := util.SetValueOrNull(res.Data.GroupSelection.SelectableGroups)
selectableGroupTypes := util.SetValueOrNull(res.Data.GroupSelection.SelectableGroupTypes)
Expand Down Expand Up @@ -1175,7 +1177,8 @@ func updateStateModel(res cidaas.AppResponse, state, config *AppConfig, operatio
state.Mfa = mfa
}

if res.Data.MobileSettings != nil {
if res.Data.MobileSettings != nil && (((operation == CREATE || operation == UPDATE) && !config.MobileSettings.IsNull()) ||
operation == IMPORT || operation == READ) {
teamID := util.StringValueOrNull(&res.Data.MobileSettings.TeamID)
bundleID := util.StringValueOrNull(&res.Data.MobileSettings.BundleID)
packageName := util.StringValueOrNull(&res.Data.MobileSettings.PackageName)
Expand Down
55 changes: 46 additions & 9 deletions internal/resources/app_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault"
Expand Down Expand Up @@ -281,6 +282,7 @@ func (r *AppResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
setplanmodifier.UseStateForUnknown(),
},
},
// cidaas faulty api, so marked this attribute as computed
"mobile_settings": schema.SingleNestedAttribute{
Optional: true,
Computed: true,
Expand All @@ -298,9 +300,22 @@ func (r *AppResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
Optional: true,
},
},
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
Default: objectdefault.StaticValue(
types.ObjectValueMust(
map[string]attr.Type{
"team_id": types.StringType,
"bundle_id": types.StringType,
"package_name": types.StringType,
"key_hash": types.StringType,
},
map[string]attr.Value{
"team_id": types.StringNull(),
"bundle_id": types.StringNull(),
"package_name": types.StringNull(),
"key_hash": types.StringNull(),
},
),
),
},
"default_max_age": schema.Int64Attribute{
Optional: true,
Expand Down Expand Up @@ -653,6 +668,7 @@ func (r *AppResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
},
"group_selection": schema.SingleNestedAttribute{
Optional: true,
// cidaas faulty api, so marked this attribute as computed
Computed: true,
Attributes: map[string]schema.Attribute{
"always_show_group_selection": schema.BoolAttribute{
Expand All @@ -667,9 +683,20 @@ func (r *AppResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
Optional: true,
},
},
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
Default: objectdefault.StaticValue(
types.ObjectValueMust(
map[string]attr.Type{
"always_show_group_selection": types.BoolType,
"selectable_groups": types.SetType{ElemType: types.StringType},
"selectable_group_types": types.SetType{ElemType: types.StringType},
},
map[string]attr.Value{
"always_show_group_selection": types.BoolNull(),
"selectable_groups": types.SetNull(types.StringType),
"selectable_group_types": types.SetNull(types.StringType),
},
),
),
},
"group_types": schema.SetAttribute{
ElementType: types.StringType,
Expand Down Expand Up @@ -894,6 +921,7 @@ func (r *AppResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
ElementType: types.StringType,
Optional: true,
},
// cidaas faulty api, so marked this attribute as computed
"login_spi": schema.SingleNestedAttribute{
Optional: true,
Computed: true,
Expand All @@ -906,9 +934,18 @@ func (r *AppResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *
Optional: true,
},
},
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
Default: objectdefault.StaticValue(
types.ObjectValueMust(
map[string]attr.Type{
"oauth_client_id": types.StringType,
"spi_url": types.StringType,
},
map[string]attr.Value{
"oauth_client_id": types.StringNull(),
"spi_url": types.StringNull(),
},
),
),
},
"background_uri": schema.StringAttribute{
Optional: true,
Expand Down
6 changes: 4 additions & 2 deletions internal/resources/resource_custom_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,11 @@ func (r *CustomProvider) Read(ctx context.Context, req resource.ReadRequest, res
hasCustomfield := false
for key, value := range res.Data.UserinfoFields {
val := value
supportedUserInfoFields := []string{"name", "family_name", "given_name", "middle_name", "nickname", "preferred_username",
supportedUserInfoFields := []string{
"name", "family_name", "given_name", "middle_name", "nickname", "preferred_username",
"profile", "picture", "website", "gender", "birthdate", "zoneinfo", "locale", "updated_at", "email", "email_verified",
"phone_number", "mobile_number", "address", "sub"}
"phone_number", "mobile_number", "address", "sub",
}

if strings.HasPrefix(key, "customFields.") {
customFields[strings.TrimPrefix(key, "customFields.")] = util.StringValueOrNull(&val)
Expand Down

0 comments on commit 03d3566

Please sign in to comment.