我正在尝试创建一个具有几个子网,安全组和Internet网关的VPC。我收到错误“模板格式错误:无法解析的资源依赖项[VPCSubnet03]”
这是我的.yml文件的一部分
Parameters:
Subnet03CIDRBlock:
Type: String
Description: CIDR Block range for the public subnet 03 in the VPC if the region has more than 2 Availability Zones.
Conditions:
Has2Azs:
Fn::Or:
- Fn::Equals:
- {Ref: 'AWS::Region'}
- us-west-2
- Fn::Equals:
- {Ref: 'AWS::Region'}
- us-east-1
- Fn::Equals:
- {Ref: 'AWS::Region'}
- me-south-1
HasMore:
Fn::Not:
- Condition: Has2Azs
Resources:
VPCSubnet03:
Condition: HasMore
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref Subnet03CIDRBlock
AvailabilityZone: !Select [ 2, !GetAZs '' ]
Tags:
- Key: Name
Value: !Sub "${ProjectName}-Subnet03CIDRBlock"
供参考,这也是我的.json参数文件
[{
"ParameterKey": "Subnet03CIDRBlock",
"ParameterValue": "192.168.3.0/24"
},
{
"ParameterKey": "ProjectName",
"ParameterValue": "GreenBlueDeployment"
}]
我在Google上搜索了一段时间,不知道该如何解决。 AFAIK,定义了VPCSubnet03中的所有依赖项。
编辑: 我在VPCSubnet03的定义中建立了一个条件,但是忘记在相应的关联路由表资源中添加相同的条件。现在正在创建堆栈!
在更新我的.yml文件后,最终示例如下所示:
Parameters:
Subnet03CIDRBlock:
Type: String
Description: CIDR Block range for the public subnet 03 in the VPC if the region has more than 2 Availability Zones.
Conditions:
Has2Azs:
Fn::Or:
- Fn::Equals:
- {Ref: 'AWS::Region'}
- us-west-2
- Fn::Equals:
- {Ref: 'AWS::Region'}
- us-east-1
- Fn::Equals:
- {Ref: 'AWS::Region'}
- me-south-1
HasMore:
Fn::Not:
- Condition: Has2Azs
Resources:
VPCSubnet03:
Condition: HasMore
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref Subnet03CIDRBlock
AvailabilityZone: !Select [ 2, !GetAZs '' ]
Tags:
- Key: Name
Value: !Sub "${ProjectName}-Subnet03CIDRBlock"
Subnet03RouteTableAssociation:
Condition: HasMore
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref VPCSubnet03
RouteTableId: !Ref RouteTable
再次感谢您的帮助!
答案 0 :(得分:0)
答案 1 :(得分:0)
您的模板缺少ProjectName
和VPC
参数。因此应该是:
Parameters:
Subnet03CIDRBlock:
Type: String
Description: CIDR Block range for the public subnet 03 in the VPC if the region has more than 2 Availability Zones.
ProjectName:
Type: String
Default: my-project-name
VPC:
Type: AWS::EC2::VPC::Id
Conditions:
Has2Azs:
Fn::Or:
- Fn::Equals:
- {Ref: 'AWS::Region'}
- us-west-2
- Fn::Equals:
- {Ref: 'AWS::Region'}
- us-east-1
- Fn::Equals:
- {Ref: 'AWS::Region'}
- me-south-1
HasMore:
Fn::Not:
- Condition: Has2Azs
Resources:
VPCSubnet03:
Condition: HasMore
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref Subnet03CIDRBlock
AvailabilityZone: !Select [ 2, !GetAZs '' ]
Tags:
- Key: Name
Value: !Sub "${ProjectName}-Subnet03CIDRBlock"