Skip to content

Commit d89843a

Browse files
committed
Use AWS Secrets Manager instead of passing form Github secrets
1 parent c978235 commit d89843a

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

.github/workflows/deploy-lnt.llvm.org.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,3 @@ jobs:
3131

3232
- name: Apply Terraform changes
3333
run: terraform -chdir=deployment apply -auto-approve
34-
env:
35-
TF_VAR_lnt_db_password: ${{ secrets.LNT_DB_PASSWORD }}
36-
TF_VAR_lnt_auth_token: ${{ secrets.LNT_AUTH_TOKEN }}

deployment/main.tf

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,6 @@
22
# Terraform file for deploying lnt.llvm.org.
33
#
44

5-
variable "lnt_db_password" {
6-
type = string
7-
description = "The database password for the lnt.llvm.org database."
8-
sensitive = true
9-
}
10-
11-
variable "lnt_auth_token" {
12-
type = string
13-
description = "The authentication token to perform destructive operations on lnt.llvm.org."
14-
sensitive = true
15-
}
16-
17-
locals {
18-
# The Docker image to use for the webserver part of the LNT service
19-
lnt_image = "d9ffa5317a9a42a1d2fa337cba97ec51d931f391"
20-
21-
# The port on the EC2 instance used by the Docker webserver for communication
22-
lnt_host_port = "80"
23-
}
24-
255
terraform {
266
backend "s3" {
277
bucket = "lnt.llvm.org-test-bucket" # TODO: Adjust this for the real LLVM Foundation account
@@ -39,6 +19,36 @@ provider "aws" {
3919
region = "us-west-2"
4020
}
4121

22+
#
23+
# Setup secrets and other variables
24+
#
25+
# Note that the LNT database password and the LNT authentication token for destructive actions
26+
# must be stored in the AWS Secrets Manager under a secrets named `lnt.llvm.org-secrets`, and
27+
# with the `lnt-db-password` and `lnt-auth-token` keys respectively. This secrets must exist
28+
# in whatever AWS account is currently authenticated when running Terraform.
29+
#
30+
data "aws_secretsmanager_secret" "lnt_secrets" {
31+
name = "lnt.llvm.org-secrets"
32+
}
33+
34+
data "aws_secretsmanager_secret_version" "lnt_secrets_latest" {
35+
secret_id = data.aws_secretsmanager_secret.lnt_secrets.id
36+
}
37+
38+
locals {
39+
# The Docker image to use for the webserver part of the LNT service
40+
lnt_image = "d9ffa5317a9a42a1d2fa337cba97ec51d931f391"
41+
42+
# The port on the EC2 instance used by the Docker webserver for communication
43+
lnt_host_port = "80"
44+
45+
# The database password for the lnt.llvm.org database.
46+
lnt_db_password = jsondecode(data.aws_secretsmanager_secret_version.lnt_secrets_latest.secret_string)["lnt-db-password"]
47+
48+
# The authentication token to perform destructive operations on lnt.llvm.org.
49+
lnt_auth_token = jsondecode(data.aws_secretsmanager_secret_version.lnt_secrets_latest.secret_string)["lnt-auth-token"]
50+
}
51+
4252
#
4353
# Setup the EC2 instance
4454
#
@@ -79,8 +89,8 @@ data "cloudinit_config" "startup_scripts" {
7989
path = "/etc/lnt/compose.env"
8090
permissions = "0400" # read-only for owner
8191
content = templatefile("${path.module}/compose.env.tpl", {
82-
__db_password__ = var.lnt_db_password,
83-
__auth_token__ = var.lnt_auth_token,
92+
__db_password__ = local.lnt_db_password,
93+
__auth_token__ = local.lnt_auth_token,
8494
__lnt_image__ = local.lnt_image,
8595
__lnt_host_port__ = local.lnt_host_port,
8696
})

0 commit comments

Comments
 (0)