Skip to content

Instantly share code, notes, and snippets.

@NitriKx
Created April 14, 2022 06:58
Show Gist options
  • Save NitriKx/1df4f41428600e352c09d10afaafe5f5 to your computer and use it in GitHub Desktop.
Save NitriKx/1df4f41428600e352c09d10afaafe5f5 to your computer and use it in GitHub Desktop.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Croit training VM'
Parameters:
EnvironmentName:
Description: A name that will be used in the resource creation
Type: String
AllowedPattern: "[a-zA-Z0-9]+"
InstanceType:
Description: EC2 instance type
Type: String
Default: c5.4xlarge
ConstraintDescription: must be a valid EC2 instance type.
DiskSizeGB:
Description: The size of the disk in GB
Type : String
Default: "256"
Mappings:
RegionAMIMap:
af-south-1:
"HVM64": "ami-052422a872a404e56"
ap-east-1:
"HVM64": "ami-01a72351d91a31652"
ap-northeast-1:
"HVM64": "ami-07cbbfc98b4837f1f"
ap-northeast-2:
"HVM64": "ami-00fb606f624c5e34e"
ap-northeast-3:
"HVM64": "ami-017cb8d705f20a549"
ap-south-1:
"HVM64": "ami-08c018b3176451fb6"
ap-southeast-1:
"HVM64": "ami-0345588a93bd78615"
ap-southeast-2:
"HVM64": "ami-0ba04a630b0abac78"
ca-central-1:
"HVM64": "ami-0f1b797ff8bc78861"
eu-central-1:
"HVM64": "ami-0a17cb6473d536f3e"
eu-north-1:
"HVM64": "ami-0a2f51971aaecdf81"
eu-south-1:
"HVM64": "ami-0ed938532e8eb64ea"
eu-west-1:
"HVM64": "ami-09a61774c03cb2ab9"
eu-west-2:
"HVM64": "ami-0decad0f65cdcf8b8"
eu-west-3:
"HVM64": "ami-0b2d179c86b594f2e"
me-south-1:
"HVM64": "ami-059c996f7aa671c98"
sa-east-1:
"HVM64": "ami-0807b047645b687eb"
us-east-1:
"HVM64": "ami-06a80441f25333895"
us-east-2:
"HVM64": "ami-07bd2cb8846a6ded1"
us-west-1:
"HVM64": "ami-059861fd104fd7f27"
us-west-2:
"HVM64": "ami-012c545587af64585"
Resources:
EC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType:
Ref: InstanceType
ImageId:
Ref: !FindInMap [RegionAMIMap, !Ref "AWS::Region", HVM64]
Tags:
- Key: Name
Value: !Sub "ceph-training-${EnvironmentName}"
- Key: ToBeDeletedAfter
Value: EndOfCephTraining
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- Ref: "InstanceSecurityGroup"
SubnetId:
Ref: "PublicSubnet"
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeType: gp3
VolumeSize: !Ref DiskSizeGB
DeleteOnTermination: 'false'
Encrypted: 'true'
UserData:
Fn::Base64: !Sub |
#!/bin/bash
sudo echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDjCXY/OFV+OSA6UkTbkxbeyg7ibTG3zFeRY8tn5XWh1 antreich@desktop' >> /home/admin/.ssh/authorized_keys
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}
CreationPolicy:
ResourceSignal:
Count: 1
Timeout: "PT10M"
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Sub "ceph-training-instance-security-group-${EnvironmentName}"
GroupDescription: "Security group for Ceph training"
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 192.168.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Ref EnvironmentName
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Ref EnvironmentName
InternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
CidrBlock: !Ref PublicSubnetCIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub ${EnvironmentName} Public Subnet
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub ${EnvironmentName} Public Routes
DefaultPublicRoute:
Type: AWS::EC2::Route
DependsOn: InternetGatewayAttachment
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment