Skip to content

Commit 3867345

Browse files
committed
markdown standards
1 parent dab3d23 commit 3867345

File tree

1 file changed

+28
-56
lines changed

1 file changed

+28
-56
lines changed

_source/_posts/2025-01-09-terraform-powershell-lab.md

+28-56
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@ tweets:
1212
- ""
1313
image: blog/terraform-powershell-lab/image.jpg
1414
type: awareness
15+
---
1516

1617
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.
1718

1819
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.
1920

2021
## 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.
2523

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.
2925

3026
## How to create your lab environment
3127

@@ -39,29 +35,22 @@ You can follow these steps on any computer where you're able to install the foll
3935
Note: Free trial accounts expire after 30 days, but developer accounts do not expire.
4036

4137
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+
4239
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.
4340

4441
## How to set up Terraform to manage your Okta org's configuration
4542

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.
5144

5245
## 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.
5747

5848

5949
### Accessing Terraform
6050

6151
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.
6252

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.
6554

6655
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.
6756

@@ -101,8 +90,7 @@ You will save a private key alongside your code to simplify the lab. In producti
10190

10291
4. On your computer, paste the key into a file and save it as `key.pem`
10392

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.
10694

10795
5. Complete the configuration steps.
10896

@@ -113,11 +101,11 @@ You will save a private key alongside your code to simplify the lab. In producti
113101
c. In the "Existing client secrets will no longer be used" popup, select Save.
114102

115103
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`
121109

122110
7. Modify the admin roles for the Terraform lab app.
123111

@@ -158,11 +146,11 @@ provider "okta" {
158146

159147
9. In your `main.tf` file, replace `ORGID` with the subdomain for your Okta org.
160148

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`.
163150

164151
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.
166154

167155
11. Save the `main.tf` file.
168156
12. Initiate and run the terraform plan.
@@ -181,15 +169,10 @@ provider "okta" {
181169
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.
182170
183171
## 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!
189173
190174
### 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.
193176
194177
## Configure a PowerShell Application using Terraform
195178
1. Add the following to your main.tf file:
@@ -217,11 +200,8 @@ resource "okta_app_oauth_api_scope" "ps-scopes" {
217200
"okta.userTypes.read", "okta.users.read"]
218201
}
219202
```
220-
2. In your terminal, run the following command:
221-
```
222-
terraform apply
223-
```
224-
3. Type yes when prompted.
203+
2. In your terminal, run the command `terraform apply`
204+
3. Type `yes` when prompted.
225205
4. Wait for the `terraform apply` to complete.
226206
5. From the `Creation complete after` output, copy the value of the `okta_app_oauth` id.
227207
**Note:** PowerShell and Terraform now have separate applications in your Okta organization.
@@ -240,16 +220,11 @@ resource "okta_app_oauth_api_scope" "ps-scopes" {
240220
241221
7. The `Invoke-OktaEstablishAccessToken` command displays a URL. Open the link in a web browser.
242222
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`
248224
249225
## 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+
253228
If you want to explore your Okta org more with PowerShell, these resources may help:
254229
- Okta Developer [PowerShell blog post](/blog/2024/05/07/okta-powershell-module)
255230
- Okta Developer Podcast [PowerShell Episode](/blog/2024/04/11/okta-powershell-module-podcast)
@@ -267,11 +242,8 @@ Your manager at Okta Ice assigns you a ticket to update the configuration of the
267242
268243
## Manage Terraform in Terraform
269244
270-
1) In your PowerShell session from the previous section, run the following command:
271-
272-
``` powershell
273-
Invoke-OktaListApplications
274-
```
245+
1) In your PowerShell session from the previous section, run the command `powershell
246+
Invoke-OktaListApplications`
275247
276248
2) In the resulting list, find the ID of your Terraform app. Note that the name you chose, such as "Terraform lab," will be shown in the label field.
277249
@@ -285,15 +257,15 @@ import {
285257
```
286258
4) Save `main.tf`
287259

288-
5) In your terminal, run the command: `terraform plan --generate-config-out tf-app-config.tf`
260+
5) In your terminal, run the command `terraform plan --generate-config-out tf-app-config.tf`
289261

290262
6) Remove the `import{...}` block from `main.tf` and save `main.tf`
291263

292264
7) In your terminal, run the command: `terraform apply`
293265

294266
8) Open the file `tf-app-config.tf`
295267

296-
9) Remove the comments from the top of the file (single-line comments in Terraform start with # or //)
268+
9) Remove the comments from the top of the file (single-line comments in Terraform start with `#` or `//`)
297269

298270
10) Remove the lines from the resource block that do not represent properties you plan to manage. You can safely remove any null field.
299271

@@ -317,7 +289,7 @@ Now that you are managing Terraform's Okta application in Terraform, you can mod
317289

318290
Remember that the scopes configured in the provider block and those configured in the Okta application must match before Terraform can use them!
319291

320-
# Appendix: All the Terraform Code in one place
292+
## Appendix: All the Terraform Code in one place
321293
After completing the lab, your `main.tf` will contain the following. To clean up the whitespace in your files, run the command terraform fmt.
322294
```
323295
terraform {

0 commit comments

Comments
 (0)