-
Notifications
You must be signed in to change notification settings - Fork 0
feat(azure/postgresql): modernize module to pass scorecard #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tfelix
wants to merge
1
commit into
main
Choose a base branch
from
feature/postgresql-scorecard-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,24 +1,57 @@ | ||
| resource "azurerm_role_definition" "buildingblock_deploy" { | ||
| resource "azurerm_resource_group" "backplane" { | ||
| name = var.name | ||
| location = var.location | ||
| } | ||
|
|
||
| resource "azurerm_user_assigned_identity" "backplane" { | ||
| name = var.name | ||
| location = var.location | ||
| resource_group_name = azurerm_resource_group.backplane.name | ||
| } | ||
|
|
||
| resource "azurerm_federated_identity_credential" "backplane" { | ||
| for_each = { for i, s in var.workload_identity_federation.subjects : tostring(i) => s } | ||
|
|
||
| name = "subject-${each.key}" | ||
| resource_group_name = azurerm_resource_group.backplane.name | ||
| parent_id = azurerm_user_assigned_identity.backplane.id | ||
| audience = ["api://AzureADTokenExchange"] | ||
| issuer = var.workload_identity_federation.issuer | ||
| subject = each.value | ||
| } | ||
|
|
||
| resource "azurerm_role_definition" "backplane" { | ||
| name = "${var.name}-deploy" | ||
| description = "Enables deployment of the ${var.name} building block to subscriptions" | ||
| scope = var.scope | ||
| permissions { | ||
| actions = [ | ||
| "Microsoft.DBforPostgreSQL/servers/write", | ||
| "Microsoft.DBforPostgreSQL/servers/read", | ||
| "Microsoft.DBforPostgreSQL/servers/delete", | ||
| "Microsoft.DBforPostgreSQL/servers/firewallRules/read", | ||
| "Microsoft.DBforPostgreSQL/servers/firewallRules/write", | ||
| "Microsoft.DBforPostgreSQL/servers/databases/read", | ||
| "Microsoft.DBforPostgreSQL/servers/databases/write" | ||
| # resource provider registration — required on freshly created subscriptions | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. n: in particular this stuff here could be hallucinated or outdated. |
||
| "*/register/action", | ||
|
|
||
| # resource groups | ||
| "Microsoft.Resources/subscriptions/resourcegroups/read", | ||
| "Microsoft.Resources/subscriptions/resourcegroups/write", | ||
| "Microsoft.Resources/subscriptions/resourcegroups/delete", | ||
|
|
||
| # postgresql flexible servers | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/read", | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/write", | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/delete", | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/firewallRules/read", | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/firewallRules/write", | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/firewallRules/delete", | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/databases/read", | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/databases/write", | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/databases/delete", | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/configurations/read", | ||
| "Microsoft.DBforPostgreSQL/flexibleServers/configurations/write", | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "azurerm_role_assignment" "buildingblock_deploy" { | ||
| for_each = var.principal_ids | ||
|
|
||
| role_definition_id = azurerm_role_definition.buildingblock_deploy.role_definition_resource_id | ||
| principal_id = each.value | ||
| resource "azurerm_role_assignment" "backplane" { | ||
| scope = var.scope | ||
| role_definition_id = azurerm_role_definition.backplane.role_definition_resource_id | ||
| principal_id = azurerm_user_assigned_identity.backplane.principal_id | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,25 +1,23 @@ | ||
| output "identity" { | ||
| value = { | ||
| client_id = azurerm_user_assigned_identity.backplane.client_id | ||
| principal_id = azurerm_user_assigned_identity.backplane.principal_id | ||
| tenant_id = azurerm_user_assigned_identity.backplane.tenant_id | ||
| } | ||
| description = "The managed identity used as the automation principal for this building block." | ||
| } | ||
|
|
||
| output "role_definition_id" { | ||
| value = azurerm_role_definition.buildingblock_deploy.id | ||
| value = azurerm_role_definition.backplane.id | ||
| description = "The ID of the role definition that enables deployment of the building block to subscriptions." | ||
| } | ||
|
|
||
| output "role_definition_name" { | ||
| value = azurerm_role_definition.buildingblock_deploy.name | ||
| value = azurerm_role_definition.backplane.name | ||
| description = "The name of the role definition that enables deployment of the building block to subscriptions." | ||
| } | ||
|
|
||
| output "role_assignment_ids" { | ||
| value = [for id in azurerm_role_assignment.buildingblock_deploy : id.id] | ||
| description = "The IDs of the role assignments for the service principals." | ||
| } | ||
|
|
||
| output "role_assignment_principal_ids" { | ||
| value = [for id in azurerm_role_assignment.buildingblock_deploy : id.principal_id] | ||
| description = "The principal IDs of the service principals that have been assigned the role." | ||
| } | ||
|
|
||
| output "scope" { | ||
| value = var.scope | ||
| description = "The scope where the role definition and role assignments are applied." | ||
| description = "The scope where the role definition and role assignment are applied." | ||
| } | ||
|
|
This file contains hidden or 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 |
|---|---|---|
| @@ -1,17 +1,30 @@ | ||
| variable "name" { | ||
| type = string | ||
| nullable = false | ||
| default = "postgresql" | ||
| type = string | ||
| nullable = false | ||
| description = "Name for the building block identity and role definition." | ||
| validation { | ||
| condition = can(regex("^[-a-z0-9]+$", var.name)) | ||
| error_message = "Only alphanumeric lowercase characters and dashes are allowed" | ||
| } | ||
| } | ||
|
|
||
| variable "scope" { | ||
| type = string | ||
| nullable = false | ||
| description = "Scope where the building block should be deployable, typically the parent of all Landing Zones." | ||
| description = "Scope for role assignment (management group or subscription ID)." | ||
| } | ||
|
|
||
| variable "location" { | ||
| type = string | ||
| nullable = false | ||
| description = "Azure region for the UAMI resource." | ||
| } | ||
|
|
||
| variable "principal_ids" { | ||
| type = set(string) | ||
| variable "workload_identity_federation" { | ||
| type = object({ | ||
| issuer = string | ||
| subjects = list(string) | ||
| }) | ||
| nullable = false | ||
| description = "set of principal ids that will be granted permissions to deploy the building block" | ||
| description = "WIF issuer and subjects for federated authentication." | ||
| } |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s:
the module is already called
backplane. I've always wanted to have a rule "single resource type in model must be namedthis. We should add this to the scorecard.