Introduction
Last week we discussed what went into Terraform and Github Pipelines, and Okta workspaces. A brief summary is below.
Key Points
Workspace Segmentation
- Dividing infrastructure into distinct workspaces to scale and prevent configuration drift.
- Core Stack: Critical components like automation scripts, groups, applications, policies, and core infrastructure.
- Standard Stack: Non-critical elements such as contributions from other teams, branding, and less essential applications.
Development Workflow
- Develop: Individual local environments for initial development.
- Feature/Change Validation: Testing and quality assurance in a preview environment.
- Release: Deployment to the production environment.
Branch Protection
- Enforces branch protection policies on main (production) branches to ensure stability.
- Development and testing occur in separate branches to mitigate risks.
Multiple Repositories and Workspaces
- Using multiple GitHub repositories and Terraform workspaces for self-contained modules.
- Facilitates automated runs and reduces interdependencies.
Personal Development Tenants
- Team members maintain personal tenants for local Terraform development.
- Promotes isolated testing and minimizes the impact on shared environments.
The blog post outlines a structured approach to scaling and automating Okta environments using Terraform. The segmentation, workflow, and use of personal tenants create a scalable, organized framework that balances control with flexibility for growth.
This blog post, will generally go over scaling our Department Groups using Terraform automatically, and using Group Rules to do so. This includes a break down of the code, and the pieces for each.
The Implementation
Now let’s get on to the configuration.
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.
Automate Business Line Creation of Groups and their Memberships
One of the trickier methods for us to accomplish. We have a large structure for our business lines, which can change anytime. We have 200+ business line structures that decline and expand depending on business needs. We also have had severe amounts of Tech Debt, which we have been slowly cleaning up.
Requirements
- An internal immutable reference ID for an object, which means that the ID cannot change.
- The ability to manage or control the change management of the groups, while still being able to automate everything within the group.
- Have an external system managing the organization of teams (such as NetSuite, Workday, BambooHR, a Database system, etc).
- Groups have a naming scheme or policy that is easy to read, follow, and use by other company employees.
So how did we plan this?
First, we need to determine the data for each user. We could do this in various ways, but if we have a source of truth that is already feeding us this data, why not just query Okta directly for that information?
To make this easy, you can start that query with the following:
|
|
But let’s say we have a new inbound employee in the pipeline who will be a part of a new team that has not yet been created in Okta. Well, then, we need to also search for Staged and Provisioned users:
|
|
That’s great. We now have a query of all Okta users with this data. How can we work with all of it simultaneously without worrying about individual resources?
The below helps us take information out.
|
|
This allows us to consolidate the list of data and start working off a single object. Which is much better for us in the long term as we begin to work with more significant amounts of data.
So now that we have this data consolidated in a way that we can read and is easy to work with, how do we start picking out the data we need to actually work with and manipulate? Remember that the search takes all Okta data, and we don’t care about it; it only takes bits and pieces.
And because we are also working with the requirement that a Key ID belong to and map/match to its corresponding Readable Name for the business structure, how do we ensure that the data doesn’t shift incorrectly?
We need to map the data.
|
|
The easier way to read this is below:
Level | ID Attribute | Non-ID Attribute | Prefix |
---|---|---|---|
Cost Center | companynameBkeyIdCostCenter | companynameCostCenter | companyname-cc |
Division | companynameBkeyIdDivision | companynameDivison | companyname-div |
The items in the first row are our key components, and each line represents what they are and where they should be placed within the mapping.
So now that we have our list of mappings and how we want to process and manipulate the data structure, we need to generate the data from those mappings.
We do that by running through extracting and manipulating the data:
|
|
From there, we do a for_each loop over the generated tuple to output the desired results and groups.
The complete code
The complete section of the code is as follows:
|
|
Info
You will see some custom Group Schema Attributes; you could remove them from the code, add them to your local group schema, or edit them to suit your needs.
Now, if we ever need to prevent the destruction of any of these groups or the group rules, we can always add the following into the resources blocks:
|
|
Meaning, we have a fully automated group management system that can only be destroyed if we desire to do so. If we need to be modular so that only certain group Hierarchies are not destroyed, we can manipulate the code base to have an “if present” statement and make a “True” or “False” option in the mapping for the level.
Additionally, we can always switch this from Group Rules, which have their own scaling problems within Okta, to manual group assignment, as we have all of the user data. If we do this, we must swap out the group rule assignments and create a more complex assignment system using the okta_group_membership
resource. This will be covered in a different blog post once we approach that.
Update
Since writing this, we have improved a few things. For example, what if you need to also manually write in new business lines and teams?
|
|
Is all that is needed at the top, and then you would just concatenate the manual list of entries into the existing structure. This way, if a business line get’s added, we can manually remove the entry and keep it updated going forward automatically with the rest of the structure.
I won’t be able to post the full list of updates we have done, but, this should be sufficient to get you started.
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 core Okta Groups.
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.