简体   繁体   English

在 Cloud Formation 模板中传递安全组 ID 和 Su.net ID

[英]Passing Security Group Ids and Subnet Ids in a Clould Formation template

Parameters:
  ClusterName:
    Type: String
  ClusterVersion:
    Type: Number
    AllowedValues: [1.21, 1.20, 1.19, 1.18]
  RoleArnValue:
    Type: String
  ListOfSubnetIDs: 
    Description: Array of Subnet IDs
    Type: List<AWS::EC2::Subnet::Id>
  ListOfSecurityGroupIDs:
    Description: Array of security group ids
    Type: List<AWS::EC2::SecurityGroup::Id>


Resources:
  EKSCluster:
    Type: AWS::EKS::Cluster
    Properties:
      Name: !Sub ${ClusterName}
      Version: !Sub ${ClusterVersion}
      RoleArn: !Sub ${RoleArnValue}
      ResourcesVpcConfig:
        SecurityGroupIds: 
          - !Sub ${ListOfSecurityGroupIDs}
        SubnetIds:
          - !Sub ${ListOfSubnetIDs}                  

Above is the.yaml clouldformation template I have created so i can spin up eks cluster.以上是我创建的 .yaml clouldformation模板,因此我可以启动 eks 集群。 Then i am using aws cli to spin up the cluster using the following command.然后我使用 aws cli 使用以下命令启动集群。

aws cloudformation deploy --template-file eks.yaml --stack-name cluster-test --parameter-overrides ClusterName=Dev ClusterVersion=1.21 ListOfSubnetIDs=subnet-11111d11b11b011f4,subnet-99999d237f87f11d7,subnet-222222c110c7e4be7,subnet-88888884de8d25176  ListOfSecurityGroupIDs=sg-01111111a21221 RoleArnValue=arn:aws:iam::123456546456:role/cluster-ServiceRole-WMIC72AOWSP0 --capabilities CAPABILITY_NAMED_IAM

I get the following error我收到以下错误

An error occurred (ValidationError) when calling the CreateChangeSet operation: Template error: variable ListOfSecurityGroupIDs in Fn::Sub expression does not resolve to a string

I am not sure why.我不确定为什么。 Am i using?sub in correctly.我使用了吗?sub in 正确吗? Would really appreciate input on this.非常感谢对此的投入。

Since you want to reference the parameters you provided the template as they are, you should use the Ref function.由于您想要按原样引用您提供模板的参数,因此您应该使用Ref function。

Here's an example of a valid template:下面是一个有效模板的示例:

Parameters:
  ClusterName:
    Type: String
  RoleArnValue:
    Type: String
  ListOfSubnetIDs: 
    Description: Array of Subnet IDs
    Type: List<AWS::EC2::Subnet::Id>
  ListOfSecurityGroupIDs:
    Description: Array of security group ids
    Type: List<AWS::EC2::SecurityGroup::Id>


Resources:
  EKSCluster:
    Type: AWS::EKS::Cluster
    Properties:
      Name: !Ref ClusterName
      RoleArn: !Ref RoleArnValue
      ResourcesVpcConfig:
        SecurityGroupIds: !Ref ListOfSecurityGroupIDs
        SubnetIds: !Ref ListOfSubnetIDs

and here's how I deployed it:这是我的部署方式:

aws cloudformation deploy --template-file eks.yml --stack-name cluster-test --parameter-overrides ClusterName=Dev ListOfSubnetIDs=subnet-be0a99c4,subnet-c71046ae ListOfSecurityGroupIDs=sg-009690ac6b3bff6df,sg-009a3f1cb63943941 -RoleArnValue=...

Sub should be used when you want to perform string manipulation.当您要执行字符串操作时,应使用Sub Checkout the examples from the documentation .查看文档中的示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Terraform Output 多个 su.net id - Terraform Output multiple subnet ids AWS Cloudformation - 安全组 ID 列表导出和导入 - SecurityGroupIds 无效 - AWS Cloudformation - security group ids list export and import - SecurityGroupIds not valid 如何正则表达式匹配包含 AWS 安全组 ID 的逗号分隔列表? - How to regex-match a comma delimited list containing AWS Security Group IDs? 传递 List 类型的参数<aws::ec2::subnet::id>到嵌套的 CloudFormation 模板</aws::ec2::subnet::id> - Passing parameters of type List<AWS::EC2::Subnet::Id> to nested CloudFormation template “没有完成帐户名和安全 ID 之间的映射。” 连接到 Azure 托管实例 - "No mapping between account names and security IDs was done." connecting to Azure managed instance 为什么我的安全组规则在从私有 su.net 调用公共 su.net 时不起作用? - Why does my security group rule not work when calling from the private to public subnet? Microsoft Defender for Cloud:“Su.nets 应该与 a.network 安全组相关联”状态不适用于专用端点 su.net - Microsoft Defender for Cloud: "Subnets should be associated with a network security group" status is Not Applicable for a private endpoints subnet 多租户ID时如何在Azure创建资源组? - How to create resource group in Azure when you are working with multiple tenant IDs? GCP 项目迁移 - 维护 ID - GCP Project Migration - Maintain IDs 只有在表中不唯一时才连接 ID - Concatenate IDs only IF not unique in table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM