-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add new gh-files-set module #970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 29 commits
648bf41
900aa51
0be8dbf
44ad6b2
35b7c2c
5aae430
51827d8
6fb689e
f046d0e
48c6e67
82d09b0
e5d36cd
57b46d1
b1d49ee
70e31e0
05c77f9
40a8360
a10780f
f1d8e98
75c7937
fd9e16f
7869fdc
5a88544
7cb469e
2c09af2
9aae9fb
69b2c5f
258f05e
f760419
6ca12b3
d63731b
1b96a9e
765e734
82b89c3
b62f590
28bb910
7220434
e3fc0b5
9266463
7cd8c44
e1377f6
6822db9
65d3f92
a1fcb45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| formatter: "markdown" | ||
|
|
||
| version: "" | ||
|
|
||
| header-from: docs/header.md | ||
| footer-from: docs/footer.md | ||
|
|
||
| recursive: | ||
| enabled: false | ||
| path: modules | ||
| include-main: true | ||
|
|
||
| sections: | ||
| hide: [] | ||
| show: [] | ||
|
|
||
| content: "" | ||
|
|
||
| output: | ||
| file: "README.md" | ||
| mode: inject | ||
| template: |- | ||
| <!-- BEGIN_TF_DOCS --> | ||
| {{ .Content }} | ||
| <!-- END_TF_DOCS --> | ||
|
|
||
| output-values: | ||
| enabled: false | ||
| from: "" | ||
|
|
||
| sort: | ||
| enabled: true | ||
| by: name | ||
|
|
||
| settings: | ||
| anchor: true | ||
| color: true | ||
| default: true | ||
| description: false | ||
| escape: true | ||
| hide-empty: false | ||
| html: true | ||
| indent: 2 | ||
| lockfile: true | ||
| read-comments: true | ||
| required: true | ||
| sensitive: true | ||
| type: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <!-- BEGIN_TF_DOCS --> | ||
| # **GitHub Files Set Terraform Module** | ||
|
|
||
| ## Overview | ||
|
|
||
| This module creates or updates one or more files in GitHub repositories using the `github_repository_file` resource. | ||
| It is designed to be used in automated repository bootstrapping / golden-path workflows. | ||
|
|
||
| It accepts a list of files in a single `config` object — ideal for YAML/JSON input from external tools. | ||
|
|
||
| ## Key Features | ||
|
|
||
| - Multiple files in one module call | ||
| - Per-file branch, commit message, overwrite control | ||
| - Native GitHub provider integration | ||
| - Input validation on required fields | ||
| - Clean outputs for downstream usage | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| ```hcl | ||
| module "files" { | ||
| source = "git::https://github.com/prefapp/tfm.git//modules/gh-files-set" | ||
|
|
||
| config = yamldecode(file("${path.module}/files.yaml")) | ||
| # or jsondecode(...) if using JSON | ||
| } | ||
| ``` | ||
|
|
||
| ## Requirements | ||
|
|
||
| | Name | Version | | ||
| |------|---------| | ||
| | <a name="requirement_github"></a> [github](#requirement\_github) | ~> 6.0 | | ||
|
|
||
| ## Providers | ||
|
|
||
| | Name | Version | | ||
| |------|---------| | ||
| | <a name="provider_github"></a> [github](#provider\_github) | ~> 6.0 | | ||
|
|
||
| ## Modules | ||
|
|
||
| No modules. | ||
|
|
||
| ## Resources | ||
|
|
||
| | Name | Type | | ||
| |------|------| | ||
| | [github_repository_file.managed](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file) | resource | | ||
| | [github_repository_file.user_managed](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file) | 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_config"></a> [config](#input\_config) | GitHub files configuration — userManaged files are provisioned once and survive destroy | <pre>object({<br/> files = list(object({<br/> branch = string<br/> commitMessage = string<br/> content = string<br/> file = string<br/> repository = string<br/> overwriteOnCreate = optional(bool, true)<br/> userManaged = optional(bool, false)<br/> }))<br/><br/> repository = string<br/> })</pre> | n/a | yes | | ||
|
|
||
| ## Outputs | ||
|
|
||
| | Name | Description | | ||
| |------|-------------| | ||
| | <a name="output_user_managed_files"></a> [user\_managed\_files](#output\_user\_managed\_files) | Files marked as userManaged (will survive destroy) | | ||
|
|
||
| ### 5. `docs/footer.md` | ||
|
|
||
| ```markdown | ||
| ## Examples | ||
|
|
||
| See [_examples/basic](https://github.com/prefapp/tfm/tree/main/modules/gh-files-set/_examples/basic) | ||
|
|
||
| ## Resources | ||
|
|
||
| - **github_repository_file** | ||
| https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file | ||
|
|
||
| ## Support | ||
|
|
||
| Open issues in https://github.com/prefapp/tfm/issues | ||
| ``` | ||
frmadem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <!-- END_TF_DOCS --> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| config: | ||
| repository: org/component_c | ||
| files: | ||
| - branch: main | ||
| commitMessage: "feat: hello-world-ee87ccfc-5d0a-4ad0-b9ee-4c142f40e00b main" | ||
| content: | | ||
| # Hello World! | ||
|
|
||
| From my-org/ | ||
| file: hello.md | ||
| overwriteOnCreate: true | ||
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| lifecycle: {} # optional / placeholder | ||
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ## Examples | ||
|
|
||
| See [_examples/basic](https://github.com/prefapp/tfm/tree/main/modules/gh-files-set/_examples/basic) | ||
|
|
||
| ## Resources | ||
|
|
||
| - **github_repository_file** | ||
| https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file | ||
|
|
||
| ## Support | ||
|
|
||
| Open issues in https://github.com/prefapp/tfm/issues |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # **GitHub Files Set Terraform Module** | ||
|
|
||
| ## Overview | ||
|
|
||
| This module creates or updates one or more files in GitHub repositories using the `github_repository_file` resource. | ||
| It is designed to be used in automated repository bootstrapping / golden-path workflows. | ||
|
|
||
| It accepts a list of files in a single `config` object — ideal for YAML/JSON input from external tools. | ||
|
|
||
| ## Key Features | ||
|
|
||
| - Multiple files in one module call | ||
| - Per-file branch, commit message, overwrite control | ||
frmadem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Native GitHub provider integration | ||
| - Input validation on required fields | ||
| - Clean outputs for downstream usage | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| ```hcl | ||
| module "files" { | ||
| source = "git::https://github.com/prefapp/tfm.git//modules/gh-files-set" | ||
|
|
||
| config = yamldecode(file("${path.module}/files.yaml")) | ||
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # or jsondecode(...) if using JSON | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # ───────────────────────────────────────────────────────────── | ||
| # Fetch repository info (validates existence + gives canonical name) | ||
| # ───────────────────────────────────────────────────────────── | ||
| data "github_repository" "this" { | ||
| full_name = var.config.repository | ||
| } | ||
|
|
||
| # Normal files — Terraform fully enforces content | ||
| resource "github_repository_file" "managed" { | ||
| for_each = { | ||
| for f in var.config.files : "${f.repository}/${f.file}/${f.branch}" => f | ||
| if !f.userManaged | ||
| } | ||
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| repository = data.github_repository.this.name | ||
| branch = each.value.branch | ||
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| file = each.value.file | ||
| content = each.value.content | ||
| commit_message = each.value.commitMessage | ||
| overwrite_on_create = each.value.overwriteOnCreate | ||
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| # User-managed files — provision once + ignore content drift | ||
| resource "github_repository_file" "user_managed" { | ||
| for_each = { | ||
| for f in var.config.files : "${f.repository}/${f.file}/${f.branch}" => f | ||
| if f.userManaged | ||
| } | ||
|
Comment on lines
+23
to
+28
|
||
|
|
||
| repository = data.github_repository.this.name | ||
| branch = each.value.branch | ||
| file = each.value.file | ||
| content = each.value.content | ||
| commit_message = each.value.commitMessage | ||
| overwrite_on_create = each.value.overwriteOnCreate | ||
|
|
||
| lifecycle { | ||
| ignore_changes = [content] | ||
frmadem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
Comment on lines
+23
to
+39
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| output "user_managed_files" { | ||
| description = "Files marked as userManaged (will survive destroy)" | ||
frmadem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
frmadem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| value = [for f in var.config.files : "${f.repository}/${f.file}" if f.userManaged] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| variable "config" { | ||
| description = "GitHub files configuration — userManaged files are provisioned once and survive destroy" | ||
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type = object({ | ||
| files = list(object({ | ||
| branch = string | ||
| commitMessage = string | ||
| content = string | ||
| file = string | ||
| repository = string | ||
| overwriteOnCreate = optional(bool, true) | ||
| userManaged = optional(bool, false) | ||
| })) | ||
|
|
||
| repository = string | ||
| }) | ||
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| validation { | ||
| condition = length(var.config.files) > 0 | ||
| error_message = "At least one file must be defined in config.files" | ||
| } | ||
|
|
||
| validation { | ||
| condition = can(regex("^[a-zA-Z0-9_-]+/[a-zA-Z0-9_.-]+$", var.config.repository)) | ||
| error_message = "config.repository must be in 'owner/repo' format." | ||
| } | ||
|
|
||
| validation { | ||
| condition = alltrue([ | ||
| for f in var.config.files : | ||
| length(trimspace(f.branch)) > 0 && | ||
| length(trimspace(f.commitMessage)) > 0 && | ||
| length(trimspace(f.file)) > 0 && | ||
| length(trimspace(f.repository)) > 0 | ||
| ]) | ||
| error_message = "Every file must have non-empty branch, commitMessage, file path, and repository." | ||
frmadem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
frmadem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| terraform { | ||
| required_providers { | ||
| github = { | ||
| source = "integrations/github" | ||
| version = "~> 6.0" | ||
| } | ||
| } | ||
| } | ||
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
frmadem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.