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: operations/automation-script/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,7 @@ Follow these instructions to run the script with with the included main.tf and v
75
75
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.
76
76
1.`export TFE_TOKEN=<owners_token>` where \<owners_token\> is the token generated in the previous step.
77
77
1.`export TFE_ORG=<your_organization>` where \<your_organization\> is the name of your target TFE organization.
78
-
1.`export TFE_ADDR=<your_custom_address>` where \<your_custom_address\> is the address of your target TFE server in the format server.domain.tld. If you do not set this environment variable it will default to the Terraform Enterprise Cloud/SaaS address of app.terraform.io.
78
+
1.`export TFE_ADDR=<your_address>` where \<your_address\> is the custom address of your target TFE server in the format server.domain.tld. If you do not set this environment variable it will default to the Terraform Enterprise Cloud/SaaS address of app.terraform.io.
79
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.
80
80
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.
81
81
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.
Copy file name to clipboardExpand all lines: operations/sentinel-policies-scripts/README.md
+35-6Lines changed: 35 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,11 @@ These are scripts that can be used to export and import Sentinel policies betwee
5
5
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.
6
6
1.`export TFE_TOKEN=<owners_token>` where \<owners_token\> is the token generated in the previous step.
7
7
1.`export TFE_ORG=<your_organization>` where \<your_organization\> is the name of your target TFE organization.
8
-
1.`export TFE_ADDR=<your_custom_address>` where \<your_custom_address\> is the address of your target TFE server in the format server.domain.tld. If you do not set this environment variable it will default to the Terraform Enterprise Cloud/SaaS address of app.terraform.io.
8
+
1.`export TFE_ADDR=<your_address>` where \<your_address\> is the custom address of your target TFE server in the format server.domain.tld. If you do not set this environment variable it will default to the Terraform Enterprise Cloud/SaaS address of app.terraform.io.
9
9
10
10
## Exporting Policies
11
11
12
-
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 100 policies since it does not handle multiple pages from the List Policies API that retrieves them.
12
+
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 100 policies since it does not handle multiple pages from the List Policies API that retrieves them.
13
13
14
14
The script uses curl to interact with Terraform Enterprise via the TFE API. It performs the following steps:
15
15
@@ -24,12 +24,12 @@ The script uses curl to interact with Terraform Enterprise via the TFE API. It
24
24
1. Finally, it prints out the number of policies it exported.
25
25
26
26
## Importing Policies
27
+
The `import_policies.sh` script imports all policies in a directory into a specified organization on a specified server.
28
+
It also adds all of them to a specified policy set, using a **policy set ID** (which can be determined by looking at the policy set's URL).
27
29
28
-
The import_policies.sh script imports all policies in a directory into a specified organization on a specified server. It also adds all of them to a specified policy set, using a policy set ID which is set through the first CLI argument.
30
+
**Note** that you must use the policy set's ID (e.g., polset-rCLeCwoSBUHXDC7L), not the name of the policy set.
29
31
30
-
For example: `./import_policies.sh sample` where \<sample>\ is the desired name of the policy set.
31
-
32
-
Note that you will get errors if any of the policies you are importing already exist. Please delete any policies you plan to import first if they already exist in your organization.
32
+
**Note** that you will get errors if any of the policies you are importing already exist. Please delete any policies you plan to import first if they already exist in your organization.
33
33
34
34
The script uses curl to interact with Terraform Enterprise via the TFE API. It performs the following steps:
35
35
@@ -39,6 +39,35 @@ The script uses curl to interact with Terraform Enterprise via the TFE API. It p
39
39
1. It uses curl to invoke the [Upload a Policy API](https://www.terraform.io/docs/enterprise/api/policies.html#upload-a-policy).
40
40
1. Finally, it prints out the number of policies found and imported.
41
41
42
+
### Using This Script
43
+
44
+
You will need to grab the Policy Set ID from the TFE GUI to use as a CLI argument when running`import_policies.sh`
45
+
46
+
1. Create Policy Set within the TFE GUI
47
+
48
+
1a. Settings > Policy Sets > Create a new policy set
49
+
50
+
1b. Provide friendly name, description
51
+
52
+
1c. For the Policy Set Source, choose _Upload via API_
53
+
54
+
1d. For the Scope of Policies, choose either option
55
+
56
+
1e. Select _Create policy set_
57
+
58
+
1. After creating the policy set you are returned to the Policy Sets sub-menu
59
+
1. Select the policy set you just created
60
+
1. Look at the URL of within your browser window
61
+
1. The programmatic _Policy Set ID_ required for this script is contained within the URL immediately after `/policy-sets/` for example: https://app.terraform.io/app/jray-hashi/settings/policy-sets/**polset-6YVMugX6VX3FG1Zu**/edit
62
+
1. Copy this data to your clipboard, working file, or directly terminal where you will run the `import_policies.sh` script
63
+
1. Create the desired Sentinel policies files and copy them into the directory where the script will be executed. Be sure they have a `*.sentinel` extension
64
+
1. Open `create-policy.template.json` and modify the value of `"mode":` to `advisory`, `soft-mandatory`, or `hard-mandatory` for the desired [enforcement type](https://www.terraform.io/docs/enterprise/api/policies.html#request-body)
65
+
1. Execute the script as follows:
66
+
67
+
`./import_policies.sh <polset-somenumber>` where \<polset-somenumber\> is your unique policy set ID
68
+
69
+
**Note** if you receive the error message `Policy Upload Response: {"errors":[{"status":"415","title":"invalid content type","detail":"content-type must be application/vnd.api+json"}]}` this means you have an existing policy with the same name that you are trying to load. Delete all policies using the `delete_policies.sh` script or manually from the GUI and try again.
70
+
42
71
## Deleting Policies
43
72
The delete_policies.sh script **deletes all policies** from a TFE organization. It uses curl to invoke the [List Policies API](https://www.terraform.io/docs/enterprise/api/policies.html#list-policies) to retrieve all Sentinel policies. It then iterates through these and invokes the [Delete a Policy API](https://www.terraform.io/docs/enterprise/api/policies.html#delete-a-policy) to delete them one at a time. It also prints out the ID of each deleted policy and finally gives a count of how many were deleted.
0 commit comments