#########################################################
# ここで分割
#########################################################
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
Prefix:
Type: String
Description: "A prefix that does not conflict with other instances when multiple instances are launched"
VPCCidr:
Type: String
Description: IP Address range for the VPN connected VPC
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
MinLength: 9
MaxLength: 18
Default: 10.0.0.0/16
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})
Resources:
MainVpc:
Properties:
CidrBlock: !Ref VPCCidr
Tags:
- Key: 'Name'
MainInetGateway:
Type: 'AWS::EC2::InternetGateway'
Properties:
Tags:
- Key: 'Name'
Value: !Sub ${Prefix}-main-igw
MainVpcGatewayAttachment:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
InternetGatewayId: !Ref MainInetGateway
VpcId: !Ref MainVpc
Outputs:
VPCCidr:
Export:
Name: 'VPCCidr'
MainVpc:
Export:
MainInetGateway:
Value: !Ref MainInetGateway
Export:
Name: 'main-igw-id'
#########################################################
# 分割
#########################################################
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
Prefix:
Type: String
Description: "A prefix that does not conflict with other instances when multiple instances are launched"
SubnetCidr:
Type: String
Description: SubnetCidr
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
MinLength: 9
MaxLength: 18
Default: 10.0.1.0/24
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})
Resources:
PublicSubnet:
Properties:
CidrBlock: !Ref SubnetCidr
MapPublicIpOnLaunch: true
VpcId: {'Fn::ImportValue': 'main-vpc-id'}
Tags:
- Key: 'Name'
Value: !Sub ${Prefix}-public-subnet
PublicRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: {'Fn::ImportValue': 'main-vpc-id'}
Tags:
- Key: 'Name'
Value: !Sub ${Prefix}-public-rtb
PublicDefaultRoute:
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: {'Fn::ImportValue': 'main-igw-id'}
PublicSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnet
RouteTableId: !Ref PublicRouteTable
Outputs:
SubnetCidr:
Export:
Name: 'SubnetCidr'
PublicSubnet:
Export:
Name: !Sub 'public-subnet-id'
#########################################################
# 分割
#########################################################
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
Prefix:
Type: String
Description: "A prefix that does not conflict with other instances when multiple instances are launched"
Resources:
PublicSecurityGroupWin:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupName: public-sg-Win
GroupDescription: "SecurityGroup for Public EC2 Linux"
SecurityGroupIngress:
FromPort: '3389'
ToPort: '3389'
CidrIp: 0.0.0.0/0
Tags:
- Key: 'Name'
Value: !Sub ${Prefix}-public-sg
VpcId: {'Fn::ImportValue': 'main-vpc-id'}
PublicSecurityGroupLinux:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupName: public-sg-Linux
GroupDescription: "SecurityGroup for Public EC2 Windows"
SecurityGroupIngress:
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: !Sub ${Prefix}-public-sg
VpcId: {'Fn::ImportValue': 'main-vpc-id'}
Outputs:
PublicSecurityGroupWin:
Value: !Ref PublicSecurityGroupWin
Export:
Name: !Sub 'PublicSecurityGroupWin-id'
PublicSecurityGroupLinux:
Value: !Ref PublicSecurityGroupLinux
Export:
Name: !Sub 'PublicSecurityGroupLinux-id'
#########################################################
# 分割
#########################################################
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
Ec2KeyName:
Type: 'AWS::EC2::KeyPair::KeyName'
WindowsLatestAmi:
Type : AWS::SSM::Parameter::Value<String>
Description: 'Select Windows Server 2016 or 2019'
InstanceType:
Type: String
AllowedValues: ["t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large", "t2.xlarge", "t2.2xlarge"]
Default: "t2.micro"
Description: 'Select InstanceType'
Prefix:
Type: String
Description: "A prefix that does not conflict with other instances when multiple instances are launched"
PrivateIpAddress:
Type: String
Description: PrivateIpAddress x.x.x.x
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x
MinLength: 9
MaxLength: 18
Default: 10.0.1.10
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})
Hostname:
Type: String
Description: "Input Hostname"
Resources:
EC2Win:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: !Ref WindowsLatestAmi
InstanceType: !Ref InstanceType
KeyName: !Ref Ec2KeyName
SubnetId: !ImportValue public-subnet-id
PrivateIpAddress: !Ref PrivateIpAddress
SecurityGroupIds: [ !ImportValue PublicSecurityGroupWin-id ]
UserData:
# disabled IEenhanced security
$AdminPath = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
$UserPath = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
$AdminPath, $UserPath | % { Set-ItemProperty -Path $_ -Name "IsInstalled" -Value 0 }
tzutil /s "Tokyo Standard Time"
Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\TimeZoneInformation" -Name "RealTimeIsUniversal" -Value 1
Get-NetFirewallProfile | Set-NetFirewallProfile -Enabled false
# show fileext and hidden file
# set high performance
powercfg.exe -SETACTIVE 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
# Set Hostname
!Ref Rename-Computer -NewName ${Hostname} -Force
Tags:
- Key: 'Name'
Value: !Sub ${Prefix}-EC2Win
#########################################################
# 分割
#########################################################
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
Prefix:
Type: String
Description: "A prefix that does not conflict with other instances when multiple instances are launched"
Parameters:
Ec2KeyName:
Type: 'AWS::EC2::KeyPair::KeyName'
Description: 'Select KeyPair'
LinuxLatestAmi:
Type: AWS::SSM::Parameter::Value<String>
InstanceType:
Type: String
AllowedValues: ["t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large", "t2.xlarge", "t2.2xlarge"]
Default: "t2.micro"
Description: 'Select InstanceType'
Prefix:
Type: String
Description: "A prefix that does not conflict with other instances when multiple instances are launched"
PrivateIpAddress:
Type: String
Description: PrivateIpAddress x.x.x.x
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x
MinLength: 9
MaxLength: 18
Default: 10.0.1.30
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})
Resources:
EC2Linux:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: !Ref LinuxLatestAmi
InstanceType: !Ref InstanceType
KeyName: !Ref Ec2KeyName
SubnetId: !ImportValue public-subnet-id
PrivateIpAddress: !Ref PrivateIpAddress
SecurityGroupIds: [ !ImportValue PublicSecurityGroupLinux-id ]
sudo su -
Tags:
- Key: 'Name'
Value: !Sub ${Prefix}-EC2Linux