Introduction
Last week we went over the following:
- Overview: Automating group memberships and business line structures using Terraform.
- Group Memberships: Consolidate user data from Okta queries for efficient processing.
- Business Line Groups: Manage 200+ dynamic business line structures via Terraform.
- Key Requirements: Immutable IDs, change control, external data sources, and clear naming policies.
- Data Consolidation: Query and combine user statuses into a single dataset for simplicity.
- Attribute Mapping: Map business structure levels (e.g., Cost Center, Division) with IDs and names.
- Dynamic Groups: Automatically create and manage groups and rules using mapped attributes.
- Flexibility: Prevent resource deletion with
lifecycle { prevent_destroy = true }
when needed.- Future Topics: Transitioning to manual group assignments with
okta_group_membership
.- Resources: Join
#okta-terraform
on MacAdmins for community support and ideas.
This week, we will be discussing how to automate and manage core groups to the business.
The Implementation
Automate Group Memberships
A good group structure is one of the most important things you can have. This seems like the most straightforward task, but given the chaos of groups and organizational structures inside a company, it is anything but that. Below, I outline the complications we experienced and how we built it using Terraform.
Some of this was done with the help of ChatGPT, for example, by creating lowercase, hyphenated names of cities, offices, countries, etc. However, this is still completely doable without the use of ChatGPT.
Managing Key / Core Group Memberships
We will manage several key groups via Terraform, which Okta uses to push to downstream services / systems.
First, we need to import the groups we want to manage. We will use the import resource rather than an import CLI Command.
|
|
Getting this information for groups is easy enough, but what do we do about Group Rules? It’s a bit trickier to obtain their IDs. We have two options:
- Go to the group rules URL, open the Network Inspection tool, and expand/minimize the group rule you are concerned about. This will produce a URL like this: https://$subdomain.okta.com/api/v1/groups?filter=id+eq+%2200gq516ejcp3Jbgm74x6%22
With the URL, what we are specifically after is ?filter=id+eq+%2200gq516ejcp3Jbgm74x6%22
and the bits immediately after and before the %22
, which will return; 00gq516ejcp3Jbgm74x6
OR
- Generate an API key, and query the following API Endpoint:
https://{yourOktaDomain}/api/v1/groups/rules
, which will return the following (an example taken from Okta’s Developer Documents):
|
|
Then, you can just pick the ID from the API response. We found that it is easier to generate a list or use a module to create the groups and group rules we have so that their naming policies match:
|
|
This way, we still maintain flexibility.
We can also keep group rules without a corresponding Terraform-managed group in the same file with its own list of local data.
Automate Office Groups
This is honestly fairly simple to achieve. The largest issue or problem is just getting accurate data and maintaining that data.
|
|
To advance on this, we could utilize several different features that could help us automatically obtain and manage the data and automatically create a JSON using something like csvdecode
, which is a native Terraform function.
Automate Country Groups
Automating countries is a bit more tricky. You need to verify a few things first:
- Do you want to use the country’s English-based name or its local variant?
- How do you plan on using colloquial names for a country?
- An example of this is
South Korea
. While commonly and generally referred to asSouth Korea
, it is officially known asRepublic of Korea
and is represented this way in international standardization.
- An example of this is
- How do you want to deal with non-ASCII characters? For example, do they appear in the Latin alphabet or in UTF-8, 16, or 32?
- For example,
Côte d'Ivoire
may produce problems for usability, even if it is an officially recognized name. What isthe Holy See
? Would you know that this is actuallyVatican City
?
- For example,
Considering some of these, I recommend following the ISO3166 documentation as much as possible and adding an Alt_Name
field to your local values to allow the description to be written with the more common equivalent of the name.
|
|
From here, again, we can use a variety of local exec resources, to be able to download and obtain the lists of countries from whatever system we are using so that this can be updated automatically. Alerts can be fired off when a drift or apply change behavior is found that would either delete or add new entities in the state.
Unfortunately, Terraform and Okta don’t have transliterate functionality, so there is no way to achieve the possibility of something like this natively in either service. You could, however, add this as a pre-hook in a Git commit or a GitHub action.
Automate Legal Entities
If you need to automate legal entities, while we have code for this, there isn’t much of a change in any of the codes above.
Come up with a scheme that can be followed and easily adjusted for your needs while sticking with the naming standard that the business owner of the legal entities (likely FP&A, Finance, Legal, etc.) maintains.
And that is it
Thanks for taking the time to read this, be on the lookout next week for another blog post about automating and managing Network Zones (EG: Policy Network Zones, Blocklist Network Zones, proxies, office networks, etc).
A lot will be covered over the next several parts, which sums up how we have terraformed certain pieces of our Okta environment. If you have questions and are looking for a community resource, I would heavily recommend reaching out to #okta-terraform
on MacAdmins, as I would say at least 30% (note, I made this statistic up) of the organizations using Terraform hang out in this channel. Otherwise, you can always find an alternative unofficial community for assistance or ideas.