Skip to content

Commit b0ffe39

Browse files
committed
indentation fixups
1 parent cede6b2 commit b0ffe39

File tree

1 file changed

+60
-62
lines changed

1 file changed

+60
-62
lines changed

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

+60-62
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,14 @@ You will save a private key alongside your code to simplify the lab. In producti
8181

8282
d. Select Generate new key.
8383

84-
e. Under "Private Key - Copy this!" select PEM.
85-
86-
**Note**: the PEM key begins with the line `-----BEGIN PRIVATE KEY-----`. Make sure you're looking at the PEM, not the JSON.
84+
e. Under "Private Key - Copy this!" select PEM.
85+
**Note**: the PEM key begins with the line `-----BEGIN PRIVATE KEY-----`. Make sure you're looking at the PEM, not the JSON.
8786

8887
f. Select Copy to clipboard.
8988

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

92-
**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.
91+
**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.
9392

9493
5. Complete the configuration steps.
9594

@@ -118,31 +117,30 @@ You will save a private key alongside your code to simplify the lab. In producti
118117

119118
8. In your VM, create the file `main.tf`:
120119

121-
```hcl
122-
terraform {
123-
required_providers {
124-
okta = {
125-
source = "okta/okta"
120+
```hcl
121+
terraform {
122+
required_providers {
123+
okta = {
124+
source = "okta/okta"
125+
}
126126
}
127127
}
128-
}
129-
130-
variable "org_id" {
131-
default = "ORGID"
132-
}
133128
134-
provider "okta" {
135-
org_name = var.org_id
136-
base_url = "oktapreview.com"
137-
client_id = "CLIENTID"
138-
scopes = ["okta.apps.manage", "okta.appGrants.manage",
139-
"okta.oauthIntegrations.manage", "okta.users.manage",
140-
"okta.policies.read"]
141-
private_key = file("key.pem")
142-
}
129+
variable "org_id" {
130+
default = "ORGID"
131+
}
143132
144-
```
133+
provider "okta" {
134+
org_name = var.org_id
135+
base_url = "oktapreview.com"
136+
client_id = "CLIENTID"
137+
scopes = ["okta.apps.manage", "okta.appGrants.manage",
138+
"okta.oauthIntegrations.manage", "okta.users.manage",
139+
"okta.policies.read"]
140+
private_key = file("key.pem")
141+
}
145142
143+
```
146144
9. In your `main.tf` file, replace `ORGID` with the subdomain for your Okta org.
147145

148146
**Note:** The subdomain is between `https://` and `.oktapreview.com`. In the example below, the subdomain is `oktaice0000000`.
@@ -176,47 +174,47 @@ You can access PowerShell 7 by launching it from the shortcut generated during i
176174
## Configure a PowerShell Application using Terraform
177175
1. Add the following to your `main.tf` file:
178176
179-
```hcl
180-
resource "okta_app_oauth" "ps" {
181-
182-
grant_types = ["authorization_code",
183-
"urn:ietf:params:oauth:grant-type:device_code"]
184-
label = "PowerShell"
185-
response_types = ["code"]
186-
type = "native"
187-
redirect_uris = ["com.oktapreview.${var.org_id}:/callback"]
188-
token_endpoint_auth_method = "none"
189-
implicit_assignment = true
190-
issuer_mode = "DYNAMIC"
191-
}
177+
```hcl
178+
resource "okta_app_oauth" "ps" {
179+
180+
grant_types = ["authorization_code",
181+
"urn:ietf:params:oauth:grant-type:device_code"]
182+
label = "PowerShell"
183+
response_types = ["code"]
184+
type = "native"
185+
redirect_uris = ["com.oktapreview.${var.org_id}:/callback"]
186+
token_endpoint_auth_method = "none"
187+
implicit_assignment = true
188+
issuer_mode = "DYNAMIC"
189+
}
192190
193-
resource "okta_app_oauth_api_scope" "ps-scopes" {
194-
app_id = okta_app_oauth.ps.id
195-
issuer = "https://${var.org_id}.oktapreview.com"
196-
scopes = ["okta.apps.read", "okta.domains.read",
197-
"okta.groups.read", "okta.logs.read",
198-
"okta.oauthIntegrations.read", "okta.orgs.read",
199-
"okta.userTypes.read", "okta.users.read"]
200-
}
201-
```
191+
resource "okta_app_oauth_api_scope" "ps-scopes" {
192+
app_id = okta_app_oauth.ps.id
193+
issuer = "https://${var.org_id}.oktapreview.com"
194+
scopes = ["okta.apps.read", "okta.domains.read",
195+
"okta.groups.read", "okta.logs.read",
196+
"okta.oauthIntegrations.read", "okta.orgs.read",
197+
"okta.userTypes.read", "okta.users.read"]
198+
}
199+
```
202200
2. In your terminal, run the command `terraform apply`
203201
3. Type `yes` when prompted.
204202
4. Wait for the `terraform apply` to complete.
205203
5. From the `Creation complete after` output, copy the value of the `okta_app_oauth` id.
206204

207-
**Note:** PowerShell and Terraform now have separate applications in your Okta organization. The PowerShell application's ID can also be found in the Okta admin console under Applications -> Applications.
205+
**Note:** PowerShell and Terraform now have separate applications in your Okta organization. The PowerShell application's ID can also be found in the Okta admin console under Applications -> Applications.
208206

209207
6. In PowerShell, run these commands:
210208

211-
**Note:** Replace the {yourOktaDomain} with the entire domain for your Okta org. For example, `oktaice0000000.oktapreview.com`. Replace the ID with the value you copied above.
209+
**Note:** Replace the {yourOktaDomain} with the entire domain for your Okta org. For example, `oktaice0000000.oktapreview.com`. Replace the ID with the value you copied above.
212210

213-
```
214-
$Configuration = Get-OktaConfiguration
215-
$Configuration.BaseUrl = "https://{yourOktaDomain}"
216-
$Configuration.ClientId = "id"
217-
$Configuration.Scope = "okta.apps.read okta.domains.read okta.groups.read okta.logs.read okta.oauthIntegrations.read okta.orgs.read okta.userTypes.read okta.users.read"
218-
Invoke-OktaEstablishAccessToken
219-
```
211+
```powershell
212+
$Configuration = Get-OktaConfiguration
213+
$Configuration.BaseUrl = "https://{yourOktaDomain}"
214+
$Configuration.ClientId = "id"
215+
$Configuration.Scope = "okta.apps.read okta.domains.read okta.groups.read okta.logs.read okta.oauthIntegrations.read okta.orgs.read okta.userTypes.read okta.users.read"
216+
Invoke-OktaEstablishAccessToken
217+
```
220218

221219
7. The `Invoke-OktaEstablishAccessToken` command displays a URL. Open the link in a web browser.
222220
8. Authenticate to your Okta Training Org when prompted.
@@ -243,12 +241,12 @@ Your manager at Okta Ice assigns you a ticket to update the configuration of the
243241

244242
3) Add the following code to your `main.tf`, substituting the application ID you got from PowerShell:
245243

246-
``` hcl
247-
import {
248-
to = okta_app_oauth.tf
249-
id="FIXME"
250-
}
251-
```
244+
``` hcl
245+
import {
246+
to = okta_app_oauth.tf
247+
id="FIXME"
248+
}
249+
```
252250
4) Save `main.tf`
253251

254252
5) In your terminal, run the command `terraform plan --generate-config-out tf-app-config.tf`
@@ -284,7 +282,7 @@ Now that you are managing Terraform's Okta application in Terraform, you can mod
284282
Remember that the scopes configured in the provider block and those configured in the Okta application must match before Terraform can use them!
285283

286284
## Appendix: All the Terraform Code in one place
287-
After completing the lab, your `main.tf` will contain the following. To clean up the whitespace in your files, run the command terraform fmt.
285+
After completing the lab, your `main.tf` will contain the following. To clean up the whitespace in your files, run the command `terraform fmt`.
288286
```
289287
terraform {
290288
required_providers {

0 commit comments

Comments
 (0)