skip to Main Content

Is there a way to add a resourceid as a parameter ?

param ftports array = [
  {
    name: 'test'
    value_id:resourceId('Microsoft.Network/virtualNetworks/subnets', myVNet_name, 'mySubnet')
  }
]

can’t get rid of the error "This symbol cannot be referenced here. Only other parameters can be referenced in parameter default values."

2

Answers


  1. I never tried your scenario but you can reference the existing subnet and then use its values:

    resource subnet 'Microsoft.Network/virtualNetworks/subnets@2022-07-01' existing = {
      name : '${vnetName}/${subnetName}'
      scope: resourceGroup(vnetRGName)
    }
    
    var ftports = [
      {
        name: 'test'
        value_id: subnet.id // or whatever you need
      }
    ]
    
    Login or Signup to reply.
  2. "This symbol cannot be referenced here. Only other parameters can be referenced in parameter default values."

    It means that the resourceID value cannot be referenced directly with the default value in Arm templates. Instead of passing it directly, Use reference function to pass the resource ID in the default value parameters.

    I created a subnets in virtual networks by referencing it with a default value and was able to deploy it successfully.

    I’ve taken a sample template to create a subnet within a virtual network from MSDoc and I modified the below script in json file:

    "parameters": {
    "location": {
    "type": "string",
    "defaultValue": "Westus",
    },
    "subnets": {
    "type": "string",
    "defaultValue": "[reference('Microsoft.Network/virtualNetworks/subnets', myvn, 'subnet1').id]"
    }
    }
    

    Output:

    enter image description here

    Deployment succeeded and created in Portal:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search