You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Terraform provider for managing files in GitHub repositories.
6
7
7
-
## Use-cases
8
+
## Use Cases
8
9
9
-
A few possible use-cases for `terraform-provider-githubfile` are:
10
+
A few possible usecases for `terraform-provider-githubfile` are:
10
11
11
12
* Adding a `LICENSE` file to a number of repositories.
12
13
* Making sure repositories across an organisation have consistent issue/pull request templates.
13
-
* Configuring a tool such as [`golangci-lint`](https://github.com/golangci/golangci-lint) or [`pre-commit`](https://pre-commit.com/) uniformly across a number of repositories
14
+
* Configuring a tool such as [`golangci-lint`](https://github.com/golangci/golangci-lint) or [`pre-commit`](https://pre-commit.com/) uniformly across a number of repositories.
14
15
15
16
## Installation
16
17
17
-
Download the relevant binary from [releases](https://github.com/form3tech-oss/terraform-provider-github-file/releases) and copy it to `$HOME/.terraform.d/plugins/`.
18
+
### Manual Installation
19
+
20
+
Download the relevant binary from [releases](https://github.com/form3tech-oss/terraform-provider-githubfile/releases) and copy it to `$HOME/.terraform.d/plugins/`.
18
21
19
22
## Configuration
20
23
21
24
The following provider block variables are available for configuration:
22
25
23
-
| Name | Description |
24
-
| ---- | ----------- |
25
-
|`commit_message_prefix`| An optional prefix to be added to all commits generated as a result of manipulating files. |
26
-
|`github_email`| The email address to use for commit messages.<br>If a GPG key is provided, this must match the one which the key corresponds to. |
27
-
|`github_token`| A GitHub authorisation token with `repo` permissions and having `admin` access to the target repositories. |
28
-
|`github_username`| The username to use for commit messages. |
29
-
|`gpg_passphrase`| The passphrase associated with the provided `gpg_secret_key` (see below). |
30
-
|`gpg_secret_key`| The GPG secret key to be use for commit signing.<br>If left empty, commits will not be signed. |
26
+
| Name | Required | Environment Variable | Description |
|`github_token`|**Yes**|`GITHUB_TOKEN`| A GitHub authorisation token with permissions to manage files in the target repositories. |
29
+
|`github_email`|**Yes**|`GITHUB_EMAIL`| The email address to use for commit messages. If a GPG key is provided, this must match the one which the key corresponds to. |
30
+
|`github_username`|**Yes**|`GITHUB_USERNAME`| The username to use for commit messages. |
31
+
|`commit_message_prefix`| No |`COMMIT_MESSAGE_PREFIX`| An optional prefix to be added to all commits generated as a result of manipulating files. |
32
+
|`gpg_secret_key`| No |`GPG_SECRET_KEY`| The GPG secret key to use for commit signing. Accepts raw or base64-encoded values. If left empty, commits will not be signed. |
33
+
|`gpg_passphrase`| No |`GPG_PASSPHRASE`| The passphrase associated with the provided `gpg_secret_key`. |
34
+
35
+
Each variable can be set either in the provider block or via the corresponding environment variable. Provider block values take precedence over environment variables.
36
+
37
+
### Example
31
38
32
-
Alternatively, these values can be read from environment variables.
39
+
```hcl
40
+
provider "githubfile" {
41
+
github_token = var.github_token
42
+
github_email = "ci-bot@example.com"
43
+
github_username = "ci-bot"
44
+
commit_message_prefix = "[terraform]"
45
+
}
46
+
```
33
47
34
48
## Resources
35
49
@@ -39,44 +53,78 @@ The `githubfile_file` resource represents a file in a given branch of a GitHub r
39
53
40
54
#### Attributes
41
55
42
-
| Name | Description |
43
-
| ---- | ----------- |
44
-
|`repository_owner`| The owner of the repository. |
45
-
|`repository_name`| The name of the repository. |
46
-
|`branch`| The branch in which to create/update the file<br>Leaving this empty will cause the file to be created/updated in the default branch. |
47
-
|`path`| The path to the file being created/updated. |
48
-
|`contents`| The contents of the file. |
56
+
| Name | Type | Required | Description |
57
+
| ---- | :--: | :------: | ----------- |
58
+
|`id`| String | Computed | The ID of the file resource (format: `owner/repo:branch:path`). |
59
+
|`repository_owner`| String |**Yes**| The owner of the repository. Changing this forces a new resource. |
60
+
|`repository_name`| String |**Yes**| The name of the repository. Changing this forces a new resource. |
61
+
|`branch`| String |**Yes**| The branch in which to create/update the file. Changing this forces a new resource. |
62
+
|`path`| String |**Yes**| The path to the file being created/updated. Changing this forces a new resource. |
63
+
|`contents`| String |**Yes**| The contents of the file. |
64
+
65
+
> **Note:** When a managed file is in an archived repository, the provider will gracefully skip deletion and simply remove the resource from state.
<!-- Please provide a description of the issue. -->
67
-
EOF
83
+
<!-- Please provide a description of the issue. -->
84
+
EOF
68
85
}
69
86
```
70
87
71
-
Creating the resource above will result in the `.github/ISSUE_TEMPLATE.md` file being created/updated on the default branch of the `form3tech-oss/terraform-provider-githubfile` repository with the following contents:
88
+
Creating the resource above will result in the `.github/ISSUE_TEMPLATE.md` file being created/updated on the `main` branch of the `form3tech-oss/terraform-provider-githubfile` repository.
89
+
90
+
#### Import
91
+
92
+
Existing files can be imported into Terraform state using the following ID format:
0 commit comments