Azure / Azure-Spring-Apps

Azure Spring Cloud
MIT License
8 stars 5 forks source link

Enterprise Tier service-binding deployment fails with 'InvalidArgument Not supported resource type: Microsoft.AppPlatform' #31

Closed ezYakaEagle442 closed 1 year ago

ezYakaEagle442 commented 1 year ago

Describe the bug

see my Bicep code :

resource customersbinding 'Microsoft.AppPlatform/Spring/apps/bindings@2022-11-01-preview' = if (azureSpringAppsTier=='Enterprise') {
  name: 'customers-service-binding'
  parent: customersserviceapp
  properties: {
    bindingParameters: {}
    resourceId: customersserviceapp.id
    key: 'customers-service' // There is no API Key for MySQL
  }
  dependsOn: [
    serviceRegistry
  ]
}

resource vetsbinding 'Microsoft.AppPlatform/Spring/apps/bindings@2022-11-01-preview' = if (azureSpringAppsTier=='Enterprise') {
  name: 'vets-service-binding'
  parent: vetsserviceapp
  properties: {
    bindingParameters: {}
    resourceId: vetsserviceapp.id
    key: 'vets-service' // There is no API Key for MySQL
  }
  dependsOn: [
    serviceRegistry
  ]  
}

resource visitsbinding 'Microsoft.AppPlatform/Spring/apps/bindings@2022-11-01-preview' = if (azureSpringAppsTier=='Enterprise') {
  name: 'visits-service-binding'
  parent: visitsservicerapp
  properties: {
    bindingParameters: {
      /*
      databaseName: 'mydb'
      xxx: '' // username ? PWD ?
      */
    }
    key: 'visits-service' // There is no API Key for MySQL
    resourceId: visitsservicerapp.id
  }
  dependsOn: [
    serviceRegistry
  ]  
}

Example of App :

resource customersserviceapp 'Microsoft.AppPlatform/Spring/apps@2022-11-01-preview' = {
  name: 'customers-service'
  location: location
  parent: azureSpringApps
  identity: {
    type: 'UserAssigned'
    userAssignedIdentities: {
      '${customersServicedentity.id}': {}
    }      
  }
  properties: {
    addonConfigs: {
      azureMonitor: {
        enabled: true
      }
      applicationConfigurationService: {
        resourceId: '${azureSpringApps.id}/configurationServices/${applicationConfigurationServiceName}'
      }
      serviceRegistry: {
          resourceId: '${azureSpringApps.id}/serviceRegistries/${serviceRegistryName}'
      }
      buildService: {
        resourceId: '${azureSpringApps.id}/buildServices/${buildServiceName}'
      }
    }
    httpsOnly: false
    public: true
    temporaryDisk: {
      mountPath: '/tmp'
      sizeInGB: 5
    }
  }
  dependsOn: [
    appconfigservice
  ]  
}

In the Azure Portal, the Deployments UI shows for each of my 3 Apps service-binding:

{
    "status": "Failed",
    "error": {
        "code": "InvalidArgument",
        "message": "Not supported resource type: Microsoft.AppPlatform"
    }
}

The Bicep IaC deployment workflow shows this error logs:

RROR: ***"status":"Failed","error":***"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[***"code":"Conflict","message":"***\r\n  \"status\": \"Failed\",\r\n  \"error\": ***\r\n    \"code\": \"ResourceDeploymentFailure\",\r\n    \"message\": \"The resource operation completed with terminal provisioning state 'Failed'.\",\r\n    \"details\": [\r\n      ***\r\n        \"code\": \"DeploymentFailed\",\r\n        \"message\": \"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.\",\r\n        \"details\": [\r\n          ***\r\n            \"code\": \"BadRequest\",\r\n            \"message\": \"***\\r\\n  \\\"error\\\": ***\\r\\n    \\\"code\\\": \\\"InvalidArgument\\\",\\r\\n    \\\"message\\\": \\\"Not supported resource type: Microsoft.AppPlatform\\\",\\r\\n    \\\"target\\\": null,\\r\\n    \\\"details\\\": null\\r\\n  ***\\r\\n***\"\r\n          ***,\r\n          ***\r\n            \"code\": \"BadRequest\",\r\n            \"message\": \"***\\r\\n  \\\"error\\\": ***\\r\\n    \\\"code\\\": \\\"InvalidArgument\\\",\\r\\n    \\\"message\\\": \\\"Not supported resource type: Microsoft.AppPlatform\\\",\\r\\n    \\\"target\\\": null,\\r\\n    \\\"details\\\": null\\r\\n  ***\\r\\n***\"\r\n          ***,\r\n          ***\r\n            \"code\": \"BadRequest\",\r\n            \"message\": \"***\\r\\n  \\\"error\\\": ***\\r\\n    \\\"code\\\": \\\"InvalidArgument\\\",\\r\\n    \\\"message\\\": \\\"Not supported resource type: Microsoft.AppPlatform\\\",\\r\\n    \\\"target\\\": null,\\r\\n    \\\"details\\\": null\\r\\n  ***\\r\\n***\"\r\n          ***\r\n        ]\r\n      ***\r\n    ]\r\n  ***\r\n***"***]***
Error: Process completed with exit code 1.

To Reproduce Steps to reproduce : on my repo

Expected behavior The Iac deployment should be successfull

Screenshots N/A

Additional context

ezYakaEagle442 commented 1 year ago

In the App bindings, what is the correct value to set in the 'key' & 'bindingParameters' fields ?

ezYakaEagle442 commented 1 year ago

The doc is confusing :

https://learn.microsoft.com/en-us/azure/spring-apps/how-to-enterprise-service-registry#bind-a-service-to-the-service-registry explains that you have to Bind an App for service-to-service communication whereas the CLI shows that it refers to bindings Apps to bindings with Azure Data Services which is another topic.

az spring app binding --help
Group
    az spring app binding : Commands to manage bindings with Azure Data Services, you need to
    manually restart app to make settings take effect.

I have commented ALL the App bindings and it removed the related error message, and I also see All the Apps automatically bound in the portal / service registry

allxiao commented 1 year ago

Hi @ezYakaEagle442 ,

The Microsoft.AppPlatform/Spring/apps/bindings API is used by the Service Binding feature, which allows the customer to bind their data services (such as MySQL, CosmosDB, etc) to the ASA apps. It's not specifically for Enterprise tier.

If you need this service binding feature, you can check the CLI command az spring app binding --help to create or update data bindings to CosmosDB, MySQL or Redis. You can pass --debug --verbose to the command to show the actual ARM template payload that is passed to the server, which can help you to write the bicep payload. For MySQL, if you check az spring app binding mysql add --help you can see you need to pass the --key to the API. The resourceId passed to this API should be the target data service resource ID rather than the ASA ID. That's why it reported the ASA resource namespace Microsoft.AppPlatform was not supported.

Please note that the Service Binding feature is being replaced by the Service Connector. You can check this quickstart. For all the CLI commands mentioned in the quickstart tutorial, you can add --debug --verbose to check the actual payload, which can be copied to your bicep template if necessary.

If you need the app binding feature in Application Configuration Service, the CLI command is actually az spring application-configuration-service bind. You can check the --debug --verbose output and see that its actually updating the properties.addonConfigs.applicationConfigurationService property of the given app. You can write your bicep template with this property pointing to the ACS ID.