project_conquer/aws/templates/ec2/nc.yaml

101 lines
2.6 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
EbsVolumeB:
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/xvdb # Specify the device name to attach the volume to on the EC2 instance
InstanceId: !Ref ToolsEc2 # Reference the existing EC2 instance
VolumeId: !Ref EbsVolumeB # Reference the newly created EBS volume
ToolsEc2LaunchTemplate:
DeletionPolicy: Retain
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: ElkStackLaunchTemplate
LaunchTemplateData:
IamInstanceProfile:
Arn: !Ref InstanceProfileArn
DisableApiTermination: true
ImageId: !Ref AmiId
InstanceType: !Ref InstanceType
KeyName: !Ref KeyName
BlockDeviceMappings:
- DeviceName: "/dev/xvda"
Ebs:
Encrypted: true
VolumeSize: 500
VolumeType: "gp3"
DeleteOnTermination: true
NetworkInterfaces:
- AssociatePublicIpAddress: false
DeviceIndex: 0
Groups:
- !Ref ToolsSg
SubnetId: !Ref InstanceSubnetId
TagSpecifications:
- ResourceType: instance
Tags:
- Key: "Name"
Value: nc
UserData:
Fn::Base64: !Sub |
# Run Ubuntu updates & install dependencies
sudo apt update
sudo apt upgrade -y
sudo 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
sudo ./aws/install
InstanceEIP:
Type: "AWS::EC2::EIP"
Properties:
InstanceId: !Ref ToolsEc2
Outputs: {}
...