chore: add current provisioning state before migration
This commit is contained in:
parent
a9703b4748
commit
50745b0f22
660 changed files with 88126 additions and 0 deletions
9
providers/aws/bin/create-default-subnet.sh
Executable file
9
providers/aws/bin/create-default-subnet.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
[ -z "$AWS_PROFILE" ] || [ ! -r "$HOME/.aws/credentials" ] && echo "AWS credentials not found" && exit 1
|
||||
|
||||
[ -z "$1" ] && echo "No zone provided (example eu-west-1)" && exit 1
|
||||
|
||||
aws ec2 create-default-subnet --availability-zone ${1}a
|
||||
aws ec2 create-default-subnet --availability-zone ${1}b
|
||||
aws ec2 create-default-subnet --availability-zone ${1}c
|
||||
4
providers/aws/bin/get-image.sh
Executable file
4
providers/aws/bin/get-image.sh
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
match="debian-12-amd64"
|
||||
aws ec2 describe-images --owners --out json | jq '.Images[] | select( .Name | contains("'$match'")) '
|
||||
125
providers/aws/bin/install.sh
Executable file
125
providers/aws/bin/install.sh
Executable file
|
|
@ -0,0 +1,125 @@
|
|||
#!/bin/bash
|
||||
# Info: Script to install aws tools
|
||||
# Author: JesusPerezLorenzo
|
||||
# Release: 1.0
|
||||
# Date: 15-04-2024
|
||||
|
||||
[ "$DEBUG" == "-x" ] && set -x
|
||||
|
||||
USAGE="install-tools [ tool-name: tera k9s, etc | all] [--update]
|
||||
As alternative use environment var TOOL_TO_INSTALL with a list-of-tools (separeted with spaces)
|
||||
Versions are set in ./versions file
|
||||
|
||||
This can be called by directly with an argumet or from an other srcipt
|
||||
"
|
||||
|
||||
ORG=$(pwd)
|
||||
function _info_tools {
|
||||
local match=$1
|
||||
local info_keys
|
||||
info_keys="info version site"
|
||||
|
||||
if [ -z "$match" ] || [ "$match" == "all" ] || [ "$match" == "-" ]; then
|
||||
match="all"
|
||||
fi
|
||||
echo "$PROVIDER_TITLE"
|
||||
[ ! -r "$PROVIDERS_PATH/$PROVIDER_NAME/provisioning.yaml" ] && return
|
||||
echo "-------------------------------------------------------"
|
||||
case "$match" in
|
||||
"i" | "?" | "info")
|
||||
for key in $info_keys
|
||||
do
|
||||
echo -n "$key:"
|
||||
[ "$key" != "version" ] && echo -ne "\t"
|
||||
echo " $(grep "^$key:" "$PROVIDERS_PATH/$PROVIDER_NAME/provisioning.yaml" | sed "s/$key: //g")"
|
||||
done
|
||||
;;
|
||||
"all")
|
||||
cat "$PROVIDERS_PATH/$PROVIDER_NAME/provisioning.yaml"
|
||||
;;
|
||||
*)
|
||||
echo -e "$match:\t $(grep "^$match:" "$PROVIDERS_PATH/$PROVIDER_NAME/provisioning.yaml" | sed "s/$match: //g")"
|
||||
esac
|
||||
echo "________________________________________________________"
|
||||
}
|
||||
function _install_tools {
|
||||
local match=$1
|
||||
shift
|
||||
local options
|
||||
options="$*"
|
||||
local has_aws
|
||||
local aws_version
|
||||
|
||||
OS="$(uname | tr '[:upper:]' '[:lower:]')"
|
||||
ORG_OS=$(uname)
|
||||
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')"
|
||||
ORG_ARCH="$(uname -m)"
|
||||
|
||||
AWS_VERSION=${AWS_AWS_VERSION:-}
|
||||
if [ -n "$AWS_VERSION" ] && [ "$match" == "all" ] || [ "$match" == "aws" ] ; then
|
||||
[ -r "/usr/bin/aws" ] && mv /usr/bin/aws /usr/bin/_aws
|
||||
has_aws=$(type -P aws)
|
||||
num_version=0
|
||||
[ -n "$has_aws" ] && aws_version=$(aws --version | cut -f1 -d" " | sed 's,aws-cli/,,g') && num_version=${aws_version//\./}
|
||||
[ -z "$num_version" ] && num_version=0
|
||||
expected_version_num=${AWS_VERSION//\./}
|
||||
if [ -z "$CHECK_ONLY" ] && [ "$num_version" -ne "$expected_version_num" ] ; then
|
||||
cd "$ORG" || exit 1
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-${OS}-${ORG_ARCH}.zip" -o "/tmp/awscliv2.zip"
|
||||
cd /tmp
|
||||
unzip awscliv2.zip >/dev/null
|
||||
[ "$1" != "-update" ] && [ -d "/usr/local/aws-cli" ] && sudo rm -rf "/usr/local/aws-cli"
|
||||
sudo ./aws/install && printf "%s\t%s\n" "aws" "installed $AWS_VERSION"
|
||||
#sudo ./aws/install $options && echo "aws cli installed"
|
||||
cd "$ORG" && rm -rf /tmp/awscliv2.zip /tmp/aws
|
||||
elif [ -n "$CHECK_ONLY" ] ; then
|
||||
printf "%s\t%s\t%s\n" "aws" "$aws_version" "expected $AWS_VERSION"
|
||||
else
|
||||
printf "%s\t%s\n" "aws" "already $AWS_VERSION"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
function _on_tools {
|
||||
local tools_list=$1
|
||||
[ -z "$tools_list" ] || [[ "$tools_list" == -* ]] && tools_list=${TOOL_TO_INSTALL:-all}
|
||||
case $tools_list in
|
||||
"all")
|
||||
_install_tools "all" "$@"
|
||||
;;
|
||||
"info" | "i" | "?")
|
||||
shift
|
||||
_info_tools "$@"
|
||||
;;
|
||||
*)
|
||||
for tool in $tools_list
|
||||
do
|
||||
[[ "$tool" == -* ]] && continue
|
||||
_install_tools "$tool" "${*//$tool/}"
|
||||
done
|
||||
esac
|
||||
}
|
||||
|
||||
set -o allexport
|
||||
## shellcheck disable=SC1090
|
||||
[ -n "$PROVISIONING_ENV" ] && [ -r "$PROVISIONING_ENV" ] && source "$PROVISIONING_ENV"
|
||||
[ -r "../env-provisioning" ] && source ../env-provisioning
|
||||
[ -r "env-provisioning" ] && source ./env-provisioning
|
||||
set +o allexport
|
||||
|
||||
export PROVISIONING=${PROVISIONING:-/usr/local/provisioning}
|
||||
|
||||
PROVIDERS_PATH=${PROVIDERS_PATH:-"$PROVISIONING/providers"}
|
||||
|
||||
PROVIDER_NAME="aws"
|
||||
PROVIDER_TITLE="AWS"
|
||||
|
||||
if [ -r "$(dirname "$0")/../versions" ] ; then
|
||||
. "$(dirname "$0")"/../versions
|
||||
elif [ -r "$(dirname "$0")/versions" ] ; then
|
||||
. "$(dirname "$0")"/versions
|
||||
fi
|
||||
|
||||
[ "$1" == "-h" ] && echo "$USAGE" && shift
|
||||
[ "$1" == "check" ] && CHECK_ONLY="yes" && shift
|
||||
[ -n "$1" ] && cd /tmp && _on_tools "$@"
|
||||
[ -z "$1" ] && _on_tools
|
||||
31
providers/aws/bin/on-ssh.sh
Executable file
31
providers/aws/bin/on-ssh.sh
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
USAGE="on-ssh.sh show|describe | create (key-name) | import (pub-key-path) | delete (key-name)
|
||||
reference: https://docs.aws.amazon.com/cli/latest/reference/ec2/import-key-pair.html
|
||||
"
|
||||
[ -z "$AWS_PROFILE" ] || [ ! -r "$HOME/.aws/credentials" ] && echo "AWS credentials not found" && exit 1
|
||||
|
||||
case "$1" in
|
||||
show|describe)
|
||||
aws ec2 describe-key-pairs
|
||||
;;
|
||||
create)
|
||||
[ -z "$2" ] && echo "No name to create ssh found" && exit 1
|
||||
aws ec2 create-key-pair \
|
||||
--key-name "$2" \
|
||||
--key-type ed25519 \
|
||||
--query 'KeyMaterial' --output text
|
||||
;;
|
||||
import)
|
||||
[ -z "$2" ] && echo "No name to reate ssh found" && exit 1
|
||||
[ ! -r "$HOME/.ssh/$2" ] && echo "No public key found in $HOME/.ssh/$2" && exit 1
|
||||
--out json | jq -r '.InstanceStatuses[] | select(.InstanceState.Name == "running")aws ec2 import-key-pair --key-name "$2" --public-key-material fileb://~/.ssh/$2
|
||||
;;
|
||||
delete)
|
||||
[ -z "$2" ] && echo "No name for create ssh found" && exit 1
|
||||
aws ec2 delete-key-pair --key-name "$2"
|
||||
;;
|
||||
-h|help) echo "$USAGE"
|
||||
;;
|
||||
*) echo "Option $1 not defined"
|
||||
;;
|
||||
esac
|
||||
11
providers/aws/bin/public_ip_ec2.sh
Executable file
11
providers/aws/bin/public_ip_ec2.sh
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
[ -z "$AWS_PROFILE" ] || [ ! -r "$HOME/.aws/credentials" ] && echo "AWS credentials not found" && exit 1
|
||||
|
||||
[ -z "$1" ] && echo "No instance id found" && exit 1
|
||||
|
||||
instace_id=$1
|
||||
|
||||
aws ec2 describe-instances --instance-ids $instance_id \
|
||||
--query 'Reservations[*].Instances[*].PublicIpAddress' \
|
||||
--output text
|
||||
Loading…
Add table
Add a link
Reference in a new issue