Skip to content

[BICEP] Add support for custom resource naming in FinOps Toolkit #1635

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

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/templates/finops-hub/modules/hub-app.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ param features HubAppFeature[] = []
@description('Optional. Custom string with additional metadata to log. Must an alphanumeric string without spaces or special characters except for underscores and dashes. Namespace + appName + telemetryString must be 50 characters or less - additional characters will be trimmed.')
param telemetryString string = ''

@description('Optional. Custom name for the Storage Account. If not provided, a name will be generated based on the hub name.')
param storageAccountName string = ''

@description('Optional. Custom name for the Data Factory. If not provided, a name will be generated based on the hub name.')
param dataFactoryName string = ''

@description('Optional. Custom name for the Key Vault. If not provided, a name will be generated based on the hub name.')
param keyVaultName string = ''

//------------------------------------------------------------------------------
// Temporary parameters that should be removed in the future
//------------------------------------------------------------------------------
Expand All @@ -51,7 +60,17 @@ param coreConfig HubCoreConfig
// Variables
//==============================================================================

var appConfig = newAppConfig(coreConfig, publisher, namespace, appName, displayName, appVersion)
var appConfig = newAppConfig(
coreConfig,
publisher,
namespace,
appName,
displayName,
appVersion,
storageAccountName,
dataFactoryName,
keyVaultName
)

// Features
var usesDataFactory = contains(features, 'DataFactory')
Expand Down
17 changes: 13 additions & 4 deletions src/templates/finops-hub/modules/hub-types.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ func newAppInternalConfig(
appNamespace string,
displayName string,
version string,
customStorageName string,
customDataFactoryName string,
customKeyVaultName string
) HubAppConfig => {
...coreConfig
publisher: {
Expand All @@ -359,13 +362,13 @@ func newAppInternalConfig(
tags: union(coreConfig.hub.tags, publisherTags)

// Globally unique Data Factory name: 3-63 chars; letters, numbers, non-repeating dashes
dataFactory: replace('${take('${replace(coreConfig.hub.name, '_', '-')}-engine', 63 - length(publisherSuffix))}${publisherSuffix}', '--', '-')
dataFactory: !empty(customDataFactoryName) ? customDataFactoryName : replace('${take('${replace(coreConfig.hub.name, '_', '-')}-engine', 63 - length(publisherSuffix))}${publisherSuffix}', '--', '-')

// Globally unique KeyVault name: 3-24 chars; letters, numbers, dashes
keyVault: replace('${take('${replace(coreConfig.hub.name, '_', '-')}-vault', 24 - length(publisherSuffix))}${publisherSuffix}', '--', '-')
keyVault: !empty(customKeyVaultName) ? customKeyVaultName : replace('${take('${replace(coreConfig.hub.name, '_', '-')}-vault', 24 - length(publisherSuffix))}${publisherSuffix}', '--', '-')

// Globally unique storage account name: 3-24 chars; lowercase letters/numbers only
storage: '${take(coreConfig.hub.safeName, 24 - length(publisherSuffix))}${publisherSuffix}'
storage: !empty(customStorageName) ? customStorageName : '${take(coreConfig.hub.safeName, 24 - length(publisherSuffix))}${publisherSuffix}'
}
app: {
// id: '${hubResourceId}/publishers/${namespace}/apps/${appName}'
Expand All @@ -389,6 +392,9 @@ func newAppConfig(
appName string,
displayName string,
version string,
customStorageName string = '',
customDataFactoryName string = '',
customKeyVaultName string = ''
) HubAppConfig => newAppInternalConfig(
config,
publisher,
Expand All @@ -398,7 +404,10 @@ func newAppConfig(
appName,
'${namespace}.${appName}', // appNamespace
displayName,
version
version,
customStorageName,
customDataFactoryName,
customKeyVaultName
)

@export()
Expand Down
13 changes: 13 additions & 0 deletions src/templates/finops-hub/modules/hub.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ param location string = resourceGroup().location
// @description('Optional. Azure location to use for a temporary Event Grid namespace to register the Microsoft.EventGrid resource provider if the primary location is not supported. The namespace will be deleted and is not used for hub operation. Default: "" (same as location).')
// param eventGridLocation string = ''

@description('Optional. Custom name for the Storage Account. If not provided, a name will be generated based on the hub name.')
param storageAccountName string = ''

@description('Optional. Custom name for the Data Factory. If not provided, a name will be generated based on the hub name.')
param dataFactoryName string = ''

@description('Optional. Custom name for the Key Vault. If not provided, a name will be generated based on the hub name.')

param keyVaultName string = ''

@allowed([
'Premium_LRS'
'Premium_ZRS'
Expand Down Expand Up @@ -302,6 +312,9 @@ module appRegistration 'hub-app.bicep' = {
'Storage'
]
telemetryString: telemetryString
storageAccountName: storageAccountName
dataFactoryName: dataFactoryName
keyVaultName: keyVaultName

coreConfig: coreConfig
}
Expand Down