【问题标题】:Cloudformation: CommaDelimitedList of Cert ARNs for ListenerCertificate ResourceCloudformation:ListenerCertificate 资源的 Cert ARN 的 CommaDelimitedList
【发布时间】:2021-09-30 22:35:00
【问题描述】:

我正在尝试传入 CommaDelimitedList 以填充 AWS::ElasticLoadBalancingV2::ListenerCertificate 资源中的证书列表。

错误:属性证书的值必须是对象列表

我尝试了几种格式,包括以下几种:

Parameters:
  pAdditionalAlbListenerCertArns:
    Type: CommaDelimitedList
    Default: "arn:someCert1, arnsomeCert2"
    Description: enter list of the ACM Certificates (Arns)

## Resource Format 1 - I would think this way would work as the result is [thing1, thing2]
Resources:
rCertificatesList:
    Type: AWS::ElasticLoadBalancingV2::ListenerCertificate
    Properties:
      Certificates: ! Ref  pAdditionalAlbListenerCertArns

## Resource Format 2 - I know this should not work, because it's a single item trying to be populated by a list.
Resources:
rCertificatesList:
    Type: AWS::ElasticLoadBalancingV2::ListenerCertificate
    Properties:
      Certificates: 
        CertificateArn: ! Ref  pAdditionalAlbListenerCertArns

显然 Cfn 不够聪明,无法在每个项目前加上 CertificateArn:

我还尝试了 !Split!Sub!Join 的组合,但都给出了相同的错误。目前我不得不直接输入证书,这是不可行的。虽然我可以为每个证书创建单独的参数,或者使用!Select 将它们从列表中取出,但我不知道每个环境(DEV/TEST/PROD)中会有多少。

我知道这对安全组之类的东西很有效;我错过了什么吗?

提前致谢!

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    AWS::ElasticLoadBalancingV2::ListenerCertificate Certificate的格式为:

      Certificates: 
        - CertificateArn: String
    

    您的任何用途都不能使用它。事实上,什么都行不通,因为这需要循环,而 CloudFormation 不支持。实现您想要的唯一可行方法是开发您自己的custom CFN macro

    从头韵上讲,如果您需要在 CFN 代码中进行大量迭代,那么 CFN 可能不是适合您的工具。看看对循环有丰富支持的 CDK 或 terraform。

    【讨论】:

    • 我害怕这个。现在,我将使用 AWS:NoValue 为可能存在或不存在的值做一串 CertificateArn 值。我同意 Tf 几乎在各个方面都表现出色,但在过去 3 年中,我工作的环境是 100% Cfn,添加新的 IaC 工具是一个更大的话题。
    • @user2253884 我明白了。谢谢。如果您觉得答案有帮助,我们将不胜感激。
    猜你喜欢
    • 2011-12-02
    • 2021-09-18
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    • 2018-11-09
    • 2022-11-11
    • 1970-01-01
    • 2022-12-06
    相关资源
    最近更新 更多