timz_123
timz_123

Reputation: 437

Resources not available in Azure portal after successful bicep deployment

I am very new to Bicep. I have created a test bicep solution in VSCode as below:

  1. main.bicep

     param prefix string
     param environment string
     param deploymentLocation string
     @allowed(['prod','non-prod'])
     param environmentType string
    
     var storageAccountSkuName = (environmentType == 'prod') ? 'Standard_GRS' : 'Standard_LRS'
    
     targetScope = 'subscription'
    
     resource resourceGroup 'Microsoft.Resources/resourceGroups@2023-07-01' = {
       name: '${prefix}-${environment}-rg'
       location: deploymentLocation
     }
    
     module storageAccount 'storage.bicep' = {
       scope: resourceGroup
       name: 'storageModule'
       params: {
         storageAccountName: '${prefix}${environment}sa'
         storageAccountLocation: deploymentLocation
         storageAccountSkuName: storageAccountSkuName
      }
    }
    
  2. storage.bicep

    param storageAccountName string
    param storageAccountLocation string //= resourceGroup().location
    param storageAccountSkuName string
    
    resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
      name: storageAccountName
      location: storageAccountLocation
      sku: {
        name: storageAccountSkuName
      }
      kind: 'Storage'
    }
    

In the main.bicep, when I only had 'resource resourceGroup' code, the deployment went well and I could see the resource group in Azure portal. Once done, I deleted the resourceGroup manually from the Azure portal.

Now, after adding 'module storageAccount' code to the main.bicep file, I am trying to deploy main.bicep using below CLI command:

az deployment sub create --name AbcTest-sub --location eastus --template-file main.bicep

I get below output:

A new Bicep release is available: v0.25.53. Upgrade now by running "az bicep upgrade".
Please provide string value for 'prefix' (? for help): abc
Please provide string value for 'environment' (? for help): dev
Please provide string value for 'deploymentLocation' (? for help): eastus
Please provide string value for 'environmentType' (? for help): 
 [1] prod
 [2] non-prod
Please enter a choice [Default choice(1)]: 2
{
  "id": "/subscriptions/21fc5d5d-8ee6-4850-8b7e-2fdcf71d834b/providers/Microsoft.Resources/deployments/AbcTest-sub",
  "location": "eastus",
  "name": "AbcTest-sub",
  "properties": {
    "correlationId": "b0612345-c75b-4683-86e1-e6fee6a2c503",
    "debugSetting": null,
    "dependencies": [
      {
        "dependsOn": [
          {
            "id": "/subscriptions/21fc5d5d-8ee6-4850-8b7e-2fdcf71d834b/resourceGroups/abc-dev-rg",
            "resourceName": "abc-dev-rg",
            "resourceType": "Microsoft.Resources/resourceGroups"
          }
        ],
        "id": "/subscriptions/21fc5d5d-8ee6-4850-8b7e-2fdcf71d834b/resourceGroups/abc-dev-rg/providers/Microsoft.Resources/deployments/storageModule",
        "resourceGroup": "abc-dev-rg",
        "resourceName": "storageModule",
        "resourceType": "Microsoft.Resources/deployments"
      }
    ],
    "duration": "PT35.0652943S",
    "error": null,
    "mode": "Incremental",
    "onErrorDeployment": null,
    "outputResources": [
      {
        "id": "/subscriptions/21fc5d5d-8ee6-4850-8b7e-2fdcf71d834b/resourceGroups/abc-dev-rg"
      },
      {
        "id": "/subscriptions/21fc5d5d-8ee6-4850-8b7e-2fdcf71d834b/resourceGroups/abc-dev-rg/providers/Microsoft.Storage/storageAccounts/abcdevsa",
        "resourceGroup": "abc-dev-rg"
      }
    ],
    "outputs": null,
    "parameters": {
      "deploymentLocation": {
        "type": "String",
        "value": "eastus"
      },
      "environment": {
        "type": "String",
        "value": "dev"
      },
      "environmentType": {
        "type": "String",
        "value": "non-prod"
      },
      "prefix": {
        "type": "String",
        "value": "abc"
      }
    },
    "parametersLink": null,
    "providers": [
      {
        "id": null,
        "namespace": "Microsoft.Resources",
        "providerAuthorizationConsentState": null,
        "registrationPolicy": null,
        "registrationState": null,
        "resourceTypes": [
          {
            "aliases": null,
            "apiProfiles": null,
            "apiVersions": null,
            "capabilities": null,
            "defaultApiVersion": null,
            "locationMappings": null,
            "locations": [
              "eastus"
            ],
            "properties": null,
            "resourceType": "resourceGroups",
            "zoneMappings": null
          },
          {
            "aliases": null,
            "apiProfiles": null,
            "apiVersions": null,
            "capabilities": null,
            "defaultApiVersion": null,
            "locationMappings": null,
            "locations": [
              null
            ],
            "properties": null,
            "resourceType": "deployments",
            "zoneMappings": null
          }
        ]
      }
    ],
    "provisioningState": "Succeeded",
    "templateHash": "7124063297348834220",
    "templateLink": null,
    "timestamp": "2024-02-14T10:16:45.296532+00:00",
    "validatedResources": null
  },
  "tags": null,
  "type": "Microsoft.Resources/deployments"
}

Issue Even after successful deployment, I am not able to see the above 2 resources in the Azure portal. Nor do I see any errors. Please let me know the root cause behind. Any help/suggestion would help me a lot.

Thank you so much in advance.

Upvotes: 0

Views: 228

Answers (1)

Jahnavi
Jahnavi

Reputation: 7898

It is a very transient problem happens with bicep environment. Check below steps to resolve the issue.

Need to check below:

Firstly, check all the resource names with suffixes or prefixes are correctly aligned to the bicep name policy.

Go to the Deployments section under resource group blade and check the deployment history to check if any errors are occurred during deployment as shown below.

enter image description here

Make sure you have the proper Contributor & Reader permissions to access and view the resource after deployment.

Use az resource show CLI command to check the resource existence if the resource is not found in Portal.

I tried the same code as you, executed using Visual Studio code editor and was able to deploy, view the resources successfully as shown below.

main.bicep:

param prefix string = 'janu'
param environment string = 'dev'
param deploymentLocation string = 'eastUS'
param environmentType string = 'prod'

var storageAccountSkuName = (environmentType == 'prod') ? 'Standard_GRS' : 'Standard_LRS'
targetScope = 'subscription'
resource resourceGroup 'Microsoft.Resources/resourceGroups@2023-07-01' = {
   name: '${prefix}-${environment}-rg'
   location: deploymentLocation
}
 module storageAccount 'storage.bicep' = {
   scope: resourceGroup
   name: 'storageModule'
   params: {
     storageAccountName: '${prefix}${environment}sa'
     storageAccountLocation: deploymentLocation
     storageAccountSkuName: storageAccountSkuName
  }
}

storage.bicep:

param storageAccountName string = 'newjahs'
param storageAccountLocation string = resourceGroup().location
param storageAccountSkuName string = 'Standard_LRS'
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
  name: storageAccountName
  location: storageAccountLocation
  sku: {
    name: storageAccountSkuName
  }
  kind: 'Storage'
}

enter image description here

enter image description here

Reference: Troubleshooting MSDoc & Deployment issues

Upvotes: 0

Related Questions