generated from kedacore/github-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor RabbitMQ app registration to be reusable (generic App Regist…
…raion) Signed-off-by: Jakub Adamus <jakub.adamus@vivantis.cz>
- Loading branch information
Jakub Adamus
committed
Jun 15, 2023
1 parent
e8da2f7
commit 4fee06d
Showing
7 changed files
with
120 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
terraform { | ||
required_providers { | ||
azuread = { | ||
source = "hashicorp/azuread" | ||
} | ||
} | ||
} | ||
|
||
locals { | ||
application_name = "${var.unique_project_name}-${var.application_purpose}" | ||
application_identifier = "api://${local.application_name}" | ||
} | ||
|
||
resource "random_uuid" "app_roles" { | ||
for_each = var.app_roles | ||
} | ||
|
||
resource "random_uuid" "app_scope" {} | ||
|
||
resource "azuread_application" "oauth2_api" { | ||
|
||
display_name = "${local.application_name} OAuth2 API tokens app ${var.application_purpose}" | ||
|
||
api { | ||
mapped_claims_enabled = true | ||
requested_access_token_version = 2 | ||
|
||
oauth2_permission_scope { | ||
id = random_uuid.app_scope.id | ||
admin_consent_description = "Dummy text for dummy application" | ||
admin_consent_display_name = "Dummy text for dummy application" | ||
enabled = true | ||
type = "User" | ||
user_consent_description = "Dummy text for dummy application" | ||
user_consent_display_name = "Dummy text for dummy application" | ||
value = "access" | ||
} | ||
} | ||
|
||
identifier_uris = [local.application_identifier] | ||
|
||
dynamic "app_role" { | ||
for_each = var.app_roles | ||
content { | ||
id = random_uuid.app_roles[app_role.key].id | ||
allowed_member_types = ["User", "Application"] | ||
value = app_role.value | ||
display_name = app_role.key | ||
description = app_role.key | ||
enabled = true | ||
} | ||
} | ||
} | ||
|
||
resource "azuread_service_principal" "oauth2_api" { | ||
application_id = azuread_application.oauth2_api.application_id | ||
use_existing = true | ||
} | ||
|
||
locals { | ||
# assign each role to each identity requested | ||
roles_to_principals = flatten([ | ||
for role,_ in var.app_roles : [ | ||
for identity in var.access_identities : { | ||
role_uuid_key = random_uuid.app_roles[role].id | ||
principal_id = identity.principal_id | ||
} | ||
] | ||
]) | ||
} | ||
|
||
resource "azuread_app_role_assignment" "oauth2_api_access" { | ||
count = length(local.roles_to_principals) | ||
|
||
app_role_id = local.roles_to_principals[count.index].role_uuid_key | ||
principal_object_id = local.roles_to_principals[count.index].principal_id | ||
resource_object_id = azuread_service_principal.oauth2_api.object_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
output "application_id" { | ||
value = azuread_application.oauth2_api.application_id | ||
} | ||
|
||
output "application_scope_id" { | ||
value = random_uuid.app_scope.id | ||
} | ||
|
||
output "application_identifier_uri" { | ||
value = local.application_identifier | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
variable "unique_project_name" { | ||
type = string | ||
description = "Value to make unique every resource name generated" | ||
} | ||
|
||
variable "application_purpose" { | ||
type = string | ||
description = "Value to create app name / app identifier from" | ||
} | ||
|
||
variable "app_roles" { | ||
type = map(string) | ||
description = "Role names of application" | ||
} | ||
|
||
variable "access_identities" { | ||
type = list(any) | ||
description = "Identities with access to this application (all roles)" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.