gpt4 book ai didi

aws-cloudformation - 添加多个SecurityGroupIngress规则

转载 作者:行者123 更新时间:2023-12-03 07:21:17 32 4
gpt4 key购买 nike

我正在尝试创建循环依赖安全组。因此,首先我创建两个安全组。然后我尝试添加入站规则。但我无法为入站规则添加多个规则。

"SecurityGroup01": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "SecurityGroup01",
"VpcId": { "Ref": "VPCID" },
"SecurityGroupEgress": [
{ "IpProtocol": "tcp", "FromPort": "1", "ToPort": "65535", "CidrIp": "0.0.0.0/0" },
{ "IpProtocol": "icmp", "FromPort": "8", "ToPort": "-1", "CidrIp": "0.0.0.0/0" }
],
"Tags": [
{ "Key": "Name", "Value": "SG01" }
]
}
},
"SecurityGroup02": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "SecurityGroup02",
"VpcId": {
"Ref": "VPCID"
},
"SecurityGroupEgress": [
{ "IpProtocol": "tcp", "FromPort": "1", "ToPort": "65535", "CidrIp": "0.0.0.0/0" },
{ "IpProtocol": "icmp", "FromPort": "8", "ToPort": "-1", "CidrIp": "0.0.0.0/0" }
],
"Tags": [
{ "Key": "Name", "Value": "SG02" }
]
}
},
"SG01InboundRule": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"IpProtocol": "tcp", "FromPort": "3389", "ToPort": "3389", "CidrIp": { "Ref": "LocalIPAddress" },
"DestinationSecurityGroupId": { "Fn::GetAtt": [ "SecurityGroup02", "GroupId" ] },
"GroupId": { "Fn::GetAtt": [ "SecurityGroup01", "GroupId" ] }
}
}

预期结果添加多个规则

"SG01InboundRule": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": [
"IpProtocol": "tcp", "FromPort": "3389", "ToPort": "3389", "CidrIp": { "Ref": "LocalIPAddress" }, "GroupId": { "Fn::GetAtt": [ "SecurityGroup01", "GroupId" ] }
"IpProtocol": "tcp", "FromPort": "4200", "ToPort": "4200", "CidrIp": { "Ref": "LocalIPAddress" }, "GroupId": { "Fn::GetAtt": [ "SecurityGroup01", "GroupId" ] }
]
}

最佳答案

资源 AWS::EC2::SecurityGroupIngress 仅包含一条规则,但您可以创建多个 AWS::EC2::SecurityGroupIngress 并将它们附加到同一个规则安全组。

所以你会:

"SG01InboundRule": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"IpProtocol": "tcp", "FromPort": "3389", "ToPort": "3389", "CidrIp": { "Ref": "LocalIPAddress" },
"DestinationSecurityGroupId": { "Fn::GetAtt": [ "SecurityGroup02", "GroupId" ] },
"GroupId": { "Fn::GetAtt": [ "SecurityGroup01", "GroupId" ] }
}
}

"SG02InboundRule": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"IpProtocol": "tcp", "FromPort": "4200", "ToPort": "4200", "CidrIp": { "Ref": "LocalIPAddress" },
"DestinationSecurityGroupId": { "Fn::GetAtt": [ "SecurityGroup02", "GroupId" ] },
"GroupId": { "Fn::GetAtt": [ "SecurityGroup01", "GroupId" ] }
}
}

关于aws-cloudformation - 添加多个SecurityGroupIngress规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55914644/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com