You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: _source/_posts/2025-01-09-terraform-powershell-lab.md
+28-56
Original file line number
Diff line number
Diff line change
@@ -12,20 +12,16 @@ tweets:
12
12
- ""
13
13
image: blog/terraform-powershell-lab/image.jpg
14
14
type: awareness
15
+
---
15
16
16
17
At Oktane 2024, we offered a lab session to teach the basics of automating Okta administration tasks with Terraform and PowerShell. This blog post will walk you through the content taught in that lab so you can follow along at your own pace to get some hands-on experience managing an Okta tenant with both tools.
17
18
18
19
This lab includes some Scenario sections to give realistic examples of a situation where you might perform each task. You can ignore these sections if you don't find them helpful.
19
20
20
21
## Background
21
-
PowerShell is an excellent introductory tool for general automation tasks. It is easier to set up
22
-
but can require extensive customization to integrate with a more complete infrastructure-as-
23
-
code solution. In this lab, the focus will be on reading data with PowerShell, but it is a general-
24
-
purpose tool that can read from and write to Okta when configured with the appropriate scopes.
22
+
PowerShell is an excellent introductory tool for general automation tasks. It is easier to set up but can require extensive customization to integrate with a more complete infrastructure-as-code solution. In this lab, the focus will be on reading data with PowerShell, but it is a general-purpose tool that can read from and write to Okta when configured with the appropriate scopes.
25
23
26
-
Terraform is a specialized tool for developing infrastructure as code. Terraform requires more
27
-
setup steps than PowerShell, but adding Okta management to an existing Terraform
28
-
deployment is more straightforward than designing a new solution with PowerShell.
24
+
Terraform is a specialized tool for developing infrastructure as code. Terraform requires more setup steps than PowerShell, but adding Okta management to an existing Terraform deployment is more straightforward than designing a new solution with PowerShell.
29
25
30
26
## How to create your lab environment
31
27
@@ -39,29 +35,22 @@ You can follow these steps on any computer where you're able to install the foll
39
35
Note: Free trial accounts expire after 30 days, but developer accounts do not expire.
40
36
41
37
To use Terraform, you'll run commands in a terminal. You can even use a PowerShell window if you don't have a favorite terminal!
38
+
42
39
If this is your first time writing code, you might want to install an IDE like [Visual Studio](https://code.visualstudio.com/docs/introvideos/basics) so that you can navigate the files you're writing, detect errors using plugins, and execute commands using the built-in terminal.
43
40
44
41
## How to set up Terraform to manage your Okta org's configuration
45
42
46
-
When an identity administrator gives a person the ability to make changes in Okta, they
47
-
provision the person with credentials to authenticate and scopes to indicate what they're
48
-
authorized to do. When you set up an automation tool in your Okta organization, it's similar to
49
-
onboarding any other colleague: Your tool will need credentials to authenticate and scopes to
50
-
indicate what it's authorized to do.
43
+
When an identity administrator gives a person the ability to make changes in Okta, they provision the person with credentials to authenticate and scopes to indicate what they're authorized to do. When you set up an automation tool in your Okta organization, it's similar to onboarding any other colleague: Your tool will need credentials to authenticate and scopes to indicate what it's authorized to do.
51
44
52
45
## Scenario
53
-
You are on the DevOps team at Okta Ice. As the company has grown, it's gotten more challenging to
54
-
manage and audit the changes that various teams make in Okta. Adding Okta to the
55
-
infrastructure you are already managing with Terraform allows you to apply existing
56
-
code review processes to your identity configuration.
46
+
You are on the DevOps team at Okta Ice. As the company has grown, it's gotten more challenging to manage and audit the changes that various teams make in Okta. Adding Okta to the infrastructure you are already managing with Terraform allows you to apply existing code review processes to your identity configuration.
57
47
58
48
59
49
### Accessing Terraform
60
50
61
51
In a production setting, you would collaborate on your Terraform files with colleagues using version control. If anyone at your organization uses Terraform, you should set it up according to their advice on best practices.
62
52
63
-
Note that Terraform creates a `.tfstate` file. Each real-world resource should only be
64
-
represented in one `.tfstate` file. If you're collaborating on a Terraform codebase, products like [Terraform Cloud](https://www.hashicorp.com/resources/what-is-terraform-cloud) are available to help you manage shared access to `.tfstate` files.
53
+
Note that Terraform creates a `.tfstate` file. Each real-world resource should only be represented in one `.tfstate` file. If you're collaborating on a Terraform codebase, products like [Terraform Cloud](https://www.hashicorp.com/resources/what-is-terraform-cloud) are available to help you manage shared access to `.tfstate` files.
65
54
66
55
You will save a private key alongside your code to simplify the lab. In production, you should store keys in your organization's secrets management solution. Because private keys are secrets, follow your organization's best practices for secrets management when dealing with them.
67
56
@@ -101,8 +90,7 @@ You will save a private key alongside your code to simplify the lab. In producti
101
90
102
91
4. On your computer, paste the key into a file and save it as `key.pem`
103
92
104
-
**Important:** The key is saved locally to simplify the lab. You should save the key to an appropriate secrets management solution when working with production environments. If
105
-
you do not have secrets management, [this blog post](/blog/2024/10/11/terraform-ci-cd) shares one way to set it up.
93
+
**Important:** The key is saved locally to simplify the lab. You should save the key to an appropriate secrets management solution when working with production environments. If you do not have secrets management, [this blog post](/blog/2024/10/11/terraform-ci-cd) shares one way to set it up.
106
94
107
95
5. Complete the configuration steps.
108
96
@@ -113,11 +101,11 @@ You will save a private key alongside your code to simplify the lab. In producti
113
101
c. In the "Existing client secrets will no longer be used" popup, select Save.
114
102
115
103
6. From the Okta API Scopes tab, grant the following scopes:
116
-
- okta.appGrants.manage
117
-
- okta.apps.manage
118
-
- okta.oauthIntegrations.manage
119
-
- okta.policies.read
120
-
- okta.users.manage
104
+
-`okta.appGrants.manage`
105
+
-`okta.apps.manage`
106
+
-`okta.oauthIntegrations.manage`
107
+
-`okta.policies.read`
108
+
-`okta.users.manage`
121
109
122
110
7. Modify the admin roles for the Terraform lab app.
123
111
@@ -158,11 +146,11 @@ provider "okta" {
158
146
159
147
9. In your `main.tf` file, replace `ORGID` with the subdomain for your Okta org.
160
148
161
-
Note: The subdomain is between `https://` and `.oktapreview.com`. In the example below,
162
-
the subdomain is `oktaice0000000`.
149
+
**Note:** The subdomain is between `https://` and `.oktapreview.com`. In the example below, the subdomain is `oktaice0000000`.
163
150
164
151
10. In your `main.tf` file, replace `CLIENTID` with the client ID of your Terraform lab app.
165
-
Note: Go to Applications > Applications to find the client ID of your Terraform lab app.
152
+
153
+
**Note:** Go to Applications > Applications to find the client ID of your Terraform lab app.
166
154
167
155
11. Save the `main.tf` file.
168
156
12. Initiate and run the terraform plan.
@@ -181,15 +169,10 @@ provider "okta" {
181
169
In this lab, we'll use Terraform to create an application that PowerShell can use to read Okta data safely. If you want to use Okta's PowerShell module without managing it in Terraform, follow [the usage guide](https://github.com/okta/okta-powershell-cli?tab=readme-ov-file#usage-guide) instead.
182
170
183
171
## Scenario
184
-
An Okta Ice intern uses PowerShell to generate a newsletter with statistics about the
185
-
company. They have asked you to help them access data about how the company uses Okta.
186
-
You want to give their script read access to various data from Okta by setting up an
187
-
application for PowerShell and testing it out. Since they are already using PowerShell, the Okta
188
-
PowerShell Module is a perfect choice for the task!
172
+
An Okta Ice intern uses PowerShell to generate a newsletter with statistics about the company. They have asked you to help them access data about how the company uses Okta. You want to give their script read access to various data from Okta by setting up an application for PowerShell and testing it out. Since they are already using PowerShell, the Okta PowerShell Module is a perfect choice for the task!
189
173
190
174
### Accessing PowerShell
191
-
You can access PowerShell 7 by launching it from the shortcut generated during its installation or with the Visual Studio Code
192
-
built-in terminal.
175
+
You can access PowerShell 7 by launching it from the shortcut generated during its installation or with the Visual Studio Code built-in terminal.
193
176
194
177
## Configure a PowerShell Application using Terraform
7. The `Invoke-OktaEstablishAccessToken` command displays a URL. Open the link in a web browser.
242
222
8. Authenticate to your Okta Training Org when prompted.
243
-
9. Run this command in your PowerShell session:
244
-
245
-
```
246
-
Invoke-OktaListApplications
247
-
```
223
+
9. In your PowerShell session, run the command `Invoke-OktaListApplications`
248
224
249
225
## Extra Credit
250
-
You have set up the PowerShell application with various scopes. What interesting information about your organization can you retrieve using these scopes? Will these scopes allow you to make any
251
-
changes to the Okta organization? Try some PowerShell commands to create or destroy
252
-
resources and see what happens!
226
+
You have set up the PowerShell application with various scopes. What interesting information about your organization can you retrieve using these scopes? Will these scopes allow you to make any changes to the Okta organization? Try some PowerShell commands to create or destroy resources and see what happens!
227
+
253
228
If you want to explore your Okta org more with PowerShell, these resources may help:
254
229
- Okta Developer [PowerShell blog post](/blog/2024/05/07/okta-powershell-module)
0 commit comments