Skip to content

Commit 6b94979

Browse files
committed
azuread_conditional_access_policy - add client_applications.filter
1 parent ef397a7 commit 6b94979

File tree

12 files changed

+109
-38
lines changed

12 files changed

+109
-38
lines changed

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ testacc: fmtcheck
9191
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 180m -ldflags="-X=github.com/hashicorp/terraform-provider-azuread/version.ProviderVersion=acc"
9292

9393
acctests: fmtcheck
94-
TF_ACC=1 go test -v ./internal/services/$(SERVICE)/tests/ $(TESTARGS) -timeout $(TESTTIMEOUT) -ldflags="-X=github.com/hashicorp/terraform-provider-azuread/version.ProviderVersion=acc"
94+
TF_ACC=1 go test -v ./internal/services/$(SERVICE)/ $(TESTARGS) -timeout $(TESTTIMEOUT) -ldflags="-X=github.com/hashicorp/terraform-provider-azuread/version.ProviderVersion=acc"
9595

9696
debugacc: fmtcheck
9797
TF_ACC=1 dlv test $(TEST) --headless --listen=:2345 --api-version=2 -- -test.v $(TESTARGS)

docs/resources/conditional_access_policy.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ The following arguments are supported:
185185

186186
* `excluded_service_principals` - (Optional) A list of service principal IDs explicitly excluded in the policy.
187187
* `included_service_principals` - (Optional) A list of service principal IDs explicitly included in the policy. Can be set to `ServicePrincipalsInMyTenant` to include all service principals. This is mandatory value when at least one `excluded_service_principals` is set.
188+
* `filter` - (Optional) A `filter` block as described below.
189+
190+
~> **Note:** Specifying `filter` requires the `Attribute Definition Reader` role, this is not included in the `Global Administrator` or other administrator roles and must be separately assigned.
188191

189192
---
190193

@@ -196,8 +199,12 @@ The following arguments are supported:
196199

197200
`filter` block supports the following:
198201

199-
* `mode` - (Required) Whether to include in, or exclude from, matching devices from the policy. Supported values are `include` or `exclude`.
200-
* `rule` - (Required) Condition filter to match devices. For more information, see [official documentation](https://docs.microsoft.com/en-us/azure/active-directory/conditional-access/concept-condition-filters-for-devices#supported-operators-and-device-properties-for-filters).
202+
* `mode` - (Required) Whether to include in, or exclude from, matching items from the policy. Supported values are `include` or `exclude`.
203+
* `rule` - (Required) Condition filter to match items.
204+
205+
-> **Note:** For more information on device filters, see the [official documentation](https://docs.microsoft.com/en-us/azure/active-directory/conditional-access/concept-condition-filters-for-devices#supported-operators-and-device-properties-for-filters).
206+
207+
-> **Note:** For more information on application filters, see the [official documentation](https://learn.microsoft.com/en-us/entra/identity/conditional-access/concept-filter-for-applications).
201208

202209
---
203210

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/hashicorp/terraform-provider-azuread
33
require (
44
github.com/google/go-cmp v0.7.0
55
github.com/hashicorp/go-azure-helpers v0.73.0
6-
github.com/hashicorp/go-azure-sdk/microsoft-graph v0.20250618.1093309
7-
github.com/hashicorp/go-azure-sdk/sdk v0.20250618.1093309
6+
github.com/hashicorp/go-azure-sdk/microsoft-graph v0.20250731.1192335
7+
github.com/hashicorp/go-azure-sdk/sdk v0.20250731.1192335
88
github.com/hashicorp/go-cty v1.5.0
99
github.com/hashicorp/go-multierror v1.1.1
1010
github.com/hashicorp/go-uuid v1.0.3

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
5555
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
5656
github.com/hashicorp/go-azure-helpers v0.73.0 h1:J++NBrLzwv6U/hSXeC29pWOr+5S+xnoQWVT2r1XAexw=
5757
github.com/hashicorp/go-azure-helpers v0.73.0/go.mod h1:tAUWC+kwZQsuNAHEIlnbojMMcC6SWQb6W1HfIeluv1E=
58-
github.com/hashicorp/go-azure-sdk/microsoft-graph v0.20250618.1093309 h1:giIJVkamQZN/28JQdCpJCsnYmNp1I+vN8zlmRTXuUmc=
59-
github.com/hashicorp/go-azure-sdk/microsoft-graph v0.20250618.1093309/go.mod h1:ty40K81T+JuCzG/9hOfB0rqCg/1iXSY3OudKwcZKgf8=
60-
github.com/hashicorp/go-azure-sdk/sdk v0.20250618.1093309 h1:EZLtbwBWk3/WYGQAvae5rHezjVlIPoUwoRk9lVTMc68=
61-
github.com/hashicorp/go-azure-sdk/sdk v0.20250618.1093309/go.mod h1:eyNClZwQsa4Go51ScU9OYCE2EQvbNt8EjZ4eMxpQ1H8=
58+
github.com/hashicorp/go-azure-sdk/microsoft-graph v0.20250731.1192335 h1:3RKmlQ8jRTepZSXOiCXzzldkn5zztZaNTysv9KzDfd0=
59+
github.com/hashicorp/go-azure-sdk/microsoft-graph v0.20250731.1192335/go.mod h1:1BFZ7+9v9RCXbk9F923R/4QRK+D2dXE9PhVjy9Mo940=
60+
github.com/hashicorp/go-azure-sdk/sdk v0.20250731.1192335 h1:Mbwo0DISwRI0N8Yrb1w/F4Ub1ot71NM1w8DeozbnpKs=
61+
github.com/hashicorp/go-azure-sdk/sdk v0.20250731.1192335/go.mod h1:eyNClZwQsa4Go51ScU9OYCE2EQvbNt8EjZ4eMxpQ1H8=
6262
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
6363
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
6464
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=

internal/services/conditionalaccess/conditional_access_policy_resource.go

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ func conditionalAccessPolicyResource() *pluginsdk.Resource {
138138
ValidateFunc: validation.StringIsNotEmpty,
139139
},
140140
},
141+
142+
"filter": schemaConditionalAccessFilter(),
141143
},
142144
},
143145
},
@@ -304,26 +306,7 @@ func conditionalAccessPolicyResource() *pluginsdk.Resource {
304306
MaxItems: 1,
305307
Elem: &pluginsdk.Resource{
306308
Schema: map[string]*pluginsdk.Schema{
307-
"filter": {
308-
Type: pluginsdk.TypeList,
309-
Optional: true,
310-
MaxItems: 1,
311-
Elem: &pluginsdk.Resource{
312-
Schema: map[string]*pluginsdk.Schema{
313-
"mode": {
314-
Type: pluginsdk.TypeString,
315-
Required: true,
316-
ValidateFunc: validation.StringInSlice(stable.PossibleValuesForFilterMode(), false),
317-
},
318-
319-
"rule": {
320-
Type: pluginsdk.TypeString,
321-
Required: true,
322-
ValidateFunc: validation.StringIsNotEmpty,
323-
},
324-
},
325-
},
326-
},
309+
"filter": schemaConditionalAccessFilter(),
327310
},
328311
},
329312
},

internal/services/conditionalaccess/conditional_access_policy_resource_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,13 @@ func TestAccConditionalAccessPolicy_clientApplications(t *testing.T) {
317317
),
318318
},
319319
data.ImportStep(),
320+
{
321+
Config: r.clientApplicationsFilter(data),
322+
Check: acceptance.ComposeTestCheckFunc(
323+
check.That(data.ResourceName).ExistsInAzure(r),
324+
),
325+
},
326+
data.ImportStep(),
320327
{
321328
Config: r.clientApplicationsIncluded(data),
322329
Check: acceptance.ComposeTestCheckFunc(
@@ -862,6 +869,49 @@ resource "azuread_conditional_access_policy" "test" {
862869
`, data.RandomInteger)
863870
}
864871

872+
func (ConditionalAccessPolicyResource) clientApplicationsFilter(data acceptance.TestData) string {
873+
return fmt.Sprintf(`
874+
provider "azuread" {}
875+
876+
data "azuread_service_principal" "test" {
877+
display_name = "Terraform Acceptance Tests (Single Tenant)"
878+
}
879+
880+
resource "azuread_conditional_access_policy" "test" {
881+
display_name = "acctest-CONPOLICY-%[1]d"
882+
state = "disabled"
883+
884+
conditions {
885+
client_app_types = ["all"]
886+
887+
applications {
888+
included_applications = ["All"]
889+
}
890+
891+
client_applications {
892+
included_service_principals = ["ServicePrincipalsInMyTenant"]
893+
894+
filter {
895+
mode = "exclude"
896+
rule = "CustomSecurityAttribute.AzureADProviderTesting_Usage -contains \"Acceptance Tests\""
897+
}
898+
}
899+
900+
service_principal_risk_levels = ["medium"]
901+
902+
users {
903+
included_users = ["None"]
904+
}
905+
}
906+
907+
grant_controls {
908+
operator = "OR"
909+
built_in_controls = ["block"]
910+
}
911+
}
912+
`, data.RandomInteger)
913+
}
914+
865915
func (ConditionalAccessPolicyResource) authenticationStrengthPolicy(data acceptance.TestData) string {
866916
return fmt.Sprintf(`
867917
provider "azuread" {}

internal/services/conditionalaccess/conditionalaccess.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,34 @@ import (
99
"github.com/hashicorp/go-azure-helpers/lang/pointer"
1010
"github.com/hashicorp/go-azure-sdk/microsoft-graph/common-types/stable"
1111
"github.com/hashicorp/go-azure-sdk/sdk/nullable"
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1213
"github.com/hashicorp/terraform-provider-azuread/internal/helpers/tf"
14+
"github.com/hashicorp/terraform-provider-azuread/internal/helpers/tf/pluginsdk"
1315
)
1416

17+
func schemaConditionalAccessFilter() *pluginsdk.Schema {
18+
return &pluginsdk.Schema{
19+
Type: pluginsdk.TypeList,
20+
Optional: true,
21+
MaxItems: 1,
22+
Elem: &pluginsdk.Resource{
23+
Schema: map[string]*pluginsdk.Schema{
24+
"mode": {
25+
Type: pluginsdk.TypeString,
26+
Required: true,
27+
ValidateFunc: validation.StringInSlice(stable.PossibleValuesForFilterMode(), false),
28+
},
29+
30+
"rule": {
31+
Type: pluginsdk.TypeString,
32+
Required: true,
33+
ValidateFunc: validation.StringIsNotEmpty,
34+
},
35+
},
36+
},
37+
}
38+
}
39+
1540
func flattenConditionalAccessConditionSet(in *stable.ConditionalAccessConditionSet) []interface{} {
1641
if in == nil {
1742
return []interface{}{}
@@ -78,6 +103,7 @@ func flattenConditionalAccessClientApplications(in *stable.ConditionalAccessClie
78103
map[string]interface{}{
79104
"included_service_principals": tf.FlattenStringSlicePtr(in.IncludeServicePrincipals),
80105
"excluded_service_principals": tf.FlattenStringSlicePtr(in.ExcludeServicePrincipals),
106+
"filter": flattenConditionalAccessFilter(in.ServicePrincipalFilter),
81107
},
82108
}
83109
}
@@ -108,7 +134,7 @@ func flattenConditionalAccessDevices(in *stable.ConditionalAccessDevices) []inte
108134

109135
return []interface{}{
110136
map[string]interface{}{
111-
"filter": flattenConditionalAccessDeviceFilter(in.DeviceFilter),
137+
"filter": flattenConditionalAccessFilter(in.DeviceFilter),
112138
},
113139
}
114140
}
@@ -228,7 +254,7 @@ func flattenConditionalAccessSessionControls(in *stable.ConditionalAccessSession
228254
}
229255
}
230256

231-
func flattenConditionalAccessDeviceFilter(in *stable.ConditionalAccessFilter) []interface{} {
257+
func flattenConditionalAccessFilter(in *stable.ConditionalAccessFilter) []interface{} {
232258
if in == nil {
233259
return []interface{}{}
234260
}
@@ -401,10 +427,15 @@ func expandConditionalAccessClientApplications(in []interface{}) *stable.Conditi
401427

402428
includeServicePrincipals := config["included_service_principals"].([]interface{})
403429
excludeServicePrincipals := config["excluded_service_principals"].([]interface{})
430+
servicePrincipalFilter := config["filter"].([]interface{})
404431

405432
result.IncludeServicePrincipals = tf.ExpandStringSlicePtr(includeServicePrincipals)
406433
result.ExcludeServicePrincipals = tf.ExpandStringSlicePtr(excludeServicePrincipals)
407434

435+
if len(servicePrincipalFilter) > 0 {
436+
result.ServicePrincipalFilter = expandConditionalAccessFilter(servicePrincipalFilter)
437+
}
438+
408439
return &result
409440
}
410441

vendor/github.com/hashicorp/go-azure-sdk/microsoft-graph/common-types/stable/model_conditionalaccessclientapplications.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/hashicorp/go-azure-sdk/sdk/client/client.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/hashicorp/go-azure-sdk/sdk/client/msgraph/client.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)