-
Notifications
You must be signed in to change notification settings - Fork 161
fix: add resource group name hash to resource names #310
Conversation
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.
Let's get some tests in here and update that condition for adding the hash. See comment 👍
src/services/namingService.ts
Outdated
@@ -26,6 +26,10 @@ export class AzureNamingService { | |||
this.createShortStageName(stage), | |||
].join("-"); | |||
|
|||
if(includeHash && config.provider.resourceGroup) { |
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.
I think if config.provider.resourceGroup
is not defined, there are bigger problems here. It would probably be good to throw an error as opposed to just skipping the addition of the hash
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.
Looks good overall - some comments i'd like to see addressed.
src/services/namingService.ts
Outdated
@@ -14,7 +14,7 @@ export class AzureNamingService { | |||
* @param resourceConfig The serverless resource configuration | |||
* @param suffix Optional suffix to append on the end of the generated name | |||
*/ | |||
public static getResourceName(config: ServerlessAzureConfig, resourceConfig?: ResourceConfig, suffix?: string) { | |||
public static getResourceName(config: ServerlessAzureConfig, resourceConfig?: ResourceConfig, suffix?: string, includeHash: boolean = true) { |
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.
These flags and extra params are getting out of hand. Let's convert this into a typed options
object
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.
Let's add maxLength
into the options, otherwise looks good.
src/services/namingService.ts
Outdated
@@ -46,11 +61,11 @@ export class AzureNamingService { | |||
* @param forbidden Regex for characters to remove from name. Defaults to non-alpha-numerics | |||
* @param replaceWith String to replace forbidden characters. Defaults to empty string | |||
*/ | |||
public static getSafeResourceName(config: ServerlessAzureConfig, maxLength: number, resourceConfig?: ResourceConfig, suffix: string = "", includeHash = false) { | |||
public static getSafeResourceName(options: AzureNamingServiceOptions, maxLength: number) { |
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.
Any reason maxLength
isn't in the options?
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.
Only since the regular get resource name func didn't need it, but it makes more sense to add
Resolves #299 |
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.
LGTM
* Add hashed resource name to resource name * Fix tests * Fix resource group name test issues * Add test * Add naming service test * test: APIM resource test (#311) * Add test to validate resource naming * Add service options and refactor * Address pr feedback
fix: add resource group name hash to resource names
Azure has naming requirements for resources, and for some, requires the names to be unique across azure. Currently on deployments, the plugin doesn't add a more unique hash to the name, so it is possible collisions can occur. By adding the resource group name hash to the resource name, we can avoid this.
AB#1002