Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

fix: add resource group name hash to resource names #310

Merged
merged 10 commits into from
Sep 6, 2019
Merged

Conversation

PIC123
Copy link
Contributor

@PIC123 PIC123 commented Sep 5, 2019

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

Copy link
Contributor

@tbarlow12 tbarlow12 left a 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 👍

@@ -26,6 +26,10 @@ export class AzureNamingService {
this.createShortStageName(stage),
].join("-");

if(includeHash && config.provider.resourceGroup) {
Copy link
Contributor

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

Copy link
Contributor

@wbreza wbreza left a 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.

@@ -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) {
Copy link
Contributor

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

Copy link
Contributor

@wbreza wbreza left a 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.

@@ -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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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

@wbreza
Copy link
Contributor

wbreza commented Sep 6, 2019

Resolves #299

@PIC123 PIC123 requested a review from tbarlow12 September 6, 2019 21:12
Copy link
Contributor

@tbarlow12 tbarlow12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PIC123 PIC123 merged commit 5ba9508 into dev Sep 6, 2019
tbarlow12 pushed a commit that referenced this pull request Sep 13, 2019
* 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
@tbarlow12 tbarlow12 deleted the phcherne/naming branch September 16, 2019 16:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants