Created
May 11, 2022 03:44
-
-
Save kmansoft/c490e7958b8ff8f1d2eb14a6cd115f08 to your computer and use it in GitHub Desktop.
AWS CloudFormation - two network interfaces - public and private
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Description: 'Test - simple 2 network interfaces' | |
Parameters: | |
KeyName: | |
Description: 'Key Pair name' | |
Type: 'AWS::EC2::KeyPair::KeyName' | |
Default: kman | |
Resources: | |
VPC: | |
Type: 'AWS::EC2::VPC' | |
Properties: | |
CidrBlock: '30.0.0.0/16' | |
EnableDnsSupport: true | |
EnableDnsHostnames: true | |
Tags: | |
- Key: Name | |
Value: 'simple' | |
SubnetPublic: | |
Type: 'AWS::EC2::Subnet' | |
Properties: | |
AvailabilityZone: !Select [0, !GetAZs ''] | |
CidrBlock: '30.0.1.0/24' | |
VpcId: !Ref VPC | |
Tags: | |
- Key: Name | |
Value: 'simple - public' | |
SubnetPrivate: | |
Type: 'AWS::EC2::Subnet' | |
Properties: | |
AvailabilityZone: !Select [0, !GetAZs ''] | |
CidrBlock: '30.0.2.0/24' | |
VpcId: !Ref VPC | |
Tags: | |
- Key: Name | |
Value: 'simple - private' | |
InternetGateway: | |
Type: 'AWS::EC2::InternetGateway' | |
Properties: | |
Tags: | |
- Key: Name | |
Value: 'simple' | |
VPCGatewayAttachment: | |
Type: 'AWS::EC2::VPCGatewayAttachment' | |
Properties: | |
VpcId: !Ref VPC | |
InternetGatewayId: !Ref InternetGateway | |
RouteTablePublic: | |
Type: 'AWS::EC2::RouteTable' | |
Properties: | |
VpcId: !Ref VPC | |
Tags: | |
- Key: Name | |
Value: 'simple' | |
RouteTableAssociation: | |
Type: 'AWS::EC2::SubnetRouteTableAssociation' | |
Properties: | |
SubnetId: !Ref SubnetPublic | |
RouteTableId: !Ref RouteTablePublic | |
RouteToInternet: | |
Type: 'AWS::EC2::Route' | |
Properties: | |
RouteTableId: !Ref RouteTablePublic | |
DestinationCidrBlock: '0.0.0.0/0' | |
GatewayId: !Ref InternetGateway | |
DependsOn: VPCGatewayAttachment | |
SecurityGroup: | |
Type: 'AWS::EC2::SecurityGroup' | |
Properties: | |
GroupDescription: 'Allow SSH and ping' | |
VpcId: !Ref VPC | |
SecurityGroupIngress: | |
- IpProtocol: tcp | |
FromPort: 22 | |
ToPort: 22 | |
CidrIp: '0.0.0.0/0' | |
- IpProtocol: icmp | |
FromPort: -1 | |
ToPort: -1 | |
CidrIp: '0.0.0.0/0' | |
Tags: | |
- Key: Name | |
Value: 'simple' | |
Host1: | |
Type: 'AWS::EC2::Instance' | |
Properties: | |
ImageId: 'ami-02541b8af977f6cdd' # Amazon Linux x86 | |
InstanceType: 't2.micro' | |
AvailabilityZone: !Select [0, !GetAZs ''] | |
KeyName: !Ref KeyName | |
NetworkInterfaces: | |
- SubnetId: !Ref SubnetPublic | |
AssociatePublicIpAddress: true | |
DeleteOnTermination: true | |
DeviceIndex: '0' | |
GroupSet: | |
- !Ref SecurityGroup | |
Tags: | |
- Key: Name | |
Value: 'simple - host1' | |
Host1Eth1: | |
Type: 'AWS::EC2::NetworkInterface' | |
Properties: | |
SubnetId: !Ref SubnetPrivate | |
GroupSet: | |
- !Ref SecurityGroup | |
Tags: | |
- Key: Name | |
Value: 'simple - host1 eth1' | |
Host1Eth1Attachment: | |
Type: 'AWS::EC2::NetworkInterfaceAttachment' | |
Properties: | |
DeleteOnTermination: true | |
DeviceIndex: 1 | |
NetworkInterfaceId: !Ref Host1Eth1 | |
InstanceId: !Ref Host1 | |
# default via 30.0.1.1 dev eth0 | |
# default via 30.0.2.1 dev eth1 metric 10001 | |
# 30.0.1.0/24 dev eth0 proto kernel scope link src 30.0.1.145 | |
# 30.0.2.0/24 dev eth1 proto kernel scope link src 30.0.2.251 | |
# 169.254.169.254 dev eth0 | |
# sudo ip r del default via 30.0.2.1 dev eth1 | |
# sudo ip r del 169.254.169.254 dev eth0 | |
# sudo ip r add 169.254.169.254 dev eth1 | |
# default via 30.0.1.1 dev eth0 | |
# 30.0.1.0/24 dev eth0 proto kernel scope link src 30.0.1.145 | |
# 30.0.2.0/24 dev eth1 proto kernel scope link src 30.0.2.251 | |
# 169.254.169.254 dev eth1 scope link |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment