-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload-image
executable file
·38 lines (29 loc) · 1.63 KB
/
upload-image
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# Create Bucket to hold vmdk
aws s3api create-bucket --acl private --bucket rhcos-image --region $AWS_REGION --create-bucket-configuration LocationConstraint=$AWS_REGION
aws s3 cp rhcos*.vmdk s3://rhcos-image
aws iam create-role --role-name vmimport --assume-role-policy-document "file://templates/vmimport-role.json"
aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document "file://templates/vmimport-policy.json"
IMAGENAME=$(ls rhcos*)
aws ec2 import-snapshot --region $AWS_REGION --description "Red Hat CoreOS 4 AWS VMDK" --disk-container "Format="VMDK",UserBucket={S3Bucket="rhcos-image",S3Key="$IMAGENAME"}"
aws ec2 describe-import-snapshot-tasks
until [ $IMPORTSTATUS == 'completed' ]; do
echo $(aws ec2 describe-import-snapshot-tasks | jq '.ImportSnapshotTasks[] .SnapshotTaskDetail.Status' -r)
IMPORTSTATUS=$(aws ec2 describe-import-snapshot-tasks | jq '.ImportSnapshotTasks[] .SnapshotTaskDetail.Status' -r)
sleep 5
done
SNAPSHOT_ID=$(aws ec2 describe-import-snapshot-tasks | jq '.ImportSnapshotTasks[] .SnapshotTaskDetail.SnapshotId' -r)
aws ec2 register-image \
--region $AWS_REGION \
--architecture x86_64 \
--description "RHCOS 4" \
--ena-support \
--name "RHCOS 4" \
--virtualization-type hvm \
--root-device-name '/dev/sda1' \
--block-device-mappings "DeviceName=/dev/sda1,Ebs={DeleteOnTermination=true,SnapshotId=$SNAPSHOT_ID}"
# Get your final Image ID
echo -e "\033[1;36mYour Image ID is:" $(aws ec2 describe-images --region us-gov-west-1 --owners $(aws sts get-caller-identity | jq '.Account' -r) | jq '.Images[] .ImageId' -r)
# {
# "ImageId": "ami-f86c5299"
# }