Skip to content

Commit 7a05573

Browse files
committed
Initial Commit
0 parents  commit 7a05573

File tree

10 files changed

+178
-0
lines changed

10 files changed

+178
-0
lines changed

.github/workflows/lint.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
on:
2+
push:
3+
4+
jobs:
5+
tflint:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- uses: actions/checkout@v2
10+
name: Checkout source code
11+
12+
- uses: actions/cache@v2
13+
name: Cache plugin dir
14+
with:
15+
path: ~/.tflint.d/plugins
16+
key: ${{ matrix.os }}-tflint-${{ hashFiles('.tflint.hcl') }}
17+
18+
- uses: terraform-linters/setup-tflint@v1
19+
name: Setup TFLint
20+
with:
21+
tflint_version: v0.29.0
22+
23+
- name: Show version
24+
run: tflint --version
25+
26+
- name: Init TFLint
27+
run: tflint --init
28+
29+
- name: Run TFLint
30+
run: tflint -f compact

.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
**/.terraform/*
2+
*.tfstate
3+
*.tfstate.*
4+
crash.log
5+
*.tfvars
6+
override.tf
7+
override.tf.json
8+
*_override.tf
9+
*_override.tf.json
10+
.terraformrc
11+
terraform.rc
12+
.idea
13+
**.idea/**
14+
*.iml
15+
out
16+
gen

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Mathias V. Nielsen
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# terraform-github-action-secrets
2+
3+
Easily manage secrets across multiple repositories with shared and unique secrets.
4+
5+
## How to use
6+
7+
All secrets stored under the "all" object will be applied to all repositories.
8+
To add secrets that only go to one repository add an object (In the example, see "test") that contains the unique secrets
9+
10+
```hcl
11+
terraform {
12+
required_providers {
13+
github = {
14+
source = "integrations/github"
15+
version = "~> 4.0"
16+
}
17+
}
18+
}
19+
20+
# Remember the repository owner always defaults to the key owner
21+
# define the owner attribute if you need another
22+
provider "github" {
23+
token = var.token
24+
}
25+
26+
module "github-secrets" {
27+
source = "math280h/action-secrets/github"
28+
version = "0.0.1"
29+
30+
# In this example this would point to one repository with the full name
31+
# math280h/test
32+
# And two secrets would be created, "test" from the "all" object and
33+
# since the name matches, "test1" from the "test" object.
34+
repositories = [{ name = "test" }]
35+
secrets = { "all" = { "test" = "test" }, "test" = { "test1" = "test1" } }
36+
}
37+
```

locals.tf

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
locals {
2+
module_secrets = flatten([
3+
for module_key, gh_module in var.repositories : {
4+
name = gh_module[ "name" ],
5+
secrets = merge(
6+
var.secrets[ "all" ],
7+
lookup(var.secrets, gh_module[ "name" ], {})
8+
)
9+
}
10+
])
11+
12+
module_secrets_list = flatten([
13+
for module_secret_key, module_secret_object in local.module_secrets : [
14+
for secret_key, secret_value in module_secret_object[ "secrets" ] : {
15+
repo = module_secret_object[ "name" ]
16+
name = secret_key
17+
value = secret_value
18+
}
19+
]
20+
])
21+
}

providers.tf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
github = {
4+
source = "integrations/github"
5+
version = "~> 4.0"
6+
}
7+
}
8+
}

secrets.tf

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
data "github_actions_public_key" "repo_public_key" {
2+
3+
for_each = { for project_module in var.repositories : project_module[ "name" ] => project_module }
4+
5+
repository = each.value.name
6+
7+
}
8+
9+
resource "github_actions_secret" "custom_repo_secrets" {
10+
11+
for_each = { for object in local.module_secrets_list : "${ object[ "repo" ] }-${ object[ "name" ] }" => object }
12+
13+
repository = each.value.repo
14+
secret_name = each.value.name
15+
plaintext_value = each.value.value
16+
17+
}

test/main.tf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
terraform {
2+
required_providers {
3+
github = {
4+
source = "integrations/github"
5+
version = "~> 4.0"
6+
}
7+
}
8+
}
9+
10+
provider "github" {
11+
token = var.token
12+
}
13+
14+
module "github-secrets" {
15+
source = "../"
16+
17+
repositories = [ { name = "test" } ]
18+
secrets = {"all"={"test"="test"}, "test"={"test1"="test1"}}
19+
}

test/variables.tf

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
variable "token" {}

variables.tf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
variable "repositories" {
2+
type = list(object({name=string}))
3+
description = "List of repositories"
4+
}
5+
6+
variable "secrets" {
7+
description = "Secrets to add"
8+
}

0 commit comments

Comments
 (0)