Skip to content

Commit e909311

Browse files
authored
feat: add support for creating git access token to SM (#490)
1 parent c9def23 commit e909311

File tree

12 files changed

+113
-0
lines changed

12 files changed

+113
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ statement instead the previous block.
477477
| <a name="input_create_cd_toolchain"></a> [create\_cd\_toolchain](#input\_create\_cd\_toolchain) | Boolean flag which determines if the DevSecOps CD toolchain is created. | `bool` | `true` | no |
478478
| <a name="input_create_ci_toolchain"></a> [create\_ci\_toolchain](#input\_create\_ci\_toolchain) | Flag which determines if the DevSecOps CI toolchain is created. If this toolchain is not created then values must be set for the following variables, evidence\_repo\_url, issues\_repo\_url and inventory\_repo\_url. | `bool` | `true` | no |
479479
| <a name="input_create_cos_api_key"></a> [create\_cos\_api\_key](#input\_create\_cos\_api\_key) | Set to `true` to create and add a `cos-api-key` to the Secrets Provider. | `bool` | `false` | no |
480+
| <a name="input_create_git_token"></a> [create\_git\_token](#input\_create\_git\_token) | Set to `true` to create and add the specified personal access token secret to the Secrets Provider. | `bool` | `false` | no |
480481
| <a name="input_create_ibmcloud_api_key"></a> [create\_ibmcloud\_api\_key](#input\_create\_ibmcloud\_api\_key) | Set to `true` to create and add an `ibmcloud-api-key` to the Secrets Provider. | `bool` | `false` | no |
481482
| <a name="input_create_icr_namespace"></a> [create\_icr\_namespace](#input\_create\_icr\_namespace) | Set to `true` to have Terraform create the registry namespace. Setting to `false` will have the CI pipeline create the namespace if it does not already exist. Note: If a Terraform destroy is used, the ICR namespace along with all images will be removed. | `bool` | `false` | no |
482483
| <a name="input_create_secret_group"></a> [create\_secret\_group](#input\_create\_secret\_group) | Set to `true` to create the specified Secrets Manager secret group. | `bool` | `false` | no |
@@ -545,6 +546,7 @@ statement instead the previous block.
545546
| <a name="input_registry_namespace"></a> [registry\_namespace](#input\_registry\_namespace) | A unique namespace within the IBM Cloud Container Registry region where the application image is stored. | `string` | `""` | no |
546547
| <a name="input_repo_git_token_secret_crn"></a> [repo\_git\_token\_secret\_crn](#input\_repo\_git\_token\_secret\_crn) | The CRN for the repositories Git Token. | `string` | `""` | no |
547548
| <a name="input_repo_git_token_secret_name"></a> [repo\_git\_token\_secret\_name](#input\_repo\_git\_token\_secret\_name) | Name of the Git token secret in the secret provider. Specifying a secret name for the Git Token automatically sets the authentication type to `pat`. | `string` | `""` | no |
549+
| <a name="input_repo_git_token_secret_value"></a> [repo\_git\_token\_secret\_value](#input\_repo\_git\_token\_secret\_value) | The personal access token that will be added to the `repo_git_token_secret_name` secret in the secrets provider. | `string` | `""` | no |
548550
| <a name="input_repo_group"></a> [repo\_group](#input\_repo\_group) | Specify the Git user or group for your application. This must be set if the repository authentication type is `pat` (personal access token). | `string` | `""` | no |
549551
| <a name="input_repo_secret_group"></a> [repo\_secret\_group](#input\_repo\_secret\_group) | Secret group in Secrets Manager that contains the secret for the repository. This variable will set the same secret group for all the repositories. Can be overriden on a per secret group basis. Only applies when using Secrets Manager. | `string` | `""` | no |
550552
| <a name="input_repositories_prefix"></a> [repositories\_prefix](#input\_repositories\_prefix) | Prefix name for the cloned compliance repos. For the repositories\_prefix value only a-z, A-Z and 0-9 and the special characters `-_` are allowed. In addition the string must not end with a special character or have two consecutive special characters. | `string` | `"compliance"` | no |

ibm_catalog.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,13 @@
10661066
"description": "Set to `true` to create and add a `cos-api-key` to the Secrets Provider.",
10671067
"required": false
10681068
},
1069+
{
1070+
"key": "create_git_token",
1071+
"type": "boolean",
1072+
"default_value": false,
1073+
"description": "Set to `true` to create and add the specified personal access token secret to the Secrets Provider.",
1074+
"required": false
1075+
},
10691076
{
10701077
"key": "create_ibmcloud_api_key",
10711078
"type": "boolean",
@@ -1486,6 +1493,13 @@
14861493
"description": "Name of the Git token secret in the secret provider. Specifying a secret name for the Git Token automatically sets the authentication type to `pat`.",
14871494
"required": false
14881495
},
1496+
{
1497+
"key": "repo_git_token_secret_value",
1498+
"type": "password",
1499+
"default_value": "",
1500+
"description": "The personal access token that will be added to the `repo_git_token_secret_name` secret in the secrets provider.",
1501+
"required": false
1502+
},
14891503
{
14901504
"key": "repo_group",
14911505
"type": "string",
@@ -2848,6 +2862,13 @@
28482862
"description": "Set to `true` to create and add a `cos-api-key` to the Secrets Provider.",
28492863
"required": false
28502864
},
2865+
{
2866+
"key": "create_git_token",
2867+
"type": "boolean",
2868+
"default_value": false,
2869+
"description": "Set to `true` to create and add the specified personal access token secret to the Secrets Provider.",
2870+
"required": false
2871+
},
28512872
{
28522873
"key": "create_ibmcloud_api_key",
28532874
"type": "boolean",
@@ -3268,6 +3289,13 @@
32683289
"description": "Name of the Git token secret in the secret provider. Specifying a secret name for the Git Token automatically sets the authentication type to `pat`.",
32693290
"required": false
32703291
},
3292+
{
3293+
"key": "repo_git_token_secret_value",
3294+
"type": "password",
3295+
"default_value": "",
3296+
"description": "The personal access token that will be added to the `repo_git_token_secret_name` secret in the secrets provider.",
3297+
"required": false
3298+
},
32713299
{
32723300
"key": "repo_group",
32733301
"type": "string",

main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ module "prereqs" {
231231
source = "./prereqs"
232232
create_ibmcloud_api_key = var.create_ibmcloud_api_key
233233
create_cos_api_key = var.create_cos_api_key
234+
create_git_token = var.create_git_token
234235
create_signing_key = var.create_signing_key
235236
create_signing_certificate = var.create_signing_certificate
236237
service_name_pipeline = var.service_name_pipeline
@@ -244,6 +245,8 @@ module "prereqs" {
244245
iam_api_key_secret_name = var.pipeline_ibmcloud_api_key_secret_name
245246
signing_key_secret_name = var.ci_signing_key_secret_name
246247
signing_certifcate_secret_name = var.cd_code_signing_cert_secret_name
248+
repo_git_token_secret_name = var.repo_git_token_secret_name
249+
repo_git_token_secret_value = var.repo_git_token_secret_value
247250
rotation_period = var.rotation_period
248251
sm_secret_expiration_period = var.sm_secret_expiration_period
249252
sm_exists = var.enable_secrets_manager

prereqs/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ resource "ibm_sm_arbitrary_secret" "secret_signing_certifcate" {
198198
endpoint_type = var.sm_endpoint_type
199199
}
200200

201+
resource "ibm_sm_arbitrary_secret" "git_token" {
202+
count = ((var.create_git_token == true) && (var.sm_exists == true)) ? 1 : 0
203+
depends_on = [ibm_sm_secret_group.sm_secret_group]
204+
region = var.sm_location
205+
instance_id = (local.sm_instance_id != "") ? local.sm_instance_id : var.sm_instance_id
206+
secret_group_id = (var.create_secret_group == false) ? data.ibm_sm_secret_group.existing_sm_secret_group[0].secret_group_id : ibm_sm_secret_group.sm_secret_group[0].secret_group_id
207+
name = var.repo_git_token_secret_name
208+
description = "A personal access token for accessing your repositories."
209+
labels = []
210+
payload = var.repo_git_token_secret_value
211+
expiration_date = local.expiration_date
212+
endpoint_type = var.sm_endpoint_type
213+
}
214+
201215
################## IAM CREDENTIALS###############################
202216
resource "ibm_sm_iam_credentials_secret" "iam_pipeline_apikey_credentials_secret" {
203217
count = ((var.create_ibmcloud_api_key == true) && (var.sm_exists == true)) ? 1 : 0

prereqs/variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ variable "create_signing_certificate" {
4040
default = false
4141
}
4242

43+
variable "create_git_token" {
44+
type = bool
45+
description = "Set to `true` to create and add the specified personal access token secret to the Secrets Provider."
46+
default = false
47+
}
48+
49+
variable "repo_git_token_secret_name" {
50+
type = string
51+
description = "Name of the Git token secret in the secret provider. Specifying a secret name for the Git Token automatically sets the authentication type to `pat`."
52+
default = ""
53+
}
54+
55+
variable "repo_git_token_secret_value" {
56+
type = string
57+
sensitive = true
58+
description = "The personal access token that will be added to the `repo_git_token_secret_name` secret in the secrets provider."
59+
default = ""
60+
}
61+
4362
variable "sm_exists" {
4463
description = "Only connect to the Secrets Manager instance if it has been enabled for the toolchain."
4564
type = bool

solutions/code-engine/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ No resources.
461461
| <a name="input_create_cd_toolchain"></a> [create\_cd\_toolchain](#input\_create\_cd\_toolchain) | Boolean flag which determines if the DevSecOps CD toolchain is created. | `bool` | `true` | no |
462462
| <a name="input_create_ci_toolchain"></a> [create\_ci\_toolchain](#input\_create\_ci\_toolchain) | Flag which determines if the DevSecOps CI toolchain is created. If this toolchain is not created then values must be set for the following variables, evidence\_repo\_url, issues\_repo\_url and inventory\_repo\_url. | `bool` | `true` | no |
463463
| <a name="input_create_cos_api_key"></a> [create\_cos\_api\_key](#input\_create\_cos\_api\_key) | Set to `true` to create and add a `cos-api-key` to the Secrets Provider. | `bool` | `false` | no |
464+
| <a name="input_create_git_token"></a> [create\_git\_token](#input\_create\_git\_token) | Set to `true` to create and add the specified personal access token secret to the Secrets Provider. | `bool` | `false` | no |
464465
| <a name="input_create_ibmcloud_api_key"></a> [create\_ibmcloud\_api\_key](#input\_create\_ibmcloud\_api\_key) | Set to `true` to create and add an `ibmcloud-api-key` to the Secrets Provider. | `bool` | `false` | no |
465466
| <a name="input_create_icr_namespace"></a> [create\_icr\_namespace](#input\_create\_icr\_namespace) | Set to `true` to have Terraform create the registry namespace. Setting to `false` will have the CI pipeline create the namespace if it does not already exist. Note: If a Terraform destroy is used, the ICR namespace along with all images will be removed. | `bool` | `false` | no |
466467
| <a name="input_create_secret_group"></a> [create\_secret\_group](#input\_create\_secret\_group) | Set to `true` to create the specified Secrets Manager secret group. | `bool` | `false` | no |
@@ -529,6 +530,7 @@ No resources.
529530
| <a name="input_registry_namespace"></a> [registry\_namespace](#input\_registry\_namespace) | A unique namespace within the IBM Cloud Container Registry region where the application image is stored. | `string` | `""` | no |
530531
| <a name="input_repo_git_token_secret_crn"></a> [repo\_git\_token\_secret\_crn](#input\_repo\_git\_token\_secret\_crn) | The CRN for the repositories Git Token. | `string` | `""` | no |
531532
| <a name="input_repo_git_token_secret_name"></a> [repo\_git\_token\_secret\_name](#input\_repo\_git\_token\_secret\_name) | Name of the Git token secret in the secret provider. Specifying a secret name for the Git Token automatically sets the authentication type to `pat`. | `string` | `""` | no |
533+
| <a name="input_repo_git_token_secret_value"></a> [repo\_git\_token\_secret\_value](#input\_repo\_git\_token\_secret\_value) | The personal access token that will be added to the `repo_git_token_secret_name` secret in the secrets provider. | `string` | `""` | no |
532534
| <a name="input_repo_group"></a> [repo\_group](#input\_repo\_group) | Specify the Git user or group for your application. This must be set if the repository authentication type is `pat` (personal access token). | `string` | `""` | no |
533535
| <a name="input_repo_secret_group"></a> [repo\_secret\_group](#input\_repo\_secret\_group) | Secret group in Secrets Manager that contains the secret for the repository. This variable will set the same secret group for all the repositories. Can be overriden on a per secret group basis. Only applies when using Secrets Manager. | `string` | `""` | no |
534536
| <a name="input_repositories_prefix"></a> [repositories\_prefix](#input\_repositories\_prefix) | Prefix name for the cloned compliance repos. For the repositories\_prefix value only a-z, A-Z and 0-9 and the special characters `-_` are allowed. In addition the string must not end with a special character or have two consecutive special characters. | `string` | `"compliance"` | no |

solutions/code-engine/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module "devsecops_da" {
3535
create_cd_toolchain = var.create_cd_toolchain
3636
create_ci_toolchain = var.create_ci_toolchain
3737
create_cos_api_key = var.create_cos_api_key
38+
create_git_token = var.create_git_token
3839
create_ibmcloud_api_key = var.create_ibmcloud_api_key
3940
create_icr_namespace = var.create_icr_namespace
4041
create_secret_group = var.create_secret_group
@@ -102,6 +103,7 @@ module "devsecops_da" {
102103
registry_namespace = var.registry_namespace
103104
repo_git_token_secret_crn = var.repo_git_token_secret_crn
104105
repo_git_token_secret_name = var.repo_git_token_secret_name
106+
repo_git_token_secret_value = var.repo_git_token_secret_value
105107
repo_group = var.repo_group
106108
repo_secret_group = var.repo_secret_group
107109
repositories_prefix = var.repositories_prefix

solutions/code-engine/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ variable "create_cos_api_key" {
223223
default = false
224224
}
225225

226+
variable "create_git_token" {
227+
type = bool
228+
description = "Set to `true` to create and add the specified personal access token secret to the Secrets Provider."
229+
default = false
230+
}
231+
226232
variable "create_ibmcloud_api_key" {
227233
type = bool
228234
description = "Set to `true` to create and add an `ibmcloud-api-key` to the Secrets Provider."
@@ -678,6 +684,13 @@ variable "repo_git_token_secret_name" {
678684
default = ""
679685
}
680686

687+
variable "repo_git_token_secret_value" {
688+
type = string
689+
sensitive = true
690+
description = "The personal access token that will be added to the `repo_git_token_secret_name` secret in the secrets provider."
691+
default = ""
692+
}
693+
681694
variable "repo_group" {
682695
type = string
683696
description = "Specify the Git user or group for your application. This must be set if the repository authentication type is `pat` (personal access token)."

solutions/kubernetes/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ No resources.
461461
| <a name="input_create_cd_toolchain"></a> [create\_cd\_toolchain](#input\_create\_cd\_toolchain) | Boolean flag which determines if the DevSecOps CD toolchain is created. | `bool` | `true` | no |
462462
| <a name="input_create_ci_toolchain"></a> [create\_ci\_toolchain](#input\_create\_ci\_toolchain) | Flag which determines if the DevSecOps CI toolchain is created. If this toolchain is not created then values must be set for the following variables, evidence\_repo\_url, issues\_repo\_url and inventory\_repo\_url. | `bool` | `true` | no |
463463
| <a name="input_create_cos_api_key"></a> [create\_cos\_api\_key](#input\_create\_cos\_api\_key) | Set to `true` to create and add a `cos-api-key` to the Secrets Provider. | `bool` | `false` | no |
464+
| <a name="input_create_git_token"></a> [create\_git\_token](#input\_create\_git\_token) | Set to `true` to create and add the specified personal access token secret to the Secrets Provider. | `bool` | `false` | no |
464465
| <a name="input_create_ibmcloud_api_key"></a> [create\_ibmcloud\_api\_key](#input\_create\_ibmcloud\_api\_key) | Set to `true` to create and add an `ibmcloud-api-key` to the Secrets Provider. | `bool` | `false` | no |
465466
| <a name="input_create_icr_namespace"></a> [create\_icr\_namespace](#input\_create\_icr\_namespace) | Set to `true` to have Terraform create the registry namespace. Setting to `false` will have the CI pipeline create the namespace if it does not already exist. Note: If a Terraform destroy is used, the ICR namespace along with all images will be removed. | `bool` | `false` | no |
466467
| <a name="input_create_secret_group"></a> [create\_secret\_group](#input\_create\_secret\_group) | Set to `true` to create the specified Secrets Manager secret group. | `bool` | `false` | no |
@@ -529,6 +530,7 @@ No resources.
529530
| <a name="input_registry_namespace"></a> [registry\_namespace](#input\_registry\_namespace) | A unique namespace within the IBM Cloud Container Registry region where the application image is stored. | `string` | `""` | no |
530531
| <a name="input_repo_git_token_secret_crn"></a> [repo\_git\_token\_secret\_crn](#input\_repo\_git\_token\_secret\_crn) | The CRN for the repositories Git Token. | `string` | `""` | no |
531532
| <a name="input_repo_git_token_secret_name"></a> [repo\_git\_token\_secret\_name](#input\_repo\_git\_token\_secret\_name) | Name of the Git token secret in the secret provider. Specifying a secret name for the Git Token automatically sets the authentication type to `pat`. | `string` | `""` | no |
533+
| <a name="input_repo_git_token_secret_value"></a> [repo\_git\_token\_secret\_value](#input\_repo\_git\_token\_secret\_value) | The personal access token that will be added to the `repo_git_token_secret_name` secret in the secrets provider. | `string` | `""` | no |
532534
| <a name="input_repo_group"></a> [repo\_group](#input\_repo\_group) | Specify the Git user or group for your application. This must be set if the repository authentication type is `pat` (personal access token). | `string` | `""` | no |
533535
| <a name="input_repo_secret_group"></a> [repo\_secret\_group](#input\_repo\_secret\_group) | Secret group in Secrets Manager that contains the secret for the repository. This variable will set the same secret group for all the repositories. Can be overriden on a per secret group basis. Only applies when using Secrets Manager. | `string` | `""` | no |
534536
| <a name="input_repositories_prefix"></a> [repositories\_prefix](#input\_repositories\_prefix) | Prefix name for the cloned compliance repos. For the repositories\_prefix value only a-z, A-Z and 0-9 and the special characters `-_` are allowed. In addition the string must not end with a special character or have two consecutive special characters. | `string` | `"compliance"` | no |

0 commit comments

Comments
 (0)