Skip to content

Commit 13b66b7

Browse files
authored
Merge branch 'main' into require_conversation_resolution
2 parents e7cf4f0 + 7945749 commit 13b66b7

File tree

7 files changed

+109
-29
lines changed

7 files changed

+109
-29
lines changed

README.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -715,22 +715,45 @@ This is due to some terraform limitation and we will update the module once terr
715715
- [**`plaintext_secrets`**](#var-plaintext_secrets): *(Optional `map(string)`)*<a name="var-plaintext_secrets"></a>
716716

717717
This map allows you to create and manage secrets for repositories in your organization.
718+
718719
Each element in the map is considered a secret to be managed, being the key map the secret name and the value the corresponding secret in plain text:
719720

720-
```
721+
When applied, a secret with the given key and value will be created in the repositories.
722+
723+
The value of the secrets must be given in plain text, GitHub provider is in charge of encrypting it.
724+
725+
**Attention:** You should treat state as sensitive always. It is also advised that you do not store plaintext values in your code but rather populate the encrypted_value using fields from a resource, data source or variable as, while encrypted in state, these will be easily accessible in your code. See below for an example of this abstraction.
726+
727+
Default is `{}`.
728+
729+
Example:
730+
731+
```hcl
721732
plaintext_secrets = {
722-
SECRET_NAME_1 = "secret_value_1"
723-
SECRET_NAME_2 = "secret_value_2"
724-
...
733+
SECRET_NAME_1 = "plaintext_secret_value_1"
734+
SECRET_NAME_2 = "plaintext_secret_value_2"
725735
}
726736
```
727737

738+
- [**`encrypted_secrets`**](#var-encrypted_secrets): *(Optional `map(string)`)*<a name="var-encrypted_secrets"></a>
739+
740+
This map allows you to create and manage encrypted secrets for repositories in your organization.
741+
742+
Each element in the map is considered a secret to be managed, being the key map the secret name and the value the corresponding encrypted value of the secret using the Github public key in Base64 format.b
743+
728744
When applied, a secret with the given key and value will be created in the repositories.
729-
The value of the secrets must be given in plain text, github provider is in charge of encrypting it.
730-
**Attention:** You might want to get secrets via a data source from a secure vault and not add them in plain text to your source files; so you do not commit plaintext secrets into the git repository managing your github account.
731745

732746
Default is `{}`.
733747

748+
Example:
749+
750+
```hcl
751+
encrypted_secrets = {
752+
SECRET_NAME_1 = "c2VjcmV0X3ZhbHVlXzE="
753+
SECRET_NAME_2 = "c2VjcmV0X3ZhbHVlXzI="
754+
}
755+
```
756+
734757
- [**`required_approving_review_count`**](#var-required_approving_review_count): *(Optional `number`)*<a name="var-required_approving_review_count"></a>
735758

736759
Require x number of approvals to satisfy branch protection requirements.
@@ -758,7 +781,7 @@ This is due to some terraform limitation and we will update the module once terr
758781

759782
### Module Configuration
760783

761-
- [**`module_depends_on`**](#var-module_depends_on): *(Optional `list(any)`)*<a name="var-module_depends_on"></a>
784+
- [**`module_depends_on`**](#var-module_depends_on): *(Optional `list(dependency)`)*<a name="var-module_depends_on"></a>
762785

763786
Due to the fact, that terraform does not offer `depends_on` on modules as of today (v0.12.24)
764787
we might hit race conditions when dealing with team names instead of ids.

README.tfdoc.hcl

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -938,19 +938,40 @@ section {
938938
default = {}
939939
description = <<-END
940940
This map allows you to create and manage secrets for repositories in your organization.
941+
941942
Each element in the map is considered a secret to be managed, being the key map the secret name and the value the corresponding secret in plain text:
942943
943-
```
944+
When applied, a secret with the given key and value will be created in the repositories.
945+
946+
The value of the secrets must be given in plain text, GitHub provider is in charge of encrypting it.
947+
948+
**Attention:** You should treat state as sensitive always. It is also advised that you do not store plaintext values in your code but rather populate the encrypted_value using fields from a resource, data source or variable as, while encrypted in state, these will be easily accessible in your code. See below for an example of this abstraction.
949+
END
950+
951+
readme_example = <<-END
944952
plaintext_secrets = {
945-
SECRET_NAME_1 = "secret_value_1"
946-
SECRET_NAME_2 = "secret_value_2"
947-
...
953+
SECRET_NAME_1 = "plaintext_secret_value_1"
954+
SECRET_NAME_2 = "plaintext_secret_value_2"
948955
}
949-
```
956+
END
957+
}
958+
959+
variable "encrypted_secrets" {
960+
type = map(string)
961+
default = {}
962+
description = <<-END
963+
This map allows you to create and manage encrypted secrets for repositories in your organization.
964+
965+
Each element in the map is considered a secret to be managed, being the key map the secret name and the value the corresponding encrypted value of the secret using the Github public key in Base64 format.b
950966
951967
When applied, a secret with the given key and value will be created in the repositories.
952-
The value of the secrets must be given in plain text, github provider is in charge of encrypting it.
953-
**Attention:** You might want to get secrets via a data source from a secure vault and not add them in plain text to your source files; so you do not commit plaintext secrets into the git repository managing your github account.
968+
END
969+
970+
readme_example = <<-END
971+
encrypted_secrets = {
972+
SECRET_NAME_1 = "c2VjcmV0X3ZhbHVlXzE="
973+
SECRET_NAME_2 = "c2VjcmV0X3ZhbHVlXzI="
974+
}
954975
END
955976
}
956977

@@ -998,7 +1019,7 @@ section {
9981019
title = "Module Configuration"
9991020

10001021
variable "module_depends_on" {
1001-
type = list(any)
1022+
type = list(dependency)
10021023
default = []
10031024
description = <<-END
10041025
Due to the fact, that terraform does not offer `depends_on` on modules as of today (v0.12.24)

main.tf

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -458,18 +458,6 @@ resource "github_repository_webhook" "repository_webhook" {
458458
}
459459
}
460460

461-
# ---------------------------------------------------------------------------------------------------------------------
462-
# Action Secrets
463-
# ---------------------------------------------------------------------------------------------------------------------
464-
465-
resource "github_actions_secret" "repository_secret" {
466-
for_each = var.plaintext_secrets
467-
468-
repository = github_repository.repository.name
469-
secret_name = each.key
470-
plaintext_value = each.value
471-
}
472-
473461
# ---------------------------------------------------------------------------------------------------------------------
474462
# Autolink References
475463
# ---------------------------------------------------------------------------------------------------------------------

secrets.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# ---------------------------------------------------------------------------------------------------------------------
2+
# Action Secrets
3+
# ---------------------------------------------------------------------------------------------------------------------
4+
5+
locals {
6+
plaintext_secrets = { for name, value in var.plaintext_secrets : name => { plaintext = value } }
7+
encrypted_secrets = { for name, value in var.encrypted_secrets : name => { encrypted = value } }
8+
9+
secrets = merge(local.plaintext_secrets, local.encrypted_secrets)
10+
}
11+
12+
resource "github_actions_secret" "repository_secret" {
13+
for_each = local.secrets
14+
15+
repository = github_repository.repository.name
16+
secret_name = each.key
17+
plaintext_value = try(each.value.plaintext, null)
18+
encrypted_value = try(each.value.encrypted, null)
19+
}

test/unit-complete/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ module "repository" {
6060
(var.secret_name) = var.secret_text
6161
}
6262

63+
encrypted_secrets = {
64+
(var.encrypted_secret_name) = var.encrypted_secret_text
65+
}
66+
6367
pages = {
6468
branch = "main"
6569
path = "/"

test/unit-complete/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ variable "secret_text" {
195195
default = "42"
196196
}
197197

198+
variable "encrypted_secret_name" {
199+
description = "The name of the secret."
200+
type = string
201+
default = "ENCRYPTEDSECRET"
202+
}
203+
204+
variable "encrypted_secret_text" {
205+
description = "Secret value in Base64 format."
206+
type = string
207+
default = "NDI="
208+
}
209+
198210
variable "webhook_url" {
199211
description = "Send events to this URL"
200212
type = string

variables.tf

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,18 +462,31 @@ variable "webhooks" {
462462
}
463463

464464
variable "plaintext_secrets" {
465-
description = "(Optional) Configuring actions secrets. For details please check: https://www.terraform.io/docs/providers/github/r/actions_secret.html"
465+
description = "(Optional) Configuring actions secrets. For details please check: https://www.terraform.io/docs/providers/github/r/actions_secret"
466466
type = map(string)
467467

468468
# Example:
469-
# secrets = {
469+
# plaintext_secrets = {
470470
# "MY_SECRET" = "42"
471471
# "OWN_TOKEN" = "12345"
472472
# }
473473

474474
default = {}
475475
}
476476

477+
variable "encrypted_secrets" {
478+
description = "(Optional) Configuring encrypted actions secrets. For details please check: https://www.terraform.io/docs/providers/github/r/actions_secret"
479+
type = map(string)
480+
481+
# Example:
482+
# encrypted_secrets = {
483+
# "MY_ENCRYPTED_SECRET" = "MTIzNDU="
484+
# }
485+
486+
default = {}
487+
}
488+
489+
477490
variable "autolink_references" {
478491
description = "(Optional) Configuring autolink references. For details please check: https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_autolink_reference"
479492
type = list(object({

0 commit comments

Comments
 (0)