Skip to content

Commit aa67c1d

Browse files
Felix Ziegerfelixzieger
authored andcommitted
feat: include sso in standard setup
1 parent c45f111 commit aa67c1d

File tree

6 files changed

+56
-17
lines changed

6 files changed

+56
-17
lines changed

main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ module "metering_service_principal" {
4949
assignment_scope = data.azuread_client_config.current.tenant_id
5050
}
5151

52+
module "sso_service_principal" {
53+
count = var.sso_enabled ? 1 : 0
54+
source = "./modules/meshcloud-sso/"
55+
56+
service_principal_name = var.metering_service_principal_name
57+
}
58+
5259
# facilitate migration from v0.1.0 of the module
5360
moved {
5461
from = module.replicator_spp

modules/meshcloud-sso/module.tf

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,32 @@ terraform {
1111
}
1212
}
1313
}
14+
//---------------------------------------------------------------------------
15+
// Queries Entra ID for information about well-known application IDs.
16+
// Retrieve details about the service principal
17+
//---------------------------------------------------------------------------
1418

1519
data "azuread_application_published_app_ids" "well_known" {}
1620

1721
data "azuread_service_principal" "msgraph" {
1822
client_id = data.azuread_application_published_app_ids.well_known.result.MicrosoftGraph
1923
}
2024

25+
//---------------------------------------------------------------------------
26+
// Create New application in Microsoft Entra ID
27+
//---------------------------------------------------------------------------
28+
data "azuread_application_template" "enterprise_app" {
29+
# will create the application based on this template ID to have features like Provisioning
30+
# available in the enterprise application
31+
template_id = "8adf8e6e-67b2-4cf2-a259-e3dc5476c621"
32+
}
33+
2134
resource "azuread_application" "meshcloud_sso" {
22-
display_name = "sso.${var.service_principal_name_suffix}"
35+
display_name = var.service_principal_name
36+
template_id = data.azuread_application_template.enterprise_app.template_id
37+
feature_tags {
38+
enterprise = true
39+
}
2340

2441
required_resource_access {
2542
resource_app_id = data.azuread_application_published_app_ids.well_known.result.MicrosoftGraph
@@ -29,18 +46,16 @@ resource "azuread_application" "meshcloud_sso" {
2946
type = "Scope"
3047
}
3148
}
32-
3349
web {
3450
redirect_uris = [var.meshstack_redirect_uri]
3551
}
52+
}
3653

37-
# As far as we know it is not possible to automate the "Grant admin consent button" for app registrations
38-
# You have to grant admin consent manually
39-
lifecycle {
40-
ignore_changes = [
41-
app_role
42-
]
43-
}
54+
resource "azuread_app_role_assignment" "meshcloud_sso_user_read" {
55+
app_role_id = data.azuread_service_principal.msgraph.app_role_ids["User.Read"]
56+
principal_object_id = azuread_application.meshcloud_sso.object_id
57+
resource_object_id = data.azuread_service_principal.msgraph.object_id
58+
depends_on = [azuread_application.meshcloud_sso]
4459
}
4560

4661
resource "azuread_application_password" "meshcloud_sso" {

modules/meshcloud-sso/outputs.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
output "app_registration" {
2-
description = "Application registration application id and object id"
1+
output "credentials" {
2+
description = "Service Principal application id and object id"
33
value = {
4-
object_id = azuread_application.meshcloud_sso.object_id
5-
app_id = azuread_application.meshcloud_sso.client_id
4+
Enterprise_Application_Object_ID = azuread_application.meshcloud_sso.object_id
5+
Application_Client_ID = azuread_application.meshcloud_sso.client_id
66
}
77
}
88

9-
output "app_registration_client_secret" {
9+
output "application_client_secret" {
1010
description = "Password for the application registration."
1111
value = azuread_application_password.meshcloud_sso.value
1212
sensitive = true

modules/meshcloud-sso/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
variable "service_principal_name_suffix" {
1+
variable "service_principal_name" {
22
type = string
3-
description = "Service principal name suffix."
3+
description = "Service principal name."
44
}
55

66
variable "meshstack_redirect_uri" {
77
type = string
8-
description = "Redirect URI that will be provided by meshcloud. It is individual per meshStack."
8+
description = "Redirect URI that was provided by meshcloud. It is individual per meshStack."
99
}

outputs.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ output "metering_service_principal_password" {
2121
sensitive = true
2222
}
2323

24+
output "sso_service_principal" {
25+
description = "SSO Service Principal."
26+
value = length(module.sso_service_principal) > 0 ? module.sso_service_principal[0].credentials : null
27+
}
28+
29+
output "sso_service_principal_password" {
30+
description = "Password for SSO Service Principal."
31+
value = length(module.sso_service_principal) > 0 ? module.sso_service_principal[0].application_client_secret : null
32+
sensitive = true
33+
}
34+
2435
output "azure_ad_tenant_id" {
2536
description = "The Azure AD tenant id."
2637
value = data.azuread_client_config.current.tenant_id

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ variable "replicator_assignment_scopes" {
1515
description = "Names or UUIDs of the Management Groups which replicator should manage."
1616
}
1717

18+
variable "sso_enabled" {
19+
type = bool
20+
default = true
21+
description = "Whether to create SSO Service Principal or not."
22+
}
23+
1824
# ---------------------------------------------------------------------------------------------------------------------
1925
# OPTIONAL PARAMETERS
2026
# These parameters have reasonable defaults.

0 commit comments

Comments
 (0)