Skip to content

Commit e0a2792

Browse files
feat: Move github-deployment-env to spa terraform-modules (#246)
1 parent 6eda14c commit e0a2792

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# GitHub Deployment Environment
2+
3+
Creates a GitHub deployment environment, and injects provided AWS credentials
4+
into that new environment's secrets. See GitHub documentation on
5+
[GitHub deployment environments](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment).
6+
7+
## How to use
8+
9+
```hcl
10+
module "deployment_env" {
11+
source = "[email protected]:pleo-io/spa-tools.git//terraform-module/modules/frontend-github-deployment-env?ref=terraform-module-v3.1.1"
12+
13+
repo_name = "my-repo"
14+
env_name = "staging"
15+
access_key_id = aws_iam_access_key.key.id
16+
access_key_secret = aws_iam_access_key.key.secret
17+
}
18+
```
19+
20+
<!-- BEGIN_TF_DOCS -->
21+
## Requirements
22+
23+
| Name | Version |
24+
|------|---------|
25+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
26+
| <a name="requirement_github"></a> [github](#requirement\_github) | ~> 5.0 |
27+
28+
## Providers
29+
30+
| Name | Version |
31+
|------|---------|
32+
| <a name="provider_github"></a> [github](#provider\_github) | ~> 5.0 |
33+
34+
## Modules
35+
36+
No modules.
37+
38+
## Resources
39+
40+
| Name | Type |
41+
|------|------|
42+
| [github_actions_environment_secret.access_key_id](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/actions_environment_secret) | resource |
43+
| [github_actions_environment_secret.secret_access_key](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/actions_environment_secret) | resource |
44+
| [github_repository_environment.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_environment) | resource |
45+
46+
## Inputs
47+
48+
| Name | Description | Type | Default | Required |
49+
|------|-------------|------|---------|:--------:|
50+
| <a name="input_access_key_id"></a> [access\_key\_id](#input\_access\_key\_id) | AWS access key ID | `string` | n/a | yes |
51+
| <a name="input_access_key_secret"></a> [access\_key\_secret](#input\_access\_key\_secret) | AWS secret access key | `string` | n/a | yes |
52+
| <a name="input_env_name"></a> [env\_name](#input\_env\_name) | Name of the environment | `string` | n/a | yes |
53+
| <a name="input_repo_name"></a> [repo\_name](#input\_repo\_name) | Name of the repository to create the environment | `string` | n/a | yes |
54+
| <a name="input_protected_branches"></a> [protected\_branches](#input\_protected\_branches) | Whether only branches with branch protection rules can deploy to this environment. | `bool` | `false` | no |
55+
| <a name="input_reviewer_teams"></a> [reviewer\_teams](#input\_reviewer\_teams) | List of up to 6 IDs of teams required to review a deployment to the environment | `list(string)` | `[]` | no |
56+
57+
## Outputs
58+
59+
No outputs.
60+
<!-- END_TF_DOCS -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
resource "github_repository_environment" "this" {
2+
repository = var.repo_name
3+
environment = var.env_name
4+
reviewers {
5+
teams = var.reviewer_teams
6+
}
7+
8+
dynamic "deployment_branch_policy" {
9+
for_each = var.protected_branches == false ? [] : [1]
10+
content {
11+
protected_branches = true
12+
custom_branch_policies = false
13+
}
14+
}
15+
}
16+
17+
resource "github_actions_environment_secret" "access_key_id" {
18+
repository = var.repo_name
19+
environment = github_repository_environment.this.environment
20+
secret_name = "AWS_ACCESS_KEY_ID"
21+
plaintext_value = var.access_key_id
22+
}
23+
24+
resource "github_actions_environment_secret" "secret_access_key" {
25+
repository = var.repo_name
26+
environment = github_repository_environment.this.environment
27+
secret_name = "AWS_SECRET_ACCESS_KEY"
28+
plaintext_value = var.access_key_secret
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
variable "repo_name" {
2+
description = "Name of the repository to create the environment"
3+
type = string
4+
}
5+
6+
variable "env_name" {
7+
description = "Name of the environment"
8+
type = string
9+
}
10+
11+
variable "access_key_id" {
12+
description = "AWS access key ID"
13+
type = string
14+
}
15+
16+
variable "access_key_secret" {
17+
description = "AWS secret access key"
18+
type = string
19+
}
20+
21+
variable "protected_branches" {
22+
description = "Whether only branches with branch protection rules can deploy to this environment."
23+
type = bool
24+
default = false
25+
}
26+
27+
variable "reviewer_teams" {
28+
description = "List of up to 6 IDs of teams required to review a deployment to the environment"
29+
type = list(string)
30+
default = []
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = ">= 4.0"
6+
}
7+
8+
github = {
9+
source = "integrations/github"
10+
version = "~> 5.0"
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)