123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 | { "AWSTemplateFormatVersion": "2010-09-09", "Description": "Setup a vpc, which contains two subnets and one NAT machine", "Parameters": { "KeyName": { "Description": "Name of and existing EC2 KeyPair to enable SSH access to the instance", "Type": "String" }, "VpcCidr": { "Description": "CIDR address for the VPC to be created.", "Type": "String", "Default": "10.2.0.0/16" }, "AnyCidr": { "Description": "CIDR address for Any Where.", "Type": "String", "Default": "0.0.0.0/0" }, "AvailabilityZone1": { "Description": "First AZ.", "Type": "String", "Default": "cn-north-1a" }, "PublicSubnetCidr": { "Description": "Address range for a public subnet to be created in AZ1.", "Type": "String", "Default": "10.2.1.0/24" }, "PrivateSubnetCidr": { "Description": "Address range for private subnet.", "Type": "String", "Default": "10.2.2.0/24" }, "NATInstanceType": { "Description": "Instance type for NAT", "Type": "String", "Default": "t1.micro" } }, "Mappings": { "AWSNATAMI": { "cn-north-1": { "AMI": "ami-eab220d3" } } }, "Resources": { "VPC": { "Type": "AWS::EC2::VPC", "Properties": { "CidrBlock": { "Ref": "VpcCidr" }, "Tags": [ { "Key": "Name", "Value": "VPC" } ] } }, "InternetGateWay": { "Type": "AWS::EC2::InternetGateway", "Properties": { "Tags": [ { "Key": "Name", "Value": "INTERNET_GATEWAY" } ] } }, "GatewayToInternet": { "Type": "AWS::EC2::VPCGatewayAttachment", "Properties": { "InternetGatewayId": { "Ref": "InternetGateWay" }, "VpcId": { "Ref": "VPC" } } }, "PublicSubnet": { "Type": "AWS::EC2::Subnet", "Properties": { "CidrBlock": { "Ref": "PublicSubnetCidr" }, "AvailabilityZone": { "Ref": "AvailabilityZone1" }, "Tags": [ { "Key": "Name", "Value": "PUBLIC_SUBNET" } ], "VpcId": { "Ref": "VPC" } } }, "PrivateSubnet": { "Type": "AWS::EC2::Subnet", "Properties": { "CidrBlock": { "Ref": "PrivateSubnetCidr" }, "AvailabilityZone": { "Ref": "AvailabilityZone1" }, "Tags": [ { "Key": "Name", "Value": "PRIVATE_SUBNET" } ], "VpcId": { "Ref": "VPC" } } }, "DefaultSecurityGroup": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupDescription": "Default Instance SecurityGroup", "SecurityGroupIngress": [ { "IpProtocol": "-1", "CidrIp": { "Ref": "VpcCidr" } } ], "Tags": [ { "Key": "Name", "Value": "DEFAULT_SECURITY_GROUP" } ], "VpcId": { "Ref": "VPC" } } }, "PublicRouteTable": { "Type": "AWS::EC2::RouteTable", "Properties": { "VpcId": { "Ref": "VPC" }, "Tags": [ { "Key": "Name", "Value": "PUBLIC_ROUTE_TABLE" } ] } }, "PublicRoute": { "Type": "AWS::EC2::Route", "Properties": { "DestinationCidrBlock": { "Ref": "AnyCidr" }, "GatewayId": { "Ref": "InternetGateWay" }, "RouteTableId": { "Ref": "PublicRouteTable" } } }, "PublicSubnetRouteTableAssociation": { "Type": "AWS::EC2::SubnetRouteTableAssociation", "Properties": { "RouteTableId": { "Ref": "PublicRouteTable" }, "SubnetId": { "Ref": "PublicSubnet" } } }, "NATEIP": { "Type": "AWS::EC2::EIP", "Properties": { "InstanceId": { "Ref": "NATInstance" } } }, "NATInstance": { "Type": "AWS::EC2::Instance", "Properties": { "InstanceType": { "Ref": "NATInstanceType" }, "KeyName": { "Ref": "KeyName" }, "SubnetId": { "Ref": "PublicSubnet" }, "SourceDestCheck": false, "ImageId": { "Fn::FindInMap": [ "AWSNATAMI", { "Ref": "AWS::Region" }, "AMI" ] }, "Tags": [ { "Key": "Name", "Value": "NAT" } ], "SecurityGroupIds": [ { "Ref": "NATSecurityGroup" } ] } }, "PrivateSubnetRouteTable": { "Type": "AWS::EC2::RouteTable", "Properties": { "VpcId": { "Ref": "VPC" }, "Tags": [ { "Key": "Name", "Value": "PRIVATE_SUBNET_ROUTE_TABLE" } ] } }, "PrivateSubnetRoute": { "Type": "AWS::EC2::Route", "Properties": { "DestinationCidrBlock": { "Ref": "AnyCidr" }, "InstanceId": { "Ref": "NATInstance" }, "RouteTableId": { "Ref": "PrivateSubnetRouteTable" } } }, "PrivateSubnetRouteTableAssociation": { "Type": "AWS::EC2::SubnetRouteTableAssociation", "Properties": { "RouteTableId": { "Ref": "PrivateSubnetRouteTable" }, "SubnetId": { "Ref": "PrivateSubnet" } } }, "NATSecurityGroup": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupDescription": "NAT Instance SecurityGroup", "SecurityGroupIngress": [ { "IpProtocol": "-1", "CidrIp": { "Ref": "VpcCidr" } } ], "Tags": [ { "Key": "Name", "Value": "NAT_SECURITY_GROUP" } ], "VpcId": { "Ref": "VPC" } } } }, "Outputs": { "VPCId": { "Description": "VPC id", "Value": { "Ref": "VPC" } }, "PublicSubnetId": { "Description": "public subnet id", "Value": { "Ref": "PublicSubnet" } }, "PrivateSubnetId": { "Description": "private subnet id", "Value": { "Ref": "PrivateSubnet" } }, "NATSecurityGroupId": { "Description": "NAT SG id", "Value": { "Ref": "NATSecurityGroup" } }, "NATEIP": { "Description": "NAT Server EIP.", "Value": { "Ref": "NATEIP" } } }}
|