Skip to content

Commit

Permalink
Address review: rename device_filter block, normalize enum casing ins…
Browse files Browse the repository at this point in the history
…tead of diffsuppressing it
  • Loading branch information
manicminer committed Nov 25, 2021
1 parent e8984d9 commit 8516a68
Showing 1 changed file with 25 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-azuread/internal/tf/suppress"
"github.com/manicminer/hamilton/msgraph"
"github.com/manicminer/hamilton/odata"

Expand Down Expand Up @@ -55,14 +54,13 @@ func conditionalAccessPolicyResource() *schema.Resource {
},

"state": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: suppress.CaseDifference,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
msgraph.ConditionalAccessPolicyStateDisabled,
msgraph.ConditionalAccessPolicyStateEnabled,
msgraph.ConditionalAccessPolicyStateEnabledForReportingButNotEnforced,
}, true),
}, false),
},

"conditions": {
Expand Down Expand Up @@ -174,9 +172,8 @@ func conditionalAccessPolicyResource() *schema.Resource {
},

"client_app_types": {
Type: schema.TypeList,
Required: true,
DiffSuppressFunc: suppress.CaseDifference,
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
Expand All @@ -186,7 +183,7 @@ func conditionalAccessPolicyResource() *schema.Resource {
msgraph.ConditionalAccessClientAppTypeExchangeActiveSync,
msgraph.ConditionalAccessClientAppTypeMobileAppsAndDesktopClients,
msgraph.ConditionalAccessClientAppTypeOther,
}, true),
}, false),
},
},

Expand All @@ -196,20 +193,19 @@ func conditionalAccessPolicyResource() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"device_filter": {
"filter": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"mode": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: suppress.CaseDifference,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
msgraph.ConditionalAccessFilterModeExclude,
msgraph.ConditionalAccessFilterModeInclude,
}, true),
}, false),
},

"rule": {
Expand Down Expand Up @@ -261,8 +257,7 @@ func conditionalAccessPolicyResource() *schema.Resource {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: suppress.CaseDifference,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
msgraph.ConditionalAccessDevicePlatformAll,
msgraph.ConditionalAccessDevicePlatformAndroid,
Expand All @@ -271,16 +266,15 @@ func conditionalAccessPolicyResource() *schema.Resource {
msgraph.ConditionalAccessDevicePlatformUnknownFutureValue,
msgraph.ConditionalAccessDevicePlatformWindows,
msgraph.ConditionalAccessDevicePlatformWindowsPhone,
}, true),
}, false),
},
},

"excluded_platforms": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: suppress.CaseDifference,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
msgraph.ConditionalAccessDevicePlatformAll,
msgraph.ConditionalAccessDevicePlatformAndroid,
Expand All @@ -289,7 +283,7 @@ func conditionalAccessPolicyResource() *schema.Resource {
msgraph.ConditionalAccessDevicePlatformUnknownFutureValue,
msgraph.ConditionalAccessDevicePlatformWindows,
msgraph.ConditionalAccessDevicePlatformWindowsPhone,
}, true),
}, false),
},
},
},
Expand All @@ -300,33 +294,31 @@ func conditionalAccessPolicyResource() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: suppress.CaseDifference,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
msgraph.ConditionalAccessRiskLevelHidden,
msgraph.ConditionalAccessRiskLevelHigh,
msgraph.ConditionalAccessRiskLevelLow,
msgraph.ConditionalAccessRiskLevelMedium,
msgraph.ConditionalAccessRiskLevelNone,
msgraph.ConditionalAccessRiskLevelUnknownFutureValue,
}, true),
}, false),
},
},

"user_risk_levels": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: suppress.CaseDifference,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
msgraph.ConditionalAccessRiskLevelHidden,
msgraph.ConditionalAccessRiskLevelHigh,
msgraph.ConditionalAccessRiskLevelLow,
msgraph.ConditionalAccessRiskLevelMedium,
msgraph.ConditionalAccessRiskLevelNone,
msgraph.ConditionalAccessRiskLevelUnknownFutureValue,
}, true),
}, false),
},
},
},
Expand All @@ -348,8 +340,7 @@ func conditionalAccessPolicyResource() *schema.Resource {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: suppress.CaseDifference,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
msgraph.ConditionalAccessGrantControlApprovedApplication,
msgraph.ConditionalAccessGrantControlBlock,
Expand All @@ -359,7 +350,7 @@ func conditionalAccessPolicyResource() *schema.Resource {
msgraph.ConditionalAccessGrantControlMfa,
msgraph.ConditionalAccessGrantControlPasswordChange,
msgraph.ConditionalAccessGrantControlUnknownFutureValue,
}, true),
}, false),
},
},

Expand Down Expand Up @@ -396,15 +387,14 @@ func conditionalAccessPolicyResource() *schema.Resource {
},

"cloud_app_security_policy": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: suppress.CaseDifference,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
msgraph.ConditionalAccessCloudAppSecuritySessionControlTypeBlockDownloads,
msgraph.ConditionalAccessCloudAppSecuritySessionControlTypeMcasConfigured,
msgraph.ConditionalAccessCloudAppSecuritySessionControlTypeMonitorOnly,
msgraph.ConditionalAccessCloudAppSecuritySessionControlTypeUnknownFutureValue,
}, true),
}, false),
},

"sign_in_frequency": {
Expand Down Expand Up @@ -439,8 +429,8 @@ func conditionalAccessPolicyCustomizeDiff(ctx context.Context, diff *schema.Reso
if old, new := diff.GetChange("conditions.0.devices.#"); old.(int) > 0 && new.(int) == 0 {
diff.ForceNew("conditions.0.devices")
}
if old, new := diff.GetChange("conditions.0.devices.0.device_filter.#"); old.(int) > 0 && new.(int) == 0 {
diff.ForceNew("conditions.0.devices.0.device_filter")
if old, new := diff.GetChange("conditions.0.devices.0.filter.#"); old.(int) > 0 && new.(int) == 0 {
diff.ForceNew("conditions.0.devices.0.filter")
}

return nil
Expand Down

0 comments on commit 8516a68

Please sign in to comment.