I am trying to create a cross stack reference. Think of the stack that I am referencing from as the main VPC and the stack that I am creating now is basically creating a subnet in the main VPC and then sharing it with another account (VPC/resource sharing). When I validate this template in aws designer I get the Yaml not well formed error on line 15 which is:
CidrBlock: !Select [ 0, !Cidr [!ImportValue
'Fn::Sub': '${NetworkStackParameter}-VPCCIDR', 3, 8]]
I am new to coding and cloud formation so I appreciate any help.
Please see template below:
AWSTemplateFormatVersion: "2010-09-09"
#Description:
Parameters:
NetworkStackParameter:
Type: String
Resources:
#Create Private Subnet ABC
PrivateSubnetABC:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Select [ 0, !Cidr [!ImportValue
'Fn::Sub': '${NetworkStackParameter}-VPCCIDR', 3, 8]]
VpcId: !ImportValue
'Fn::Sub': '${NetworkStackParameter}-VPCID'
AvailabilityZone: "us-east-1a"
Tags:
- Key: "name"
Value: "PrivateSubnetABC"
#Create Resource Share
PrivateSubnetABCShare:
Type: AWS::RAM::ResourceShare
Properties:
# AllowExternalPrincipals: Boolean
Name: "Service ABC"
# PermissionArns:
# - String
Principals:
- "1234567890"
ResourceArns:
- !Sub 'arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:subnet/${PrivateSubnetABC}'
# Tags:
# - Tag
CodePudding user response:
In that case, its much easier to write it as individual blocks, rather then trying to do it in one line:
Resources:
#Create Private Subnet ABC
PrivateSubnetABC:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Select
- 0
- !Cidr
- !ImportValue
'Fn::Sub': '${NetworkStackParameter}-VPCCIDR'
- 3
- 8
VpcId: !ImportValue
'Fn::Sub': '${NetworkStackParameter}-VPCID'
AvailabilityZone: "us-east-1a"
Tags:
- Key: "name"
Value: "PrivateSubnetABC"