https://github.com/tbobm/terraform-github-environments
Manage Github Repository Environments.
https://github.com/tbobm/terraform-github-environments
github github-provider iac terraform terraform-github-provider terraform-module
Last synced: 6 days ago
JSON representation
Manage Github Repository Environments.
- Host: GitHub
- URL: https://github.com/tbobm/terraform-github-environments
- Owner: tbobm
- Created: 2021-12-04T14:11:20.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-20T18:37:20.000Z (about 3 years ago)
- Last Synced: 2026-04-06T15:06:46.036Z (about 2 months ago)
- Topics: github, github-provider, iac, terraform, terraform-github-provider, terraform-module
- Language: HCL
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
Awesome Lists containing this project
README
# terraform-github-environments
[](https://github.com/semantic-release/terraform-github-environments)
[](https://github.com/tbobm/terraform-github-environments/actions?query=workflow%3Aterraform-github-environments)
Terraform module to create Github Environments for Github Actions.
## Usage
_Note: Github Actions Environments are available for Public Repositories and
Github Enterprise Cloud users. ([doc][gh-env-doc])_
[gh-env-doc]: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment
### Github Authentication
You will need to authenticate against Github using an OAuth Token or Personal Access Token.
See [Github Provider#Authentication][tf-gh-auth] for more informations.
This can be done by setting the `token` argument of the `github` provider or by exporting
your Token to the `GITHUB_TOKEN` environment variable.
_Provider configuration:_
```hcl
provider "github" {
token = var.token # or `GITHUB_TOKEN`
}
```
_Environment variable configuration:_
```bash
export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```
[tf-gh-auth]: https://registry.terraform.io/providers/integrations/github/latest/docs#authentication
### Creating the Environments
This module takes a `map` of objects for each Environement to configure.
```hcl
module "env" {
source = "../"
repository = "tbobm/terraform-github-secrets"
environments = {
"stable" = {}
"protected" = {
deployment_branch_policy = {
protected_branches = true
custom_branch_policies = false
}
}
}
}
```
Here we defined two environemnts:
- the `stable` environment
- the `protected` environment with protected branches enabled
## Doc generation
Code formatting and documentation for variables and outputs is generated using
[pre-commit-terraform
hooks](https://github.com/antonbabenko/pre-commit-terraform) which uses
[terraform-docs](https://github.com/segmentio/terraform-docs).
Follow [these
instructions](https://github.com/antonbabenko/pre-commit-terraform#how-to-install)
to install pre-commit locally.
And install `terraform-docs` with `go get github.com/segmentio/terraform-docs`
or `brew install terraform-docs`.
## Contributing
Report issues/questions/feature requests on in the
[issues](https://github.com/tbobm/terraform-github-environments/issues/new)
section.
Full contributing [guidelines are covered
here](https://github.com/tbobm/terraform-github-environments/blob/master/.github/CONTRIBUTING.md).
## Requirements
| Name | Version |
|------|---------|
| [github](#requirement\_github) | ~> 4.0 |
## Providers
| Name | Version |
|------|---------|
| [github](#provider\_github) | ~> 4.0 |
## Modules
No modules.
## Resources
| Name | Type |
|------|------|
| [github_repository_environment.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_environment) | resource |
| [github_repository.this](https://registry.terraform.io/providers/integrations/github/latest/docs/data-sources/repository) | data source |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [environments](#input\_environments) | A map of environment definitions | `map(any)` | n/a | yes |
| [repository](#input\_repository) | The full name of the repository in the form org/repo | `string` | n/a | yes |
## Outputs
| Name | Description |
|------|-------------|
| [environments](#output\_environments) | A map of the created environments |
| [repository](#output\_repository) | The target github repository informations |