Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
resource_group_rule: in case expression is changed on ACTIVE rule, de…
Browse files Browse the repository at this point in the history
…activate it prior to changing.
  • Loading branch information
salekseev committed Apr 25, 2019
1 parent 9f032c5 commit 00b4d64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/okta_group_rule/basic_updated.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ resource "okta_group_rule" "test" {
status = "ACTIVE"
group_assignments = ["${okta_group.test_other.id}"]
expression_type = "urn:okta:expression:1.0"
expression_value = "String.startsWith(user.articulateId,\"auth0|\")"
expression_value = "String.startsWith(user.articulateId,String.toLowerCase(\"auth0|\"))"
}
17 changes: 13 additions & 4 deletions okta/resource_group_rule.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package okta

import (
"errors"
"net/http"

"github.com/okta/okta-sdk-golang/okta"
Expand Down Expand Up @@ -129,15 +128,25 @@ func resourceGroupRuleUpdate(d *schema.ResourceData, m interface{}) error {
}

if hasGroupRuleChange(d) {
client := getOktaClientFromMetadata(m)
rule := buildGroupRule(d)

if status == "ACTIVE" {
return errors.New("an active rule cannot be modified, set status to INACTIVE with any other changes")
// Only inactive rules can be changed, thus we should deactivate the rule in case it was "ACTIVE"
_, err := client.Group.DeactivateRule(d.Id())
return err
}

rule := buildGroupRule(d)
_, _, err := getOktaClientFromMetadata(m).Group.UpdateRule(d.Id(), *rule)
_, _, err := client.Group.UpdateRule(d.Id(), *rule)
if err != nil {
return err
}

if status == "ACTIVE" {
// We should reactivate the rule in case it was deactivated.
_, err := client.Group.ActivateRule(d.Id())
return err
}
}

return resourceGroupRuleRead(d, m)
Expand Down

0 comments on commit 00b4d64

Please sign in to comment.