Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azuread_conditional_access_policy: make platform and location optional, require one of included_applications or included_user_actions #775

Merged
merged 4 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/resources/conditional_access_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ The following arguments are supported:
`applications` block supports the following:

* `excluded_applications` - (Optional) A list of application IDs explicitly excluded from the policy.
* `included_applications` - (Required) A list of application IDs the policy applies to, unless explicitly excluded (in `excluded_applications`). Can also be set to `All`.
* `included_user_actions` - (Optional) A list of user actions to include. Supported values are `urn:user:registersecurityinfo` and `urn:user:registerdevice`.
* `included_applications` - (Optional) A list of application IDs the policy applies to, unless explicitly excluded (in `excluded_applications`). Can also be set to `All`. Cannot be specified with `included_user_actions`. One of `included_applications` or `included_user_actions` must be specified.
* `included_user_actions` - (Optional) A list of user actions to include. Supported values are `urn:user:registerdevice` and `urn:user:registersecurityinfo`. Cannot be specified with `included_applications`. One of `included_applications` or `included_user_actions` must be specified.

---

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.13.0
github.com/manicminer/hamilton v0.43.0
github.com/manicminer/hamilton v0.45.0
golang.org/x/text v0.3.7
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/manicminer/hamilton v0.43.0 h1:X/XrzLWFhPx1mlLBycqgKRcIjM9vfCd/QR5YnJKIDTI=
github.com/manicminer/hamilton v0.43.0/go.mod h1:lbVyngC+/nCWuDp8UhC6Bw+bh7jcP/E+YwqzHTmzemk=
github.com/manicminer/hamilton v0.45.0 h1:LSbKARKc7pRVZaD1MEkyVDdm7fmgkZSnSobWn1xDYog=
github.com/manicminer/hamilton v0.45.0/go.mod h1:lbVyngC+/nCWuDp8UhC6Bw+bh7jcP/E+YwqzHTmzemk=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ func conditionalAccessPolicyResource() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"included_applications": {
Type: schema.TypeList,
Required: true,
Type: schema.TypeList,
Optional: true,
ExactlyOneOf: []string{"conditions.0.applications.0.included_applications", "conditions.0.applications.0.included_user_actions"},
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateDiagFunc: validate.NoEmptyStrings,
Expand All @@ -94,8 +95,9 @@ func conditionalAccessPolicyResource() *schema.Resource {
},

"included_user_actions": {
Type: schema.TypeList,
Optional: true,
Type: schema.TypeList,
Optional: true,
ExactlyOneOf: []string{"conditions.0.applications.0.included_applications", "conditions.0.applications.0.included_user_actions"},
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateDiagFunc: validate.NoEmptyStrings,
Expand Down Expand Up @@ -222,7 +224,7 @@ func conditionalAccessPolicyResource() *schema.Resource {

"locations": {
Type: schema.TypeList,
Required: true,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -249,7 +251,7 @@ func conditionalAccessPolicyResource() *schema.Resource {

"platforms": {
Type: schema.TypeList,
Required: true,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -324,6 +326,7 @@ func conditionalAccessPolicyResource() *schema.Resource {
},
},
},

"grant_controls": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -374,6 +377,7 @@ func conditionalAccessPolicyResource() *schema.Resource {
},
},
},

"session_controls": {
Type: schema.TypeList,
Optional: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,35 @@ func TestAccConditionalAccessPolicy_deviceFilter(t *testing.T) {
})
}

func TestAccConditionalAccessPolicy_includedUserActions(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_conditional_access_policy", "test")
r := ConditionalAccessPolicyResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.includedUserActions(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.includedUserActions(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccConditionalAccessPolicy_sessionControls(t *testing.T) {
// This is in a separate test to avoid ForceNew in the update test due to https://github.com/microsoftgraph/msgraph-metadata/issues/93
// session_controls can be added to the complete config, and this rest removed, when this issue is resolved
Expand Down Expand Up @@ -272,14 +301,6 @@ resource "azuread_conditional_access_policy" "test" {
included_applications = ["All"]
}

locations {
included_locations = ["All"]
}

platforms {
included_platforms = ["all"]
}

users {
included_users = ["All"]
excluded_users = ["GuestsOrExternalUsers"]
Expand Down Expand Up @@ -414,6 +435,41 @@ resource "azuread_conditional_access_policy" "test" {
operator = "OR"
built_in_controls = ["block"]
}

}
`, data.RandomInteger)
}

func (ConditionalAccessPolicyResource) includedUserActions(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azuread_conditional_access_policy" "test" {
display_name = "acctest-CONPOLICY-%[1]d"
state = "disabled"

conditions {
client_app_types = ["all"]

applications {
included_user_actions = [
"urn:user:registerdevice",
"urn:user:registersecurityinfo",
]
}

locations {
included_locations = ["All"]
}

users {
included_users = ["All"]
excluded_users = ["GuestsOrExternalUsers"]
}
}

grant_controls {
operator = "OR"
built_in_controls = ["mfa"]
}
}
`, data.RandomInteger)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/services/conditionalaccess/conditionalaccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func expandConditionalAccessUsers(in []interface{}) *msgraph.ConditionalAccessUs
func expandConditionalAccessPlatforms(in []interface{}) *msgraph.ConditionalAccessPlatforms {
result := msgraph.ConditionalAccessPlatforms{}
if len(in) == 0 || in[0] == nil {
return &result
return nil
}

config := in[0].(map[string]interface{})
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions vendor/github.com/manicminer/hamilton/msgraph/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ github.com/hashicorp/terraform-svchost
# github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87
## explicit; go 1.15
github.com/hashicorp/yamux
# github.com/manicminer/hamilton v0.43.0
# github.com/manicminer/hamilton v0.45.0
## explicit; go 1.16
github.com/manicminer/hamilton/auth
github.com/manicminer/hamilton/environments
Expand Down