96 lines
2.4 KiB
HCL
96 lines
2.4 KiB
HCL
terraform {
|
|
required_version = ">= 1.0"
|
|
|
|
required_providers {
|
|
authentik = {
|
|
source = "goauthentik/authentik"
|
|
version = "= 2026.8.0"
|
|
}
|
|
random = {
|
|
source = "hashicorp/random"
|
|
version = "~> 3.7"
|
|
}
|
|
}
|
|
}
|
|
|
|
provider "authentik" {
|
|
url = var.authentik_url
|
|
token = var.authentik_token
|
|
}
|
|
|
|
data "authentik_flow" "authorization" {
|
|
slug = "default-provider-authorization-implicit-consent"
|
|
}
|
|
|
|
data "authentik_flow" "invalidation" {
|
|
slug = "default-provider-invalidation-flow"
|
|
}
|
|
|
|
data "authentik_property_mapping_provider_scope" "gitea" {
|
|
managed_list = [
|
|
"goauthentik.io/providers/oauth2/scope-openid",
|
|
"goauthentik.io/providers/oauth2/scope-profile",
|
|
"goauthentik.io/providers/oauth2/scope-email",
|
|
]
|
|
}
|
|
|
|
resource "random_password" "gitea_client_secret" {
|
|
length = 48
|
|
special = false
|
|
}
|
|
|
|
resource "authentik_group" "gitea_users" {
|
|
name = "gitea-users"
|
|
}
|
|
|
|
resource "authentik_group" "gitea_admins" {
|
|
name = "gitea-admins"
|
|
}
|
|
|
|
resource "authentik_provider_oauth2" "gitea" {
|
|
name = "Gitea"
|
|
client_id = var.gitea_client_id
|
|
client_secret = random_password.gitea_client_secret.result
|
|
grant_types = ["authorization_code"]
|
|
authorization_flow = data.authentik_flow.authorization.id
|
|
invalidation_flow = data.authentik_flow.invalidation.id
|
|
property_mappings = data.authentik_property_mapping_provider_scope.gitea.ids
|
|
|
|
allowed_redirect_uris = [{
|
|
matching_mode = "strict"
|
|
url = "${trimsuffix(var.gitea_public_url, "/")}/user/oauth2/${var.gitea_auth_source_name}/callback"
|
|
}]
|
|
}
|
|
|
|
resource "authentik_application" "gitea" {
|
|
name = "Gitea"
|
|
slug = "gitea"
|
|
meta_launch_url = trimsuffix(var.gitea_public_url, "/")
|
|
protocol_provider = authentik_provider_oauth2.gitea.id
|
|
}
|
|
|
|
resource "authentik_policy_binding" "gitea_users" {
|
|
target = authentik_application.gitea.uuid
|
|
group = authentik_group.gitea_users.id
|
|
order = 0
|
|
}
|
|
|
|
resource "authentik_policy_binding" "gitea_admins" {
|
|
target = authentik_application.gitea.uuid
|
|
group = authentik_group.gitea_admins.id
|
|
order = 1
|
|
}
|
|
|
|
output "gitea_client_id" {
|
|
value = var.gitea_client_id
|
|
}
|
|
|
|
output "gitea_client_secret" {
|
|
value = random_password.gitea_client_secret.result
|
|
sensitive = true
|
|
}
|
|
|
|
output "gitea_discovery_url" {
|
|
value = "${trimsuffix(var.authentik_url, "/")}/application/o/gitea/.well-known/openid-configuration"
|
|
}
|