Open plans as Terraform pull requests

A GitHub token and a review rule, so plans arrive as pull requests in your repository.

On this page

Before you begin

  • Admin access to the GitHub repository that holds your Okta Terraform.
  • An EntiPath owner or admin account.
  • Okta connected to EntiPath, and Okta’s group rules managed in Terraform.

It takes about 10 minutes.

If Okta’s group rules are managed with Terraform, EntiPath sends rule plans to your repository as pull requests, with the proof of what each does to people in the description. Your pipeline applies them; EntiPath never runs Terraform.

Note. Once a repository is connected, rule changes go only through pull requests, so Okta and the repository can’t drift apart through EntiPath. Plans on one person (profile values from HR) still go through the Okta API.

What EntiPath can edit

EntiPath finds group rules written either way, and edits only their expression and their excluded people:

  • okta_group_rule resources in .tf files, with name and expression_value written as plain strings.
  • Entries in a JSON file the Terraform reads, each with a string name and expression_value.

It can’t edit an expression built from variables, locals, heredocs or interpolation, a rule defined in more than one file, or two rules with the same name. Excluding people adds their Okta user ids to users_excluded, which must be a plain list.

Note. EntiPath skips test, fixture, example and testdata folders, .terraform and node_modules, JSON files over 512 KB, and anything past the first 300 files.
1

Create a GitHub token

In GitHub

  1. Open a new fine-grained personal access token.
  2. Set Resource owner to whoever owns the repository.
  3. Under Repository access, choose Only select repositories and pick the repository.
  4. Under Repository permissions, set these:
    Contents
    Read and write
    Reads your .tf files and commits each plan on a new branch
    Pull requests
    Read and write
    Opens the pull request and shows its reviews on the plan
    Administration
    Read-only
    Checks the review rule from part 2; it can’t change it
  5. Create the token, and copy it when GitHub shows it.
Note. If an organization owns the repository and approves tokens, one of its owners approves it first. Note the token’s expiry: when it expires, pull requests can’t be opened until you paste a new one.
2

Require reviews on the base branch

In GitHub, in the repository’s settings

EntiPath only opens pull requests that nobody can merge without an independent review.

  1. Open Settings › Rules › Rulesets.
  2. Click New ruleset › New branch ruleset.
  3. Set these:
    Enforcement status
    Active
    Bypass list
    Empty, so nobody skips the review, admins included
    Target branches
    Add target › Include default branch, or your base branch
    Require a pull request before merging
    On, with Required approvals set to 1 or more
    Dismiss stale pull request approvals when new commits are pushed
    On
  4. Click Create.
Before you go on, the ruleset has0 of 6
Note. A classic branch protection rule works too, if it requires the same, has Do not allow bypassing the above settings ticked, and allows nobody to bypass pull requests.
3

Connect the repository in EntiPath

In EntiPath

  1. Open Integrations, then your Okta org.
  2. Open the Applying plans tab.
  3. Under As Terraform pull requests, fill in:
    Owner
    The owner from the repository’s address, github.com/owner/repository
    Repository
    The repository’s name from the same address
    Base branch
    The branch from part 2
    Folder
    Where the Okta .tf files and any JSON they read are. Empty for the whole repository.
    GitHub token
    The token from part 1
  4. Click Check and save.The card says GitHub reviews verified, how many group rules it found, and how many have a plain name and expression EntiPath can edit.
The As Terraform pull requests card in EntiPath, with the Owner, Repository, Base branch, Folder and GitHub token fields
Note. Owners and admins can connect it. The same card is also under Settings › Agent. If the review check fails, the repository is still saved, but no pull request opens until the check passes; see Troubleshooting below.
4

What happens with each plan

In EntiPath and GitHub

  1. Someone sends a plan to GitHub. On a paid plan, a draft can go straight there with Send to GitHub; during the trial, and for plans that approval rules cover, it’s approved in EntiPath first. EntiPath checks the review rule again before writing anything.
  2. The pull request is opened as the token’s owner, so someone else approves it: GitHub doesn’t let anyone approve their own.
  3. Merging it is the approval, and your pipeline applies it to Okta. The plan shows Merged.
  4. The next Okta sync (scheduled, or Sync now) confirms Okta matches the plan, and the plan shows Done, or Okta differs if it doesn’t.

Withdrawing or undoing a plan

  • Closing the pull request without merging withdraws the plan.
  • Withdraw on the plan comments on the pull request, closes it and deletes its branch. Once merged, it can’t be withdrawn.
  • To undo a merged plan, revert the pull request in GitHub; the plan links to it. There’s no Undo in Okta for Terraform plans.
Note. The agent can read the repository and draft pull requests too; a person opens each one from its plan.

Changing or removing it

Change

Change edits the repository, branch or folder. Paste the token again to save, which is also how you replace an expiring token.

Remove

Remove deletes the stored token. Pull requests already open stay open in GitHub: close them there, and revoke the token in GitHub too.

Troubleshooting

Find the message EntiPath showed. Each one says why it happens and how to fix it.

“The GitHub token can’t read main’s branch protection (GitHub answered 403)”

The token is missing Administration: Read-only, so EntiPath can’t see the branch’s protection.

To fix it
  1. In GitHub, edit the token and add Administration: Read-only, as in part 1. It keeps its value, so there’s nothing to paste again.
  2. Click Check again.
  3. If the message also says no ruleset requires reviews, add the ruleset in part 2 as well.
“main has no protection that requires reviews”

Nothing on the branch requires a review yet.

To fix it
  1. Add the ruleset in part 2.
  2. Click Check again.
“No ruleset requires pull request reviews on main” or “main has no branch protection rule”

No ruleset requires pull request reviews on the base branch.

To fix it
  1. Add the ruleset in part 2, and check it targets the base branch you set.
  2. Click Check again.
“… has bypass actors …” or “… has bypass allowances …”

Someone can skip the review.

To fix it
  1. For a ruleset, empty its Bypass list.
  2. For a branch protection rule, tick Do not allow bypassing the above settings and remove anyone allowed to bypass pull requests.
  3. Click Check again.
“Review rulesets must require at least one approval …”

A review ruleset must require at least one approval and dismiss stale approvals, with nobody able to bypass it.

To fix it
  1. In the ruleset, set Required approvals to 1 or more.
  2. Tick Dismiss stale pull request approvals when new commits are pushed.
“Classic branch protection must require approvals …”

A branch protection rule must require approvals, dismiss stale approvals, and apply to administrators too.

To fix it
  1. Turn on Require approvals, with 1 or more.
  2. Tick Dismiss stale pull request approvals and Do not allow bypassing the above settings.
  3. Or use a ruleset, as in part 2, instead.
“… could not be read” or “… could not be verified with this token”

EntiPath couldn’t read part of the rules, often a ruleset set on the organization rather than the repository.

To fix it
  1. Check the token has Administration: Read-only on this repository.
  2. Click Check again.
“Verify the repository’s mandatory GitHub review policy …”

The review check hasn’t passed, so EntiPath won’t write to the repository.

To fix it
  1. Open the integration’s Applying plans tab.
  2. Fix what the check says.
  3. Click Check again.
“The token can read the repository but not push to it”

The token can read the repository but not push to it.

To fix it
  1. Give the token Contents and Pull requests Read and write, as in part 1.
“… failed (401): the token is invalid or expired”

The token is wrong or has expired.

To fix it
  1. Create a new one, as in part 1.
  2. Click Change under As Terraform pull requests and paste it.
“… failed (403 or 404): the token cannot see this repository …”

GitHub couldn’t find the repository or branch for this token.

To fix it
  1. Check the token’s Repository access includes the repository, and its permissions match part 1.
  2. Check the Owner, Repository and Base branch are spelled exactly as in GitHub.
“Use the GitHub owner or repository name”

Owner and Repository take just the names from the address, such as acme and okta-terraform, not the whole URL.

To fix it
  1. Enter only the names, then save again.
“No group rules found in …”

EntiPath found no rules it recognises in the folder you set (see What EntiPath can edit).

To fix it
  1. Check the folder. Plans can still open pull requests once rules are managed there.
“No group rule named … with a plain expression was found” or “… cannot be edited”

The rule exists, but not in a form EntiPath can edit: its expression is built from variables, locals or interpolation, or it changed in the repository after the plan was made.

To fix it
  1. Write the expression as a plain string, or make the change by hand.
  2. Check the plan again.
“… is defined in N places …”

The same rule name appears in more than one file.

To fix it
  1. Set the integration’s Folder to the one your Terraform applies.
“users_excluded … is not a plain list”

EntiPath adds excluded people to users_excluded, so it must be a plain list of ids, not built from a variable.

To fix it
  1. Write users_excluded as a list, or exclude the people by hand.
You can’t approve the pull request in GitHub

The pull request was opened as the token’s owner, and GitHub doesn’t let anyone approve their own.

To fix it
  1. Ask anyone else with write access to the repository to approve it.

Still stuck? Email support@entipath.com with your workspace address and the message EntiPath showed.