Skip to content

Commit b26ce2f

Browse files
committed
create bash script to convert hcl variables to json in iacinputdata and create readme for it
1 parent c19d408 commit b26ce2f

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

README.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Migrate workloads from other platforms to [StackGuardian Platform](https://app.s
2020
- [sg-cli](https://github.com/StackGuardian/sg-cli/tree/main/shell)
2121

2222
### Perform terraform login
23+
2324
Perform `terraform login` to ensure that your local Terraform can interact with your Terraform Cloud/Enterprise account.
2425

2526
### Export the resource definitions and Terraform state
@@ -37,8 +38,11 @@ terraform apply -auto-approve -var-file=terraform.tfvars
3738
A new `export` folder should have been created. The `sg-payload.json` file contains the definition for each workflow that will be created for each Terraform Workspace, and the `states` folder contains the files for the Terraform state for each of your workspaces, if the state export was enabled.
3839

3940
After completing the export , edit the `sg-payload.json` file to provide tune each workflow configuration with the following:
40-
### Use the example_payload.jsonc file as a reference and edit the schema of the `sg-payload.json`
41+
42+
### Use the example_payload.jsonc file as a reference and edit the schema of the `sg-payload.json`
43+
4144
- `DeploymentPlatformConfig` - This is used to authenticate against a cloud provider using a StackGuardian Integration. Create the relevant integration in StackGuardian platform and update `DeploymentPlatformConfig.kind` from the following "AZURE_STATIC", "AWS_STATIC","GCP_STATIC", "AWS_RBAC". Update `DeploymentPlatformConfig.config.integrationId` with "/integrations/INTEGRATION_NAME" and `DeploymentPlatformConfig.config.profileName` with the name of the integration used upon creation.
45+
4246
```
4347
DeploymentPlatformConfig: [
4448
{
@@ -50,27 +54,27 @@ After completing the export , edit the `sg-payload.json` file to provide tune ea
5054
}
5155
]
5256
```
57+
5358
- `VCSConfig` - Provide full path to the `repo` like as well the relevant `sourceConfigDestKind` from the following "GITHUB_COM", "BITBUCKET_ORG", "GITLAB_COM", "AZURE_DEVOPS"
54-
- `config.auth`
55-
- `config.isPrivate`
56-
59+
- `config.auth`
60+
- `config.isPrivate`
5761
- `ResourceName` - name of your StackGuardian Workflow
5862
- `wfgrpName` - this corresponds to the labelling of workflow group name in the StackGuardian platform
5963
- `Description` - description for the workflows created in the StackGuardian platform
60-
- `Tags` - list of tags for the workflows created in the StackGuardian platform
64+
- `Tags` - list of tags for the workflows created in the StackGuardian platform
6165
- `EnvironmentVariables` - environment variables for the workflows created in the StackGuardian platform
6266
- `RunnerConstraints` - Runner description for the workflows in the StackGuardian platform
63-
- Private runners - ```
64-
"RunnerConstraints": {
65-
"type": "private",
66-
"names": [
67-
"sg-runner"
68-
]
69-
}```
70-
- Shared runners - ```
71-
"RunnerConstraints": {
72-
"type": "shared"
73-
}```
67+
- Private runners - `
68+
"RunnerConstraints": {
69+
"type": "private",
70+
"names": [
71+
"sg-runner"
72+
]
73+
}`
74+
- Shared runners - `
75+
"RunnerConstraints": {
76+
"type": "shared"
77+
}`
7478
- `Approvers` - Approvers for the workflow to run it successfully
7579
- `TerraformConfig` - Terraform configuration for the workflows created in the StackGuardian platform
7680
- `UserSchedules` - Scheduled workflow run configuration for the workflow in the StackGuardian platform
@@ -79,7 +83,7 @@ After completing the export , edit the `sg-payload.json` file to provide tune ea
7983
### Bulk import workflows to StackGuardian Platform
8084

8185
- Fetch [sg-cli](https://github.com/StackGuardian/sg-cli.git) and set it up locally (documentation present in repo)
82-
- Run the following commands and pass the `sg-payload.json` as payload (represented below)
86+
- Run the following commands and pass the `sg-payload.json` as payload (represented belkkkkkkkkkkow)
8387
- Get your SG API Key here: https://app.stackguardian.io/orchestrator/orgs/<ORG_ID>/settings?tab=api_key
8488

8589
```shell
@@ -92,6 +96,16 @@ wget -q "$(wget -qO- "https://api.github.com/repos/stackguardian/sg-cli/releases
9296
```
9397

9498
if you want to update a workflow with different details, please re-run the sg-cli command with the modified sg-payload.json and your workflow will be updated with the new details, as long as the ResourceName (Workflow name) remains the same.
99+
95100
```shell
96101
./sg-cli workflow create --bulk --org "<ORG NAME>" -- sg-payload.json
97102
```
103+
104+
## Convert hcl variables to json
105+
106+
HCL variables in terraform cloud appear as strings in sg-payload.json, which needs to be converted to json.</br >
107+
It will change the file input file in place so that none of the other steps need any change.
108+
109+
```shell
110+
./convert_hcl_to_json.sh <intput_file>
111+
```

create_workflow.sh renamed to convert_hcl_to_json.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ for ((i=0; i<length; i++)); do
7474
# If val is null or not an object, skip
7575
if [[ "$val" == "null" || $($JQ_BIN 'type' <<<"$val") != "\"object\"" ]]; then
7676
echo "$obj" >> "$tmpfile"
77+
7778
continue
7879
fi
7980

0 commit comments

Comments
 (0)