AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1005111
Accepted
Alan Mullett
Alan Mullett
Asked: 2020-03-01 09:14:53 +0800 CST2020-03-01 09:14:53 +0800 CST 2020-03-01 09:14:53 +0800 CST

Azure 模板:使用参数值按名称访问变量的成员

  • 772

我在模板中有一个变量,其中包含许多条目,这些条目将在我的模板中指定值。我的意思是我有

    "ipSecurityRestrictions" : {
      "denyAllInbound": 
      [
        {
          "ipAddress": "0.0.0.0/0",
          "action": "Deny",
          "priority": 100,
          "name": "Deny All Inbound"
        }
      ],
      "allowAppGatewayOnly": 
      [
        {
          "vnetSubnetResourceId": "[variables('appGatewaySubnet')]",
          "action": "allow",
          "priority": 100,
          "name": "Allow App Gateway"
        }
      ]
    }
  }

我目前使用一个简单的 if 函数来根据参数确定要使用的函数(它实际上比这要复杂一些,但这对于这个问题来说已经足够了。)所以目前我有类似的东西

[if (equals(parameters('a'), 'allowAppGatewayOnly'), variables('ipSecurityRestrictions').allowAppGatewayOnly, variables('ipSecurityRestrictions').denyAllInbound)]

这很高兴地工作。但是,我想在变量中添加另一个条目,我不喜欢在其中有一个 if 链的想法,它很快就会变得丑陋。

所以我尝试了各种基于参数值的间接使用方法(所有这些都在复制循环内,参数数组中的不同条目可能有不同的条目)。

我尝试过类似的事情

"[variables('ipSecurityRestrictions')[parameters('appservices')[copyIndex()].ipSecurityRestrictions]]"

但我要问的事实意味着它没有用。[编辑:它确实有效 - 如果参数值是正确的,并且其中没有杂散的单引号!]

是否可以在 ARM 模板中执行此操作,或者如果函数调用,我是否坚持使用嵌套?

谢谢

azure azure-arm-template
  • 1 1 个回答
  • 143 Views

1 个回答

  • Voted
  1. Best Answer
    Sam Cogan
    2020-03-02T05:45:23+08:002020-03-02T05:45:23+08:00

    您可以使用一个参数来选择您想要的对象,然后将其用作对象选择的一部分来实现这一点。您还需要从“ipSecurityRestrictions”对象中删除 Array 语法,因为它们都是 1 的数组,这没有任何好处并且会给您带来问题。

    下面的示例允许使用参数选择要使用的对象,然后在输出中使用该对象。您可以对此进行扩展以执行您需要的操作。

    {
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "ipRestriction": {
    
            "type": "string",
            "allowedValues": [
                "denyAllInbound",
                "allowAppGatewayOnly",
                "allowAll"
            ],
            "metadata": {
                "description": "description"
            }
        }
    },
    "variables": {
    
        "ipSecurityRestrictions": {
            "denyAllInbound": {
                "ipAddress": "0.0.0.0/0",
                "action": "Deny",
                "priority": 100,
                "name": "Deny All Inbound"
            },
    
            "allowAppGatewayOnly": {
                "action": "allow",
                "priority": 100,
                "name": "Allow App Gateway"
            },
            "allowAll": {
                "action": "allow",
                "priority": 100,
                "name": "Allow All"
            }
    
        }
    },
    "resources": [
    ],
    "outputs": {
        "example": {
            "type": "string",
            "value": "[variables('ipSecurityRestrictions')[parameters('ipRestriction')].name]"
        }
    },
    "functions": [
    ]
    

    }

    • 1

相关问题

  • 防火墙更改后失去对 VM azure 的 RDP 访问权限

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve