2017-11-27 2 views
0

を追加する場合は、新しいセキュリティグループは)私は a)はリスト Bを使用してパラメータとしてセキュリティグループIDのリストをキャプチャすることを、いくつかの対流圏コードを持ってEC2インスタンスを作成し、新規および既存のセキュリティグループ

groups = template.add_parameter(Parameter(
    "securityGroups", 
    Type="List<AWS::EC2::SecurityGroup::Id>", 
    Description="Security Groups for EC2 Instance", 
)) 


ec2_sg = template.add_resource(
    ec2.SecurityGroup(
    'sg', 
    GroupName = 'sg_test_app', 
    GroupDescription = 'Test SG', 
    VpcId = Ref(vpcid), 
    Tags=Tags(**tags) 
) 
) 

を作成します

inst_ec2 = template.add_resource(
    ec2.Instance(
    "EC2Instance", 
    ImageId = 'ami-8b8c57f8', 
    InstanceType = Ref(Type), 
    IamInstanceProfile=Ref(instance_profile), 
    SubnetId = Ref(snid), 
    Tags=Tags(**tags), 
    SecurityGroupIds = [ GetAtt(csso_ec2_sg, "GroupId") ], 
    DependsOn = [ 
     'EC2InstanceProfile', 
     'sg' 
    ] 
) 
) 

と私は(B)を参照している場合、これは動作します:

inst_ec2 = template.add_resource(
    ec2.Instance(
    "EC2Instance", 
    ImageId = 'ami-8b8c57f8', 
    InstanceType = Ref(Type), 
    IamInstanceProfile=Ref(instance_profile), 
    SubnetId = Ref(snid), 
    Tags=Tags(**tags), 
    SecurityGroupIds = groups, 
    DependsOn = [ 
     'EC2InstanceProfile', 
     'sg' 
    ] 
) 
) 
を私は、次の(a)は、この作品を参照してEC2を作成します

しかし、私は両方を追加する方法を考え出すことはできません - これは動作しません:

inst_ec2 = template.add_resource(
    ec2.Instance(
    "EC2Instance", 
    ImageId = 'ami-8b8c57f8', 
    InstanceType = Ref(Type), 
    IamInstanceProfile=Ref(instance_profile), 
    SubnetId = Ref(snid), 
    Tags=Tags(**tags), 
    SecurityGroupIds = [ GetAtt(csso_ec2_sg, "GroupId"), groups ], 
    DependsOn = [ 
     'EC2InstanceProfile', 
     'sg' 
    ] 
) 
) 

誰もがこれを行う方法を提案することができますか?

答えて

0

リストに参加して分割してみることができます。このようなものが動作する可能性があります。

SecurityGroupIds = Split(",", Join(",", [Join(",", groups), GetAtt(csso_ec2_sg, "GroupId")])) 
関連する問題