Skip to content

Commit 1073e58

Browse files
authored
Merge pull request #2 from tbobm/feat/create-secrets
feat/create secrets
2 parents 4ba08ae + e251b12 commit 1073e58

File tree

6 files changed

+62
-2
lines changed

6 files changed

+62
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ No modules.
7171

7272
| Name | Type |
7373
|------|------|
74-
| [github_repository.repo](https://registry.terraform.io/providers/integrations/github/latest/docs/data-sources/repository) | data source |
74+
| [github_actions_secret.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/actions_secret) | resource |
75+
| [github_repository.this](https://registry.terraform.io/providers/integrations/github/latest/docs/data-sources/repository) | data source |
7576

7677
## Inputs
7778

7879
| Name | Description | Type | Default | Required |
7980
|------|-------------|------|---------|:--------:|
81+
| <a name="input_environment_secrets"></a> [environment\_secrets](#input\_environment\_secrets) | A map of environment-scoped secrets | `map(any)` | `{}` | no |
8082
| <a name="input_repository"></a> [repository](#input\_repository) | The full name of the repository in the form org/repo | `string` | n/a | yes |
83+
| <a name="input_secrets"></a> [secrets](#input\_secrets) | A map of secret definitions | `map(any)` | `{}` | no |
8184

8285
## Outputs
8386

data.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
data "github_repository" "repo" {
1+
data "github_repository" "this" {
22
full_name = var.repository
33
}

example/main.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module "env" {
2+
source = "tbobm/environments/github"
3+
version = "1.0.0"
4+
5+
repository = "tbobm/terraform-github-secrets"
6+
7+
environments = {
8+
"staging" = {}
9+
"production" = {}
10+
}
11+
}
12+
13+
module "secrets" {
14+
source = "../"
15+
16+
repository = "tbobm/terraform-github-secrets"
17+
18+
secrets = {
19+
deploy_key = {
20+
name = "DEPLOY_KEY"
21+
plaintext = "ABCDEF"
22+
}
23+
registry_username = {
24+
name = "DOCKERHUB_USERNAME"
25+
plaintext = "sampleuser"
26+
}
27+
registry_password = {
28+
name = "DOCKERHUB_PASSWORD"
29+
plaintext = "samplepass"
30+
}
31+
}
32+
}

locals.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
locals {
2+
secrets = {
3+
for key, value in var.secrets :
4+
key => value
5+
}
6+
}

main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "github_actions_secret" "this" {
2+
for_each = local.secrets
3+
4+
repository = data.github_repository.this.name
5+
secret_name = each.value.name
6+
plaintext_value = each.value.plaintext
7+
}

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,15 @@ variable "repository" {
22
type = string
33
description = "The full name of the repository in the form org/repo"
44
}
5+
6+
variable "secrets" {
7+
type = map(any)
8+
description = "A map of secret definitions"
9+
default = {}
10+
}
11+
12+
variable "environment_secrets" {
13+
type = map(any)
14+
description = "A map of environment-scoped secrets"
15+
default = {}
16+
}

0 commit comments

Comments
 (0)