101 lines
2.8 KiB
YAML
101 lines
2.8 KiB
YAML
---
|
|
AWSTemplateFormatVersion: 2010-09-09
|
|
Description: EC2 / LaunchTemplate
|
|
|
|
Parameters:
|
|
|
|
Environment:
|
|
Type: String
|
|
InstanceSubnetId:
|
|
Type: AWS::EC2::Subnet::Id
|
|
InstanceType:
|
|
Type: String
|
|
AmiId:
|
|
Type: AWS::EC2::Image::Id
|
|
KeyName:
|
|
Type: String
|
|
InstanceProfileArn:
|
|
Type: String
|
|
ToolsSg:
|
|
Type: String
|
|
|
|
|
|
Resources:
|
|
|
|
ToolsEc2:
|
|
Type: AWS::EC2::Instance
|
|
Properties:
|
|
LaunchTemplate:
|
|
LaunchTemplateId: !Ref ToolsEc2LaunchTemplate
|
|
Version: !GetAtt ToolsEc2LaunchTemplate.LatestVersionNumber
|
|
|
|
EbsVolumeA:
|
|
Type: AWS::EC2::Volume
|
|
Properties:
|
|
AvailabilityZone: !GetAtt ToolsEc2.AvailabilityZone # Specify the same availability zone as the EC2 instance
|
|
Size: 100 # Specify the desired size of the volume
|
|
VolumeType: gp3 # Specify the volume type
|
|
Encrypted: true # Specify whether the volume is encrypted or not
|
|
|
|
|
|
VolumeAttachment:
|
|
Type: AWS::EC2::VolumeAttachment
|
|
Properties:
|
|
Device: /dev/xvdf # Specify the device name to attach the volume to on the EC2 instance
|
|
InstanceId: !Ref ToolsEc2 # Reference the existing EC2 instance
|
|
VolumeId: !Ref EbsVolumeA # Reference the newly created EBS volume
|
|
|
|
|
|
ToolsEc2LaunchTemplate:
|
|
Type: AWS::EC2::LaunchTemplate
|
|
Properties:
|
|
LaunchTemplateName: AppsLaunchTemplate
|
|
LaunchTemplateData:
|
|
IamInstanceProfile:
|
|
Arn: !Ref InstanceProfileArn
|
|
DisableApiTermination: true
|
|
ImageId: !Ref AmiId
|
|
InstanceType: !Ref InstanceType
|
|
KeyName: !Ref KeyName
|
|
NetworkInterfaces:
|
|
- AssociatePublicIpAddress: false
|
|
DeviceIndex: 0
|
|
Groups:
|
|
- !Ref ToolsSg
|
|
SubnetId: !Ref InstanceSubnetId
|
|
TagSpecifications:
|
|
- ResourceType: instance
|
|
Tags:
|
|
- Key: "Name"
|
|
Value: apps
|
|
UserData:
|
|
Fn::Base64: !Sub |
|
|
# Run Ubuntu updates & install dependencies
|
|
apt update
|
|
apt upgrade -y
|
|
apt install unzip bzip2 podman postgresql-client jq
|
|
|
|
# Install AWS CLI V2
|
|
curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
|
|
unzip awscliv2.zip
|
|
./aws/install
|
|
|
|
# Install Docker
|
|
curl -fsSL https://get.docker.com | sh
|
|
usermod -aG docker ubuntu
|
|
usermod -aG docker ssm-user
|
|
|
|
mkfs -t xfs /dev//nvme1n1 # Format the volume
|
|
mount /dev/nvme1n1 /opt # Mount the volume to /data
|
|
echo "/dev/nvme1n1 /opt xfs defaults,nofail 0 2" >> /etc/fstab # Add entry to /etc/fstab for automatic mount
|
|
|
|
|
|
InstanceEIP:
|
|
Type: "AWS::EC2::EIP"
|
|
Properties:
|
|
InstanceId: !Ref ToolsEc2
|
|
|
|
|
|
Outputs: {}
|
|
...
|