Skip to content

Commit 8db0990

Browse files
authored
feat: Added OIDC connections for internal apps. (#9)
1 parent f8ababe commit 8db0990

5 files changed

Lines changed: 36 additions & 4 deletions

File tree

tofu/config/development/infra/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module "app" {
5959
services = each.value.services
6060
database_engine = try(each.value.database.type, null)
6161
database_version = try(each.value.database.version, null)
62+
internal = try(each.value.internal, true)
6263
domain = try(
6364
each.value.domain,
6465
try(each.value.internal, true) ? module.hosted_zones.route53_zone_name.internal : module.hosted_zones.route53_zone_name.external

tofu/modules/app/database.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "database" {
2-
source = "../database"
2+
source = "../database"
33
for_each = var.database_engine != null ? toset(["this"]) : toset([])
44

55
project = var.project
@@ -26,8 +26,8 @@ resource "aws_vpc_security_group_ingress_rule" "database" {
2626

2727
locals {
2828
database_environment_variables = {
29-
DATABASE_HOST = try(module.database["this"].host, null)
30-
DATABASE_PORT = try(module.database["this"].port, null)
29+
DATABASE_HOST = try(module.database["this"].host, null)
30+
DATABASE_PORT = try(module.database["this"].port, null)
3131
}
3232
database_environment_secrets = {
3333
DATABASE_USERNAME = length(module.database) > 0 ? "${module.database["this"].secret_arn}:username" : null

tofu/modules/app/local.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ locals {
99
data.aws_cloudwatch_log_groups.ecs_insights.log_group_names,
1010
data.aws_cloudwatch_log_groups.rds.log_group_names
1111
)
12+
oidc_settings = !var.internal ? null : {
13+
client_secret_arn = module.secrets.secrets["oidc"].secret_arn
14+
authorization_endpoint = "https://codeforamerica.okta.com/oauth2/v1/authorize"
15+
issuer = "https://codeforamerica.okta.com"
16+
token_endpoint = "https://codeforamerica.okta.com/oauth2/v1/token"
17+
user_info_endpoint = "https://codeforamerica.okta.com/oauth2/v1/userinfo"
18+
}
1219
production = var.environment == "production"
1320
project_short = var.project_short != null ? var.project_short : var.project
1421
tags = {

tofu/modules/app/main.tf

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@ module "secrets" {
33

44
project = var.project
55
environment = var.environment
6+
7+
secrets = var.internal ? {
8+
"oidc" = {
9+
description = "OIDC secrets for ${var.project} - ${var.environment}"
10+
tags = local.tags
11+
# We need to set something here so that we can use the secret in the
12+
# OIDC settings for the service module.
13+
start_value = jsonencode({
14+
"client_id" = "abc",
15+
"client_secret" = "123",
16+
})
17+
}
18+
} : {}
619
}
720

821
module "service" {
9-
source = "github.com/codeforamerica/tofu-modules-aws-fargate-service?ref=1.3.0"
22+
source = "github.com/codeforamerica/tofu-modules-aws-fargate-service?ref=1.4.0"
1023
for_each = var.services
24+
depends_on = [
25+
module.secrets
26+
]
1127

1228
project = var.project
1329
project_short = local.project_short
@@ -20,6 +36,8 @@ module "service" {
2036

2137
domain = var.domain
2238
subdomain = "${try(each.value.subdomain, "www")}${local.domain_prefix}"
39+
force_delete = !local.production
40+
oidc_settings = local.oidc_settings
2341

2442
vpc_id = var.vpc_id
2543
private_subnets = var.private_subnets

tofu/modules/app/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ variable "environment" {
2020
type = string
2121
}
2222

23+
variable "internal" {
24+
description = "Whether this application is internal, meaning it should only be accessible to staff via an OIDC connection."
25+
type = bool
26+
default = true
27+
}
28+
2329
variable "logging_key_arn" {
2430
description = "The ARN of the KMS key used for logging."
2531
type = string

0 commit comments

Comments
 (0)