Skip to content

Commit 3e47611

Browse files
authored
adds support for office365Client config in signon_policy_rule resource (#2644)
1 parent 24922a5 commit 3e47611

7 files changed

Lines changed: 815 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "okta_app_signon_policy" "test" {
2+
name = "testAcc_replace_with_uuid"
3+
description = "Test policy for office365_client_include"
4+
}
5+
6+
resource "okta_app_signon_policy_rule" "test" {
7+
policy_id = okta_app_signon_policy.test.id
8+
name = "testAcc_replace_with_uuid"
9+
office365_client_include = ["WEB", "MODERN_AUTH"]
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "okta_app_signon_policy" "test" {
2+
name = "testAcc_replace_with_uuid"
3+
description = "Test policy for office365_client_include"
4+
}
5+
6+
resource "okta_app_signon_policy_rule" "test" {
7+
policy_id = okta_app_signon_policy.test.id
8+
name = "testAcc_replace_with_uuid"
9+
office365_client_include = ["WEB", "MODERN_AUTH", "AAD_JOIN"]
10+
}

okta/services/idaas/resource_okta_app_signon_policy_rule.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ The only difference is that these fields are immutable and can not be managed: '
261261
Optional: true,
262262
Description: "Use with verification method = `AUTH_METHOD_CHAIN` only",
263263
},
264+
"office365_client_include": {
265+
Type: schema.TypeSet,
266+
Optional: true,
267+
Description: "Office 365 client types to include. Valid values: WEB, MODERN_AUTH, EXCHANGE_ACTIVE_SYNC, AAD_JOIN. This condition is specific to Office 365 applications.",
268+
Elem: &schema.Schema{
269+
Type: schema.TypeString,
270+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"WEB", "MODERN_AUTH", "EXCHANGE_ACTIVE_SYNC", "AAD_JOIN"}, false)),
271+
},
272+
},
264273
},
265274
}
266275
}
@@ -390,6 +399,13 @@ func resourceAppSignOnPolicyRuleRead(ctx context.Context, d *schema.ResourceData
390399
_ = d.Set("risk_score", rule.Conditions.RiskScore.Level)
391400
}
392401
_ = utils.SetNonPrimitives(d, m)
402+
var office365Includes []interface{}
403+
if rule.Conditions.Office365Client != nil {
404+
for _, v := range rule.Conditions.Office365Client.Include {
405+
office365Includes = append(office365Includes, v)
406+
}
407+
}
408+
_ = d.Set("office365_client_include", schema.NewSet(schema.HashString, office365Includes))
393409
}
394410
return nil
395411
}
@@ -569,6 +585,12 @@ func buildAppSignOnPolicyRule(d *schema.ResourceData) sdk.AccessPolicyRule {
569585
Include: utils.ConvertInterfaceToStringSetNullable(userTypesIncluded),
570586
}
571587
}
588+
office365ClientInclude, office365ClientIncludeOk := d.GetOk("office365_client_include")
589+
if office365ClientIncludeOk {
590+
rule.Conditions.Office365Client = &sdk.Office365ClientCondition{
591+
Include: utils.ConvertInterfaceToStringSetNullable(office365ClientInclude),
592+
}
593+
}
572594
return rule
573595
}
574596

okta/services/idaas/resource_okta_app_signon_policy_rule_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,3 +861,48 @@ func TestAccResourceOktaAppSignOnPolicyRule_keep_me_signed_in_drift(t *testing.T
861861
},
862862
})
863863
}
864+
865+
func TestAccResourceOktaAppSignOnPolicyRule_office365_client_include(t *testing.T) {
866+
mgr := newFixtureManager("resources", resources.OktaIDaaSAppSignOnPolicyRule, t.Name())
867+
resourceName := fmt.Sprintf("%s.test", resources.OktaIDaaSAppSignOnPolicyRule)
868+
config := mgr.GetFixtures("office365_client_include.tf", t)
869+
updatedConfig := mgr.GetFixtures("office365_client_include_updated.tf", t)
870+
871+
acctest.OktaResourceTest(t, resource.TestCase{
872+
PreCheck: acctest.AccPreCheck(t),
873+
ErrorCheck: testAccErrorChecks(t),
874+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactoriesForTestAcc(t),
875+
CheckDestroy: checkAppSignOnPolicyRuleDestroy,
876+
Steps: []resource.TestStep{
877+
{
878+
Config: config,
879+
Check: resource.ComposeTestCheckFunc(
880+
resource.TestCheckResourceAttr(resourceName, "office365_client_include.#", "2"),
881+
resource.TestCheckTypeSetElemAttr(resourceName, "office365_client_include.*", "WEB"),
882+
resource.TestCheckTypeSetElemAttr(resourceName, "office365_client_include.*", "MODERN_AUTH"),
883+
),
884+
},
885+
{
886+
Config: updatedConfig,
887+
Check: resource.ComposeTestCheckFunc(
888+
resource.TestCheckResourceAttr(resourceName, "office365_client_include.#", "3"),
889+
resource.TestCheckTypeSetElemAttr(resourceName, "office365_client_include.*", "WEB"),
890+
resource.TestCheckTypeSetElemAttr(resourceName, "office365_client_include.*", "MODERN_AUTH"),
891+
resource.TestCheckTypeSetElemAttr(resourceName, "office365_client_include.*", "AAD_JOIN"),
892+
),
893+
},
894+
{
895+
ResourceName: resourceName,
896+
ImportState: true,
897+
ImportStateVerify: true,
898+
ImportStateIdFunc: func(s *terraform.State) (string, error) {
899+
rs, ok := s.RootModule().Resources[resourceName]
900+
if !ok {
901+
return "", fmt.Errorf("failed to find app sign on policy rule %s", resourceName)
902+
}
903+
return fmt.Sprintf("%s/%s", rs.Primary.Attributes["policy_id"], rs.Primary.Attributes["id"]), nil
904+
},
905+
},
906+
},
907+
})
908+
}

sdk/v2_accessPolicyRuleConditions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type AccessPolicyRuleConditions struct {
2525
Users *UserPolicyRuleCondition `json:"users,omitempty"`
2626
ElCondition *AccessPolicyRuleCustomCondition `json:"elCondition,omitempty"`
2727
UserType *UserTypeCondition `json:"userType,omitempty"`
28+
Office365Client *Office365ClientCondition `json:"office365Client,omitempty"`
2829
}
2930

3031
func NewAccessPolicyRuleConditions() *AccessPolicyRuleConditions {

sdk/v2_office365ClientCondition.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// DO NOT EDIT LOCAL SDK - USE v3 okta-sdk-golang FOR API CALLS THAT DO NOT EXIST IN LOCAL SDK
2+
package sdk
3+
4+
// Office365ClientCondition represents the Office 365 client condition for access policy rules.
5+
// This condition allows filtering based on Office 365 client types such as WEB, MODERN_AUTH, AAD_JOIN, etc.
6+
type Office365ClientCondition struct {
7+
Include []string `json:"include,omitempty"`
8+
}
9+
10+
func NewOffice365ClientCondition() *Office365ClientCondition {
11+
return &Office365ClientCondition{}
12+
}
13+
14+
func (a *Office365ClientCondition) IsPolicyInstance() bool {
15+
return true
16+
}

0 commit comments

Comments
 (0)