mspnp / AzureNamingTool

The Azure Naming Tool is a .NET 8 Blazor application, with a RESTful API. The UI consists of several pages to allow the configuration and generation of Azure Resource names. The API provides a programmatic interface for the functionality.
https://aka.ms/azurenamingtool
MIT License
308 stars 604 forks source link

Creating multiple resources using the API #27

Closed blaqvikin closed 9 months ago

blaqvikin commented 9 months ago

Describe the bug { "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1", "title": "One or more validation errors occurred.", "status": 400, "traceId": "00-26b70131132fac2aeb0061ff19e00c27-461a02b87ac1001c-00", "errors": { "$": [ "'c' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0." ], "request": [ "The request field is required." ] } }

To Reproduce Steps to reproduce the behavior: Create a request in this form: curl -X 'POST' \ 'https://aznamingtool-sbsa.azurewebsites.net/api/ResourceNamingRequests/RequestName' \ -H 'accept: /' \ -H 'APIKey: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' \ -H 'Content-Type: application/json' \ -d '[ { "ResourceType":"nw", "customComponents":{ "ResourceEnvironments":"nonprod", "BusinessUnit":"marketing", "ResourceRegions":"san" } }, { "customComponents":{ "ResourceType":"kv", "ResourceEnvironments":"nonprod", "BusinessSegment":"marketing", "ResourceRegions":"san", "ResourceIdentifier":"infra" } }, { "ResourceType":"rtt", "customComponents":{ "ResourceLocations":"san", "BusinessSegment":"marketing", "ResourceEnvironments":"nonprod", "ResourceIdentifier":"default" } }, { "ResourceType":"as", "customComponents":{ "ResourceEnvironments":"nonprod", "BusinessSegment":"marketing", "ResourceRegions":"san" } }, { "ResourceType":"vnet", "customComponents":{ "ResourceEnvironments":"nonprod", "BusinessSegment":"marketing", "ResourceRegions":"san" } }, { "ResourceType":"rt", "customComponents":{ "ResourceEnvironments":"nonprod", "BusinessUnit":"marketing", "ResourceRegions":"san", "ResourceIdentifier":"default" } }, { "ResourceType":"subn", "customComponents":{ "ResourceEnvironments":"nonprod", "BusinessUnit":"marketing", "ResourceIdentifier":"db" } }, { "ResourceType":"nsg", "customComponents":{ "ResourceEnvironments":"nonprod", "BusinessUnit":"marketing", "ResourceRegions":"san", "ResourceTypeSubset":"subn", "ResourceIdentifier":"db" } } ]'

Expected behavior Multiple names to be create for an example: nsg-san-marketing-nonprod-subn-db

Screenshots If applicable, add screenshots to help explain your problem.

Installation Method A description of the installation environment for the Azure Naming Tool.

Additional context I am trying to create multiple resources using this tool, I have managed to create one but I am wondering if I can have a single PS script that can generate all names.

The script below does what I want perfectly.

Azure Naming Tool API URL

$apiUrl = "https://aznamingtool-sbsa.azurewebsites.net/api/ResourceNamingRequests/RequestName"

$keyVaultName = "kv-san-nonprod-poc" $secretName = "APIKey"

Retrieve the API key from Key Vault

$apiKey = (Get-AzKeyVaultSecret -VaultName $keyVaultName -Name $secretName).SecretValueText

Request Body

$requestBody = @{ ResourceType = "nsg" customComponents = { ResourceRegions = "san" BusinessUnit = "marketing" ResourceEnvironments = "nonprod" ResourceTypeSubset = "subn" ResourceIdentifier = "db" } }

Convert the request body to JSON

$jsonBody = $requestBody | ConvertTo-Json

Make the API request with the API key in the header

$headers = @{ "APIKey" = $apiKey "Content-Type" = "application/json" }

$NSGresponse = Invoke-RestMethod -Uri $apiUrl -Headers $headers -Method Post -Body $jsonBody

Output the response from the API

$NSGresponse

Extract the NSG name from the API response

$NSGname = $NSGresponse.name # Replace 'name' with the actual JSON key for the NSG name

Output the NSG name

Write-Host "The NSG name is: $NSGname"

BryanSoltis commented 9 months ago

Hi @blaqvikin,

Thank you for your feedback. The current API only supports a single resource name creation action. We will add the ability to create multiple resource names in a single request to the backlog.

blaqvikin commented 9 months ago

Ok, now I know, I was banging my head on this one, thanks @BryanSoltis , I will keep an eye on the product for new updates.