Skip to content

Commit 0c9c321

Browse files
committed
update scripts to use TFE_ORG env var
user does not need to open each script to set org name, can be done with env var while setting TFE_TOKEN env var.
1 parent b25140d commit 0c9c321

File tree

10 files changed

+36
-21
lines changed

10 files changed

+36
-21
lines changed

operations/automation-script/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ If you use this script with a Private Terraform Enterprise (PTFE) server that us
7373
Follow these instructions to run the script with with the included main.tf and variables.csv files or with your own git repository:
7474

7575
1. If you are using a private Terraform Enterprise server, edit the script and set the address variable to the address of your server. Otherwise, you would leave the address set to "app.terraform.io" which is the address of the SaaS Terraform Enterprise server.
76-
1. Edit the script and set the organization variable to the name of your Terraform Enterprise organization.
7776
1. Generate a [team token](https://www.terraform.io/docs/enterprise/users-teams-organizations/service-accounts.html#team-service-accounts) for the owners team in your organization in the Terraform Enterprise UI by selecting your organization settings, then Teams, then owners, and then clicking the Generate button and saving the token that is displayed.
7877
1. `export TFE_TOKEN=<owners_token>` where \<owners_token\> is the token generated in the previous step.
79-
1. If you want, you can also change the name of the workspace that will be created by editing the workspace variable. Note that you can also pass the workspace as the second argument to the script.
78+
1. `export TFE_ORG=<your_organization>` where \<your_organization\> is the name of your target TFE organization.
79+
1. If you want, edit _loadAndRunWorkspace.sh_ to change the name of the workspace that will be created by editing the workspace variable. *Note* that you can also pass the workspace as the second argument to the script.
8080
1. If you want, you can change the sleep_duration variable which controls how often the script checks the status of the triggered run (in seconds). Setting a longer value would make sense if using Terraform code that takes longer to apply.
8181
1. If you are providing a URL to clone a git repository, you can add Terraform and environment variables needed by your Terraform code to [variables.csv](./variables.csv) and remove the "name" variable. You can also add the edited variables.csv file to your repository.
8282
1. If you want to use the sample main.tf or other code you place in the config directory, run `./loadAndRunWorkspace.sh` or `./loadAndRunWorkspace.sh "" "" <override>` where \<override\> is "yes" or "no". (The empty quotes are needed in the second case so that override is the third variable.) If you do not specify a value for \<override\>, the script will set it to "no".

operations/automation-script/apply.json

100644100755
File mode changed.

operations/automation-script/deleteWorkspace.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/bin/bash
22
# Script to delete the workspace created by the loadAndRunWorkspace.sh script
33

4-
# Make sure TFE_TOKEN environment variable is set
5-
# to owners team token for organization
4+
# Make sure TFE_TOKEN and TFE_ORG environment variables are set
5+
# to owners team token and organization name for the respective
6+
# TFE environment.
67

78
# Set address if using private Terraform Enterprise server.
89
# Set organization and workspace to create.
910
# You should edit these before running.
1011
address="app.terraform.io"
11-
organization="<your_organization>"
12+
organization="$TFE_ORG"
1213
workspace="workspace-from-api"
1314

1415
# Set workspace if provided as the second argument

operations/automation-script/loadAndRunWorkspace.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
# If an apply is done, the script waits for it to finish and then
99
# downloads the apply log and the before and after state files.
1010

11-
# Make sure TFE_TOKEN environment variable is set
12-
# to owners team token for organization
11+
# Make sure TFE_TOKEN and TFE_ORG environment variables are set
12+
# to owners team token and organization name for the respective
13+
# TFE environment.
1314

1415
# Set address if using private Terraform Enterprise server.
1516
# Set organization and workspace to create.
1617
# You should edit these before running.
18+
1719
address="app.terraform.io"
18-
organization="<your_organization>"
20+
organization="$TFE_ORG"
1921
# workspace name should not have spaces
2022
workspace="workspace-from-api"
2123

operations/sentinel-policies-scripts/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ These are scripts that can be used to export and import Sentinel policies betwee
33

44
Before using these scripts, you need to export a valid TFE API token with the command `export TFE_TOKEN=<owners_token>` where \<owners_token\> is a team token for the owners team in your organization.
55

6+
Before running these scripts, you must export or set the TFE ORG environment variable with the command `export TFE_ORG=<your_organization>` where \<your_organization\> is the target name of the organization containing the Sentinel policies you want to manage.
7+
68
## Exporting Policies
79
The export_policies.sh script exports all the policies from a TFE organization to the directory in which you run the script. It currently is limited to exporting 150 policies since it does not handle multiple pages from the List Policies API that retrieves them.
810

operations/sentinel-policies-scripts/delete_policies.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# This script deletes all policies from the specified organization
33
# of the specified TFE server
44

5-
# Make sure TFE_TOKEN environment variable is set
6-
# to owners team token for organization
7-
# or to user token for member of the owners team
5+
# Make sure TFE_TOKEN and TFE_ORG environment variables are set
6+
# to owners team token and organization name for the respective
7+
# TFE environment.
88

99
# Set address if using private Terraform Enterprise server.
1010
# You should edit these before running.
1111
address="app.terraform.io"
1212
# Set organization to use
13-
organization="<organization>"
13+
organization="$TFE_ORG"
1414

1515
echo "Using address: $address"
1616
echo "Using organization: $organization"

operations/sentinel-policies-scripts/export_policies.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# This script exports all policies from the specified organization
33
# of the specified TFE server to the current directory
44

5-
# Make sure TFE_TOKEN environment variable is set
6-
# to owners team token for organization
7-
# or to user token for member of the owners team
5+
# Make sure TFE_TOKEN and TFE_ORG environment variables are set
6+
# to owners team token and organization name for the respective
7+
# TFE environment.
88

99
# Set address if using private Terraform Enterprise server.
1010
# You should edit these before running.
1111
address="app.terraform.io"
1212
# Set organization to use
13-
organization="<organization>"
13+
organization="$TFE_ORG"
1414

1515
echo "Using address: $address"
1616
echo "Using organization: $organization"

operations/sentinel-policies-scripts/import_policies.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# This script imports all policies in the current directory into a
33
# specific policy set within a specific organization on a TFE server.
44

5-
# Make sure TFE_TOKEN environment variable is set
6-
# to owners team token for organization
7-
# or to user token for member of the owners team
5+
# Make sure TFE_TOKEN and TFE_ORG environment variables are set
6+
# to owners team token and organization name for the respective
7+
# TFE environment.
88

99
# Set address if using private Terraform Enterprise server.
1010
# You should edit these before running.
1111
address="app.terraform.io"
1212
# Set organization to use
13-
organization="<organization>"
13+
organization="$TFE_ORG"
1414
# Set ID of policy set that all policies should be added to
1515
policy_set_id="<policy_set_id>"
1616

operations/variable-scripts/delete-variables.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/bin/bash
22
# Script that deletes all Terraform and environment variables in a Terraform Enterprise (TFE) workspace
33

4+
# Make sure TFE_TOKEN and TFE_ORG environment variables are set
5+
# to owners team token and organization name for the respective
6+
# TFE environment. TFE_TOKEN environment variable is set
7+
# to a user or team token that has the write or admin permission
8+
# for the workspace.
9+
410
# Exit if any errors encountered
511
set -e
612

operations/variable-scripts/set-variables.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
# Exit if any errors encountered
88
set -e
99

10-
# Make sure the $TFE_TOKEN environment variable is set
10+
# Make sure TFE_TOKEN and TFE_ORG environment variables are set
11+
# to owners team token and organization name for the respective
12+
# TFE environment. TFE_TOKEN environment variable is set
1113
# to a user or team token that has the write or admin permission
1214
# for the workspace.
15+
16+
1317
if [ ! -z "$TFE_TOKEN" ]; then
1418
token=$TFE_TOKEN
1519
echo "TFE_TOKEN environment variable was found."

0 commit comments

Comments
 (0)