Skip to content

Commit

Permalink
Merge pull request #2 from tbobm/feat/create-secrets
Browse files Browse the repository at this point in the history
feat/create secrets
  • Loading branch information
tbobm authored Dec 4, 2021
2 parents 4ba08ae + e251b12 commit 1073e58
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ No modules.

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

## Inputs

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

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion data.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
data "github_repository" "repo" {
data "github_repository" "this" {
full_name = var.repository
}
32 changes: 32 additions & 0 deletions example/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module "env" {
source = "tbobm/environments/github"
version = "1.0.0"

repository = "tbobm/terraform-github-secrets"

environments = {
"staging" = {}
"production" = {}
}
}

module "secrets" {
source = "../"

repository = "tbobm/terraform-github-secrets"

secrets = {
deploy_key = {
name = "DEPLOY_KEY"
plaintext = "ABCDEF"
}
registry_username = {
name = "DOCKERHUB_USERNAME"
plaintext = "sampleuser"
}
registry_password = {
name = "DOCKERHUB_PASSWORD"
plaintext = "samplepass"
}
}
}
6 changes: 6 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
locals {
secrets = {
for key, value in var.secrets :
key => value
}
}
7 changes: 7 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "github_actions_secret" "this" {
for_each = local.secrets

repository = data.github_repository.this.name
secret_name = each.value.name
plaintext_value = each.value.plaintext
}
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@ variable "repository" {
type = string
description = "The full name of the repository in the form org/repo"
}

variable "secrets" {
type = map(any)
description = "A map of secret definitions"
default = {}
}

variable "environment_secrets" {
type = map(any)
description = "A map of environment-scoped secrets"
default = {}
}

0 comments on commit 1073e58

Please sign in to comment.