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

CustomDiff for status on okta_group_rule #1813

Merged
merged 1 commit into from
Nov 15, 2023
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
11 changes: 5 additions & 6 deletions okta/resource_okta_group_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ func resourceGroupRule() *schema.Resource {
},
},
CustomizeDiff: customdiff.ForceNewIf("status", func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool {
g, _, _ := getOktaClientFromMetadata(meta).Group.GetGroupRule(ctx, d.Id(), nil)
if g == nil {
return false
}
_ = d.SetNew("status", g.Status)
return d.Get("status").(string) == statusInvalid
return statusIsInvalidDiffFn(d.Get("status").(string))
}),
}
}

func statusIsInvalidDiffFn(status string) bool {
return status == statusInvalid
}

func resourceGroupRuleCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
ctx = context.WithValue(ctx, retryOnStatusCodes, []int{http.StatusInternalServerError})
groupRule := buildGroupRule(d)
Expand Down
23 changes: 23 additions & 0 deletions okta/resource_okta_group_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/stretchr/testify/require"
)

func TestAccResourceOktaGroupRule_crud(t *testing.T) {
Expand Down Expand Up @@ -170,3 +171,25 @@ func doesGroupRuleExist(id string) (bool, error) {

return doesResourceExist(response, err)
}

func TestAccResourceOktaGroupRule_statusIsInvalidDiffFn(t *testing.T) {
cases := []struct {
status string
expected bool
}{
{
status: "VALID",
expected: false,
},
{
status: "INVALID",
expected: true,
},
}
for _, tc := range cases {
t.Run(tc.status, func(t *testing.T) {
result := statusIsInvalidDiffFn(tc.status)
require.EqualValues(t, tc.expected, result)
})
}
}
4 changes: 4 additions & 0 deletions website/docs/r/group_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Creates an Okta Group Rule.

This resource allows you to create and configure an Okta Group Rule.

-> If the Okta API marks the `status` of the rule as `INVALID` the Okta
Terraform Provider will act in a force/replace manner and call the API to delete
the underlying rule resource and create a new rule resource.

## Example Usage

```hcl
Expand Down