Skip to content

Commit

Permalink
feat: make flatten filter generic and use for device and app
Browse files Browse the repository at this point in the history
Signed-off-by: Brendan Thompson <github@blt.is>
  • Loading branch information
BrendanThompson authored and manicminer committed May 8, 2024
1 parent 7fb5a79 commit 7212c53
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions internal/services/conditionalaccess/conditionalaccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package conditionalaccess

import (
"log"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/terraform-provider-azuread/internal/tf"
"github.com/manicminer/hamilton/msgraph"
Expand Down Expand Up @@ -40,6 +42,7 @@ func flattenConditionalAccessApplications(in *msgraph.ConditionalAccessApplicati
"included_applications": tf.FlattenStringSlicePtr(in.IncludeApplications),
"excluded_applications": tf.FlattenStringSlicePtr(in.ExcludeApplications),
"included_user_actions": tf.FlattenStringSlicePtr(in.IncludeUserActions),
"filter": flattenConditionalAccessFilter(in.ApplicationFilter),
},
}
}
Expand Down Expand Up @@ -83,7 +86,7 @@ func flattenConditionalAccessDevices(in *msgraph.ConditionalAccessDevices) []int

return []interface{}{
map[string]interface{}{
"filter": flattenConditionalAccessDeviceFilter(in.DeviceFilter),
"filter": flattenConditionalAccessFilter(in.DeviceFilter),
},
}
}
Expand Down Expand Up @@ -188,11 +191,14 @@ func flattenConditionalAccessSessionControls(in *msgraph.ConditionalAccessSessio
}
}

func flattenConditionalAccessDeviceFilter(in *msgraph.ConditionalAccessFilter) []interface{} {
func flattenConditionalAccessFilter(in *msgraph.ConditionalAccessFilter) []interface{} {
if in == nil {
log.Print("=== no access filters to flatten")
return []interface{}{}
}

log.Printf("=== access filters are being flattened: %s", *in.Rule)

return []interface{}{
map[string]interface{}{
"mode": in.Mode,
Expand Down Expand Up @@ -345,7 +351,10 @@ func expandConditionalAccessApplications(in []interface{}) *msgraph.ConditionalA
result.ExcludeApplications = tf.ExpandStringSlicePtr(excludeApplications)
result.IncludeUserActions = tf.ExpandStringSlicePtr(includeUserActions)
if len(filter) > 0 {
log.Printf("=== appliction filter being expanded %+v \n", filter...)
result.ApplicationFilter = expandConditionalAccessFilter(filter)
} else {
log.Println("=== no application filter to expand")
}

return &result
Expand Down

0 comments on commit 7212c53

Please sign in to comment.