Skip to content

Commit 3f17463

Browse files
authored
Update web app (#12)
* Update `web-app` version * Update `web-app` version * Update `web-app` version * Update `web-app` version. Add `github_webhooks_token` * Pin `aws` provider * Pin `terraform` version * Update variables.tf * Update README
1 parent c772646 commit 3f17463

File tree

5 files changed

+78
-25
lines changed

5 files changed

+78
-25
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ What this module does not provision:
9090

9191
### GitHub Repo Scopes
9292

93-
This module accepts two GitHub tokens:
93+
This module accepts two GitHub OAuth tokens:
9494

9595
1. `github_oauth_token` with permissions to pull private repos. Used by CodePipeline to clone repos before the build, and by the atlantis server to clone repos and comment on Pull Requests.
9696

@@ -104,7 +104,6 @@ This module accepts two GitHub tokens:
104104

105105
2. `github_webhooks_token` with permissions to create GitHub webhooks.
106106
Only used by [Terraform GitHub Provider](https://www.terraform.io/docs/providers/github/index.html) when provisioning the module.
107-
It must be provided either in the `github_webhooks_token` variable, or it can also be sourced from the `GITHUB_TOKEN` environment variable.
108107

109108
The token needs the following OAuth scopes:
110109

@@ -127,6 +126,15 @@ We suggest the following steps when creating the tokens and provisioning the mod
127126

128127
**IMPORTANT:** Do not commit the tokens to source control (_e.g._ via `terraform.tvfars`).
129128

129+
**NOTE:** If the two tokens are not provided (left empty), they will be looked up from SSM Parameter Store.
130+
You can write `atlantis atlantis_gh` and `github_webhooks_token` to SSM Parameter Store before provisioning the module.
131+
For example, by using [chamber](https://github.com/segmentio/chamber):
132+
133+
```sh
134+
chamber write atlantis atlantis_gh_token "....."
135+
chamber write atlantis github_webhooks_token "....."
136+
```
137+
130138
## Usage
131139

132140

@@ -260,9 +268,10 @@ Available targets:
260268
| ecs_cluster_arn | ARN of the ECS cluster to deploy Atlantis | string | - | yes |
261269
| ecs_cluster_name | Name of the ECS cluster to deploy Atlantis | string | - | yes |
262270
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | string | `false` | no |
263-
| github_oauth_token | GitHub Oauth token. If not provided the token is looked up from SSM. | string | `` | no |
264-
| github_oauth_token_ssm_name | SSM param name to lookup GitHub OAuth token if not provided | string | `` | no |
265-
| github_webhooks_token | GitHub OAuth Token with permissions to create webhooks. If not provided, can be sourced from the `GITHUB_TOKEN` environment variable | string | `` | no |
271+
| github_oauth_token | GitHub OAuth token. If not provided the token is looked up from SSM | string | `` | no |
272+
| github_oauth_token_ssm_name | SSM param name to lookup `github_oauth_token` if not provided | string | `` | no |
273+
| github_webhooks_token | GitHub OAuth Token with permissions to create webhooks. If not provided the token is looked up from SSM | string | `` | no |
274+
| github_webhooks_token_ssm_name | SSM param name to lookup `github_webhooks_token` if not provided | string | `` | no |
266275
| healthcheck_path | Healthcheck path | string | `/healthz` | no |
267276
| hostname | Atlantis URL | string | `` | no |
268277
| kms_key_id | KMS key ID used to encrypt SSM SecureString parameters | string | `` | no |

README.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ introduction: |-
111111
112112
### GitHub Repo Scopes
113113
114-
This module accepts two GitHub tokens:
114+
This module accepts two GitHub OAuth tokens:
115115
116116
1. `github_oauth_token` with permissions to pull private repos. Used by CodePipeline to clone repos before the build, and by the atlantis server to clone repos and comment on Pull Requests.
117117
@@ -125,7 +125,6 @@ introduction: |-
125125
126126
2. `github_webhooks_token` with permissions to create GitHub webhooks.
127127
Only used by [Terraform GitHub Provider](https://www.terraform.io/docs/providers/github/index.html) when provisioning the module.
128-
It must be provided either in the `github_webhooks_token` variable, or it can also be sourced from the `GITHUB_TOKEN` environment variable.
129128
130129
The token needs the following OAuth scopes:
131130
@@ -148,6 +147,15 @@ introduction: |-
148147
149148
**IMPORTANT:** Do not commit the tokens to source control (_e.g._ via `terraform.tvfars`).
150149
150+
**NOTE:** If the two tokens are not provided (left empty), they will be looked up from SSM Parameter Store.
151+
You can write `atlantis atlantis_gh` and `github_webhooks_token` to SSM Parameter Store before provisioning the module.
152+
For example, by using [chamber](https://github.com/segmentio/chamber):
153+
154+
```sh
155+
chamber write atlantis atlantis_gh_token "....."
156+
chamber write atlantis github_webhooks_token "....."
157+
```
158+
151159
# How to use this project
152160
usage: |-
153161

docs/terraform.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@
6060
| ecs_cluster_arn | ARN of the ECS cluster to deploy Atlantis | string | - | yes |
6161
| ecs_cluster_name | Name of the ECS cluster to deploy Atlantis | string | - | yes |
6262
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | string | `false` | no |
63-
| github_oauth_token | GitHub Oauth token. If not provided the token is looked up from SSM. | string | `` | no |
64-
| github_oauth_token_ssm_name | SSM param name to lookup GitHub OAuth token if not provided | string | `` | no |
65-
| github_webhooks_token | GitHub OAuth Token with permissions to create webhooks. If not provided, can be sourced from the `GITHUB_TOKEN` environment variable | string | `` | no |
63+
| github_oauth_token | GitHub OAuth token. If not provided the token is looked up from SSM | string | `` | no |
64+
| github_oauth_token_ssm_name | SSM param name to lookup `github_oauth_token` if not provided | string | `` | no |
65+
| github_webhooks_token | GitHub OAuth Token with permissions to create webhooks. If not provided the token is looked up from SSM | string | `` | no |
66+
| github_webhooks_token_ssm_name | SSM param name to lookup `github_webhooks_token` if not provided | string | `` | no |
6667
| healthcheck_path | Healthcheck path | string | `/healthz` | no |
6768
| hostname | Atlantis URL | string | `` | no |
6869
| kms_key_id | KMS key ID used to encrypt SSM SecureString parameters | string | `` | no |

main.tf

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
# Pin the `aws` provider
2+
# https://www.terraform.io/docs/configuration/providers.html
3+
# Any non-beta version >= 2.12.0 and < 2.13.0, e.g. 2.12.X
4+
provider "aws" {
5+
version = "~> 2.12.0"
6+
}
7+
18
# Terraform
29
#--------------------------------------------------------------
310
terraform {
4-
required_version = ">= 0.10.7"
11+
required_version = "~> 0.11.0"
512
}
613

714
# Data
@@ -11,6 +18,11 @@ data "aws_ssm_parameter" "atlantis_gh_token" {
1118
name = "${local.github_oauth_token_ssm_name}"
1219
}
1320

21+
data "aws_ssm_parameter" "github_webhooks_token" {
22+
count = "${local.enabled && length(var.github_webhooks_token) == 0 ? 1 : 0}"
23+
name = "${local.github_webhooks_token_ssm_name}"
24+
}
25+
1426
data "aws_kms_key" "chamber_kms_key" {
1527
count = "${local.enabled && length(var.kms_key_id) == 0 ? 1 : 0}"
1628
key_id = "${local.kms_key_id}"
@@ -19,16 +31,23 @@ data "aws_kms_key" "chamber_kms_key" {
1931
# Locals
2032
#--------------------------------------------------------------
2133
locals {
22-
enabled = "${var.enabled == "true" ? true : false}"
23-
atlantis_gh_webhook_secret = "${length(var.atlantis_gh_webhook_secret) > 0 ? var.atlantis_gh_webhook_secret : join("", random_string.atlantis_gh_webhook_secret.*.result)}"
24-
atlantis_webhook_url = "${format(var.atlantis_webhook_format, local.hostname)}"
25-
atlantis_url = "${format(var.atlantis_url_format, local.hostname)}"
26-
attributes = "${concat(list(var.short_name), var.attributes)}"
27-
default_hostname = "${join("", aws_route53_record.default.*.fqdn)}"
34+
enabled = "${var.enabled == "true" ? true : false}"
35+
atlantis_gh_webhook_secret = "${length(var.atlantis_gh_webhook_secret) > 0 ? var.atlantis_gh_webhook_secret : join("", random_string.atlantis_gh_webhook_secret.*.result)}"
36+
atlantis_webhook_url = "${format(var.atlantis_webhook_format, local.hostname)}"
37+
atlantis_url = "${format(var.atlantis_url_format, local.hostname)}"
38+
attributes = "${concat(list(var.short_name), var.attributes)}"
39+
default_hostname = "${join("", aws_route53_record.default.*.fqdn)}"
40+
hostname = "${length(var.hostname) > 0 ? var.hostname : local.default_hostname}"
41+
kms_key_id = "${length(var.kms_key_id) > 0 ? var.kms_key_id : format("alias/%s-%s-chamber", var.namespace, var.stage)}"
42+
}
43+
44+
# GitHub tokens
45+
locals {
2846
github_oauth_token = "${length(join("", data.aws_ssm_parameter.atlantis_gh_token.*.value)) > 0 ? join("", data.aws_ssm_parameter.atlantis_gh_token.*.value) : var.github_oauth_token}"
2947
github_oauth_token_ssm_name = "${length(var.github_oauth_token_ssm_name) > 0 ? var.github_oauth_token_ssm_name : format(var.chamber_format, var.chamber_service, "atlantis_gh_token")}"
30-
hostname = "${length(var.hostname) > 0 ? var.hostname : local.default_hostname}"
31-
kms_key_id = "${length(var.kms_key_id) > 0 ? var.kms_key_id : format("alias/%s-%s-chamber", var.namespace, var.stage)}"
48+
49+
github_webhooks_token = "${length(join("", data.aws_ssm_parameter.github_webhooks_token.*.value)) > 0 ? join("", data.aws_ssm_parameter.github_webhooks_token.*.value) : var.github_webhooks_token}"
50+
github_webhooks_token_ssm_name = "${length(var.github_webhooks_token_ssm_name) > 0 ? var.github_webhooks_token_ssm_name : format(var.chamber_format, var.chamber_service, "github_webhooks_token")}"
3251
}
3352

3453
# Modules
@@ -47,7 +66,7 @@ module "ssh_key_pair" {
4766

4867
module "webhooks" {
4968
source = "git::https://github.com/cloudposse/terraform-github-repository-webhooks.git?ref=tags/0.4.0"
50-
github_token = "${var.github_webhooks_token}"
69+
github_token = "${local.github_webhooks_token}"
5170
webhook_secret = "${local.atlantis_gh_webhook_secret}"
5271
webhook_url = "${local.atlantis_webhook_url}"
5372
enabled = "${local.enabled}"
@@ -57,7 +76,7 @@ module "webhooks" {
5776
}
5877

5978
module "web_app" {
60-
source = "git::https://github.com/cloudposse/terraform-aws-ecs-web-app.git?ref=tags/0.21.0"
79+
source = "git::https://github.com/cloudposse/terraform-aws-ecs-web-app.git?ref=tags/0.22.0"
6180
namespace = "${var.namespace}"
6281
stage = "${var.stage}"
6382
name = "${var.name}"
@@ -111,7 +130,7 @@ module "web_app" {
111130
alb_ingress_healthcheck_path = "${var.healthcheck_path}"
112131

113132
github_oauth_token = "${local.github_oauth_token}"
114-
github_webhooks_token = "${var.github_webhooks_token}"
133+
github_webhooks_token = "${local.github_webhooks_token}"
115134
repo_owner = "${var.repo_owner}"
116135
repo_name = "${var.repo_name}"
117136
branch = "${var.branch}"
@@ -282,6 +301,16 @@ resource "aws_ssm_parameter" "atlantis_gh_token" {
282301
value = "${local.github_oauth_token}"
283302
}
284303

304+
resource "aws_ssm_parameter" "github_webhooks_token" {
305+
count = "${local.enabled ? 1 : 0}"
306+
description = "GitHub OAuth token with permission to create webhooks"
307+
key_id = "${join("", data.aws_kms_key.chamber_kms_key.*.id)}"
308+
name = "${local.github_webhooks_token_ssm_name}"
309+
overwrite = "${var.overwrite_ssm_parameter}"
310+
type = "SecureString"
311+
value = "${local.github_webhooks_token}"
312+
}
313+
285314
resource "aws_security_group_rule" "egress_http" {
286315
count = "${local.enabled ? 1 : 0}"
287316
cidr_blocks = ["0.0.0.0/0"]

variables.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,25 @@ variable "default_backend_image" {
4040

4141
variable "github_oauth_token" {
4242
type = "string"
43-
description = "GitHub Oauth token. If not provided the token is looked up from SSM."
43+
description = "GitHub OAuth token. If not provided the token is looked up from SSM"
4444
default = ""
4545
}
4646

4747
variable "github_webhooks_token" {
4848
type = "string"
49-
description = "GitHub OAuth Token with permissions to create webhooks. If not provided, can be sourced from the `GITHUB_TOKEN` environment variable"
49+
description = "GitHub OAuth Token with permissions to create webhooks. If not provided the token is looked up from SSM"
5050
default = ""
5151
}
5252

5353
variable "github_oauth_token_ssm_name" {
5454
type = "string"
55-
description = "SSM param name to lookup GitHub OAuth token if not provided"
55+
description = "SSM param name to lookup `github_oauth_token` if not provided"
56+
default = ""
57+
}
58+
59+
variable "github_webhooks_token_ssm_name" {
60+
type = "string"
61+
description = "SSM param name to lookup `github_webhooks_token` if not provided"
5662
default = ""
5763
}
5864

0 commit comments

Comments
 (0)