Skip to content

Commit a7d8460

Browse files
committed
accept SG defaults in tf vars; tf fmt
1 parent 2515f32 commit a7d8460

File tree

5 files changed

+76
-15
lines changed

5 files changed

+76
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ A new `export` folder should have been created. The `sg-payload.json` file conta
3838

3939
After completing the export , edit the `sg-payload.json` file to provide tune each workflow configuration with the following:
4040
### Use the example_payload.jsonc file as a reference and edit the schema of the `sg-payload.json`
41-
- `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.
41+
- `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.
4242
```
4343
DeploymentPlatformConfig: [
4444
{

transformer/terraform-cloud/locals.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ locals {
1818
},
1919
"kind" : "PLAIN_TEXT" } if v.category == "env" && v.sensitive == false]
2020

21-
DeploymentPlatformConfig = []
21+
DeploymentPlatformConfig = var.SGDefaultDeploymentPlatformConfig
2222
RunnerConstraints = { "type" : "shared" }
2323
VCSConfig = {
2424
"iacVCSConfig" : {
2525
"useMarketplaceTemplate" : false,
2626
"customSource" : {
27-
"sourceConfigDestKind" : "Choose from: GITHUB_COM, BITBUCKET_ORG, GITLAB_COM, AZURE_DEVOPS",
27+
"sourceConfigDestKind" : var.SGDefaultSourceConfigDestKind
2828
"config" : {
2929
"includeSubModule" : false,
3030
"ref" : length(data.tfe_workspace.data[i].vcs_repo) > 0 ? data.tfe_workspace.data[i].vcs_repo[0].branch != "" ? data.tfe_workspace.data[i].vcs_repo[0].branch : "" : "",
3131
"isPrivate" : length(data.tfe_workspace.data[i].vcs_repo) > 0 ? length(data.tfe_workspace.data[i].vcs_repo[0].oauth_token_id) > 0 || length(data.tfe_workspace.data[i].vcs_repo[0].github_app_installation_id) > 0 ? true : false : false,
32-
"auth" : length(data.tfe_workspace.data[i].vcs_repo) > 0 ? length(data.tfe_workspace.data[i].vcs_repo[0].oauth_token_id) > 0 || length(data.tfe_workspace.data[i].vcs_repo[0].github_app_installation_id) > 0 ? "Provide an integration id like /integrations/aws-dev-account or /secrets/my-git-token" : "" : "",
32+
"auth" : length(data.tfe_workspace.data[i].vcs_repo) > 0 ? length(data.tfe_workspace.data[i].vcs_repo[0].oauth_token_id) > 0 || length(data.tfe_workspace.data[i].vcs_repo[0].github_app_installation_id) > 0 ? var.SGDefaultVCSAuthIntegrationID : "" : "",
3333
"workingDir" : data.tfe_workspace.data[i].working_directory,
34-
"repo" : length(data.tfe_workspace.data[i].vcs_repo) > 0 ? data.tfe_workspace.data[i].vcs_repo[0].identifier : ""
34+
"repo" : length(data.tfe_workspace.data[i].vcs_repo) > 0 ? format("%s/%s", var.SGDefaultIACVCSRepoPrefix, data.tfe_workspace.data[i].vcs_repo[0].identifier) : ""
3535
}
3636
}
3737
},
@@ -56,7 +56,7 @@ locals {
5656
}
5757
}
5858

59-
Approvers = data.tfe_workspace.data[i].auto_apply == true ? [] : ["Add emails of the users who should approve the terraform plan, since approvalPreApply is set to true"]
59+
Approvers = data.tfe_workspace.data[i].auto_apply == true ? [] : var.SGDefaultWfApprovers
6060

6161
TerraformConfig = {
6262
"managedTerraformState" : true,
@@ -70,4 +70,4 @@ locals {
7070
data = jsonencode(
7171
local.workflows
7272
)
73-
}
73+
}

transformer/terraform-cloud/resources.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ resource "local_file" "generateTempTfFiles" {
1616
resource "null_resource" "exportStateFiles" {
1717
depends_on = [local_file.generateTempTfFiles]
1818
triggers = {
19-
always-update = timestamp()
19+
always-update = timestamp()
2020
}
21-
for_each = var.exportStateFiles ? toset(local.workflowNames) : []
21+
for_each = var.exportStateFiles ? toset(local.workflowNames) : []
2222

2323
provisioner "local-exec" {
2424
command = "mkdir -p ../../states && rm -rf .terraform .terraform.lock.hcl terraform.tfstate terraform.tfstate.backup && terraform init -input=false && terraform state pull > ../../states/'${each.key}.tfstate'"
@@ -27,9 +27,9 @@ resource "null_resource" "exportStateFiles" {
2727
}
2828

2929
resource "null_resource" "deleteTempTfFiles" {
30-
count = var.exportStateFiles ? 1 : 0
30+
count = var.exportStateFiles ? 1 : 0
3131
triggers = {
32-
always-update = timestamp()
32+
always-update = timestamp()
3333
}
3434
depends_on = [null_resource.exportStateFiles]
3535

transformer/terraform-cloud/terraform.tfvars.example

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,33 @@ workspacenames = ["*"]
88
exportStateFiles = true
99

1010
# Specify a list of tags in workspace tags to include, or leave empty to include all, for example: ["include"]
11-
# tfWorkspaceTags = []
11+
tfWorkspaceTags = null
1212

1313
# Specify a list of tags in workspace tags to exclude, or leave empty to include all, for example: [exclude"]
14-
# tfWorkspaceIgnoreTags = []
14+
tfWorkspaceIgnoreTags = null
1515

1616
# Directory to export Terraform files to
17-
# exportPath = "export"
17+
exportPath = "export"
18+
19+
# Add emails of the users who should approve the terraform plan, since approvalPreApply is set to true
20+
SGDefaultWfApprovers = []
21+
22+
# Prefix for your repo URL
23+
SGDefaultIACVCSRepoPrefix = "https://www.github.com"
24+
25+
# Provide an integration id like /integrations/aws-dev-account or /secrets/my-git-token
26+
SGDefaultVCSAuthIntegrationID = "/integrations/github_com"
27+
28+
# Integration to use to authenticate against your cloud provider
29+
SGDefaultDeploymentPlatformConfig = [
30+
{
31+
"kind" : "AWS_RBAC",
32+
"config" : {
33+
"integrationId" : "/integrations/aws-dev-account",
34+
"profileName" : "default"
35+
}
36+
}
37+
]
38+
39+
# Choose from: GITHUB_COM, BITBUCKET_ORG, GITLAB_COM, AZURE_DEVOPS, GIT_OTHER
40+
SGDefaultSourceConfigDestKind = "GITHUB_COM"

transformer/terraform-cloud/variables.tf

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,44 @@ variable "tfWorkspaceIgnoreTags" {
2929

3030
variable "exportPath" {
3131
default = "export"
32-
description = "name of the folder to export the payload, state files to ./export is the Default "
32+
description = "name of the folder to export the payload, state files to. ./export is the default"
33+
type = string
34+
}
35+
36+
variable "SGDefaultWfApprovers" {
37+
default = []
38+
description = "Add emails of the users who should approve the terraform plan, since approvalPreApply is set to true"
39+
type = list(string)
40+
}
41+
42+
variable "SGDefaultIACVCSRepoPrefix" {
43+
default = "https://VCS_PROVIDER_DOMAIN"
44+
description = "Prefix for your repo URL"
45+
type = string
46+
}
47+
48+
variable "SGDefaultVCSAuthIntegrationID" {
49+
default = "INTEGRATION_ID"
50+
description = "Provide an integration id like /integrations/aws-dev-account or /secrets/my-git-token"
51+
type = string
52+
}
53+
54+
variable "SGDefaultDeploymentPlatformConfig" {
55+
default = [
56+
{
57+
"kind" : "AWS_RBAC",
58+
"config" : {
59+
"integrationId" : "INTEGRATION_ID",
60+
"profileName" : "default"
61+
}
62+
}
63+
]
64+
description = "Integration to use to authenticate against your cloud provider"
65+
type = list(any)
66+
}
67+
68+
variable "SGDefaultSourceConfigDestKind" {
69+
default = "GIT_OTHER"
70+
description = "Choose from: GITHUB_COM, BITBUCKET_ORG, GITLAB_COM, AZURE_DEVOPS, GIT_OTHER"
3371
type = string
3472
}

0 commit comments

Comments
 (0)