Skip to content
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

The apiVersion x was not found for the resource type #714

Closed
andre-lx opened this issue Nov 3, 2022 · 7 comments
Closed

The apiVersion x was not found for the resource type #714

andre-lx opened this issue Nov 3, 2022 · 7 comments
Assignees

Comments

@andre-lx
Copy link

andre-lx commented Nov 3, 2022

Hi.

We are facing the following warnings in our validation, but the template works without any problem:

Warning:         The apiVersion 2021-09-30-preview was not found for the resource type: Microsoft.ManagedIdentity/userAssignedIdentities

Warning:         The apiVersion 2021-08-01 was not found for the resource type: Microsoft.Network/privateEndpoints/privateDnsZoneGroups

Warning:         The apiVersion 2022-01-01-preview was not found for the resource type: Microsoft.Authorization

For the type privateDnsZoneGroups and Microsoft.Authorization I cannot find it in the arm-ttk/cache/AllAzureResources.cache.json file.

For the type userAssignedIdentitiesI can see the version with "2022-01-31-PREVIEW",, so maybe is because of the caps lock PREVIEW word?

Also, the template looks like is not warning me about recent versions, for example:

            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2021-08-01",

I did not receive the warning about the new versions present in the file:

      "apiVersions": [
        "2022-07-01",
        "2022-05-01",
        "2022-01-01",
        "2021-12-01",
        "2021-08-01",

Only the 2 years old (730 days)warning. It is possible to activate this test in order to use/be warned always about the latest version?

Thanks, André

@ghost ghost added the Needs: triage 🔍 label Nov 3, 2022
@StartAutomating
Copy link
Collaborator

@andre-lx we recently did some changes that hopefully improved the API Version checking for case.

Could kindly:

  1. Attach your template (to the degree you can share it)
  2. Provide the version of arm-ttk you are currently using.

Also, you should be able to adjust the parameters for this particular test with -TestParameter @{}:

# Run the api versions test, but warn if the api version is more than 30 days old (you could just as easily say 3000)
Test-AzTemplate -TemplatePath .\MyTemplate.json -Test "APIVersions-Should-Be-Recent" -TestParameter @{
    NumberOfDays = 30
}

@andre-lx
Copy link
Author

andre-lx commented Nov 12, 2022

Hello.

About the version, we always use the master version in our pipelines.

For the following template, I can conclude that:

  1. For the Microsoft.ManagedIdentity/userAssignedIdentities using the apiVersion as Uppercase it works and it did not give a warning. But, on the other hand, the Microsoft.ContainerRegistry/registries fails in uppercase and passes in lowercase. In the arm-ttk/cache/AllAzureResources.cache.json file, we can see this inconsistency:
  "Microsoft.ManagedIdentity/userAssignedIdentities": [
    {
      "aliases": null,
      "apiProfiles": null,
      "apiVersions": [
        "2022-01-31-PREVIEW",

  "Microsoft.ContainerRegistry/registries": [
    {
      "aliases": null,
      "apiProfiles": null,
      "apiVersions": [
        "2022-02-01-preview",

  1. For the most recent versions, passing the parameter it works (I did not found this TestParameter nowhere, so thanks).
  2. For the Microsoft.Network/privateEndpoints/privateDnsZoneGroups the apiVersion was not found.
  3. For the Microsoft.Authorization I'm not sure why is this is being validated under the Microsoft.Storage/storageAccounts/providers/roleAssignments, since this is used only under the name property.
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "metadata": {
                "description": "The location of the platform."
            },
            "type": "string"
        }
    },
    "variables": {
		
    },
    "resources": [
		//
		// Test 1 - userAssignedIdentities API Version Uppercase amd Lowercase
		// this gives a warning
		{
            "type": "Microsoft.ManagedIdentity/userAssignedIdentities",
            "apiVersion": "2022-01-31-preview",
            "name": "test",
            "location": "[parameters('location')]"
        },
        {
            "type": "Microsoft.ContainerRegistry/registries",
            "apiVersion": "2022-02-01-PREVIEW",
            "name": "[variables('acrName')]",
            "location": "[parameters('location')]"
        },
		// this pass
        {
            "type": "Microsoft.ManagedIdentity/userAssignedIdentities",
            "apiVersion": "2022-01-31-PREVIEW",
            "name": "test",
            "location": "[parameters('location')]"
        },
        {
            "type": "Microsoft.ContainerRegistry/registries",
            "apiVersion": "2022-02-01-preview",
            "name": "[variables('acrName')]",
            "location": "[parameters('location')]"
        },
		//
		// Test 2 - most recent versions
        // most recent
        {
            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2022-07-01",
            "name": "[variables('vnetName')]",
            "location": "[parameters('location')]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "172.16.0.0/18"
                    ]
                }
            },
            "resources": []
        },
		// to update
        {
            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2021-08-01",
            "name": "[variables('vnetName')]",
            "location": "[parameters('location')]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "172.16.0.0/18"
                    ]
                }
            },
            "resources": []
        },
		//
		// Test 3 - privateDnsZoneGroups
		// apiVersion 2021-08-01 was not found for the resource type
        {
            "type": "Microsoft.Network/privateEndpoints/privateDnsZoneGroups",
            "apiVersion": "2021-08-01",
            "name": "[concat('test','/test')]",
            "location": "[parameters('location')]",
            "properties": {
                "privateDnsZoneConfigs": [
                    {
                        "name": "config",
                        "properties": {
                            "privateDnsZoneId": "[resourceId('Microsoft.Network/privateDnsZones', 'test')]"
                        }
                    }
                ]
            }
        },
		//
		// Test 4 - Microsoft.Authorization
		// apiVersion 2022-01-01-preview was not found for the resource type: Microsoft.Authorization
		{
            "type": "Microsoft.Storage/storageAccounts/providers/roleAssignments",
            "apiVersion": "2022-01-01-preview",
            "name": "[concat(variables('storageAccountName'), '/Microsoft.Authorization/', variables('bootstrapRoleAssignmentStorageAdmin'))]",
            "properties": {
                "roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]",
                "principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', 'test')).principalId]",
                "scope": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
                "principalType": "ServicePrincipal"
            }
        }
    ],
    "outputs": {

    }
}

Running:

sh arm-ttk/Test-AzTemplate.sh -TemplatePath 'tests.json' -TestParameter @{NumberOfDays=30}

I get the following result:

Validating arm-ttk\tests.json                                                                                           
  JSONFiles Should Be Valid                                                                                             
    [+] JSONFiles Should Be Valid (18 ms)                                                                               
Total : 1                                                                                                               
Fail  : 0                                                                                                               
Pass  : 1                                                                                                               
                                                                                                                        
                                                                                                                        
                                                                                                                        
  adminUsername Should Not Be A Literal                                                                                 
    [+] adminUsername Should Not Be A Literal (59 ms)                                                                   
  apiVersions Should Be Recent In Reference Functions                                                                   
    [+] apiVersions Should Be Recent In Reference Functions (32 ms)                                                     
  apiVersions Should Be Recent                                                                                          
    [-] apiVersions Should Be Recent (151 ms)                                                                           
        The apiVersion 2022-01-31-preview was not found for the resource type: Microsoft.ManagedIdentity/userAssignedIdentities
        The apiVersion 2022-02-01-PREVIEW was not found for the resource type: Microsoft.ContainerRegistry/registries   
        Api versions must be the latest or under 0.0821917808219178 years old (30 days) - API version 2021-08-01 of Microsoft.Network/virtualNetworks is 
468 days old                                                                                                            
        Valid Api Versions:                                                                                             
        2022-07-01                                                                                                      
        2022-07-01                                                                                                      
        The apiVersion 2021-08-01 was not found for the resource type: Microsoft.Network/privateEndpoints/privateDnsZoneGroups
        The apiVersion 2022-01-01-preview was not found for the resource type: Microsoft.Authorization                  
                                                                                                                        
  artifacts parameter                                                                                                   
    [+] artifacts parameter (9 ms)                                                                                      
  CommandToExecute Must Use ProtectedSettings For Secrets                                                               
    [+] CommandToExecute Must Use ProtectedSettings For Secrets (37 ms)                                                 
  DependsOn Best Practices                                                                                              
    [+] DependsOn Best Practices (23 ms)                                                                                
  Deployment Resources Must Not Be Debug                                                                                
    [+] Deployment Resources Must Not Be Debug (25 ms)                                                                  
  DeploymentTemplate Must Not Contain Hardcoded Uri                                                                     
    [+] DeploymentTemplate Must Not Contain Hardcoded Uri (22 ms)                                                       
  DeploymentTemplate Schema Is Correct                                                                                  
    [+] DeploymentTemplate Schema Is Correct (4 ms)                                                                     
  Dynamic Variable References Should Not Use Concat                                                                     
    [+] Dynamic Variable References Should Not Use Concat (4 ms)                                                        
  IDs Should Be Derived From ResourceIDs                                                                                
    [+] IDs Should Be Derived From ResourceIDs (60 ms)                                                                  
  Location Should Not Be Hardcoded                                                                                      
    [+] Location Should Not Be Hardcoded (96 ms)                                                                        
  ManagedIdentityExtension must not be used                                                                             
    [+] ManagedIdentityExtension must not be used (11 ms)                                                               
  Min And Max Value Are Numbers                                                                                         
    [+] Min And Max Value Are Numbers (14 ms)                                                                           
  Outputs Must Not Contain Secrets                                                                                      
    [+] Outputs Must Not Contain Secrets (14 ms)                                                                        
  Parameter Types Should Be Consistent                                                                                  
    [+] Parameter Types Should Be Consistent (44 ms)                                                                    
  Parameters Must Be Referenced                                                                                         
    [+] Parameters Must Be Referenced (23 ms)                                                                           
  Password params must be secure                                                                                        
    [+] Password params must be secure (7 ms)                                                                           
  providers apiVersions Is Not Permitted                                                                                
    [+] providers apiVersions Is Not Permitted (4 ms)                                                                   
  ResourceIds should not contain                                                                                        
    [+] ResourceIds should not contain (23 ms)                                                                          
  Resources Should Have Location                                                                                        
    [+] Resources Should Have Location (10 ms)                                                                          
  Resources Should Not Be Ambiguous                                                                                     
    [+] Resources Should Not Be Ambiguous (10 ms)                                                                       
  Secure Params In Nested Deployments                                                                                   
    [+] Secure Params In Nested Deployments (20 ms)                                                                     
  Secure String Parameters Cannot Have Default                                                                          
    [+] Secure String Parameters Cannot Have Default (6 ms)                                                             
  Template Should Not Contain Blanks                                                                                    
    [+] Template Should Not Contain Blanks (57 ms)                                                                      
  URIs Should Be Properly Constructed                                                                                   
    [+] URIs Should Be Properly Constructed (23 ms)                                                                     
  Variables Must Be Referenced                                                                                          
    [+] Variables Must Be Referenced (7 ms)                                                                             
  Virtual Machines Should Not Be Preview                                                                                
    [+] Virtual Machines Should Not Be Preview (29 ms)                                                                  
  VM Images Should Use Latest Version                                                                                   
    [+] VM Images Should Use Latest Version (3 ms)                                                                      
  VM Size Should Be A Parameter                                                                                         
    [+] VM Size Should Be A Parameter (22 ms)                                                                           
Total : 31                                                                                                              
Fail  : 1                                                                                                               
Pass  : 30                                                                                         

@StartAutomating
Copy link
Collaborator

@andre-lx thanks for providing this information.

We have a PR in that hopefully will alleviate this issue. #709

Hopefully it will be merged soon and resolve your issue.

@bmoore-msft
Copy link
Contributor

I'm not able to repro with 0.20 - @andre-lx - this has been merge, feel free to reopen if you're still seeing it.

@andre-lx
Copy link
Author

andre-lx commented Nov 21, 2022

Hi @bmoore-msft

I confirm that the last version fixes most of the issues.

The only one I still see is the: The apiVersion 2022-01-01-preview was not found for the resource type: Microsoft.Authorization for the following example:

		{
            "type": "Microsoft.Storage/storageAccounts/providers/roleAssignments",
            "apiVersion": "2022-01-01-preview",
            "name": "[concat(variables('storageAccountName'), '/Microsoft.Authorization/', variables('bootstrapRoleAssignmentStorageAdmin'))]",
            "properties": {
                "roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]",
                "principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', 'test')).principalId]",
                "scope": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
                "principalType": "ServicePrincipal"
            }
        }

Thanks, André

@bmoore-msft
Copy link
Contributor

Ah - got it, I glossed over that one as "accurate"... We do have issues with extension resources when you overload the type... however the pattern is antiquated, so we decided not to fix it. The recommended way to author that snippet would be to use the scope property:

        {
            "scope": "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
            "type": "Microsoft.Authorization/roleAssignments",
            "apiVersion": "2022-01-01-preview",
            "name": "[variables('bootstrapRoleAssignmentStorageAdmin')]",
            "properties": { ... }
        }

@andre-lx
Copy link
Author

Sorry for the late reply.

I can confirm that your solution works as expected.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants