はじめに
色々サービスの検証をするにあたり、SIMグループを作ったり消したりを繰り返したかったので
その際に利用したコマンドラインです。
あまり需要は無いと思います。。。
前提
以下のインストールが必要です。
環境はmacOSです。
- soracom-cli
- jq
準備
事前に作成するグループの名前を入力したテキストファイルを準備します
作成する SIM グループの名称ファイル
groups.txt
test-group-1
test-group-2
作成する SIM グループのコンフィグレーションファイル
以下は例です。
必要なものに合わせて設定してください。
credentialsId
は事前に設定しています。
test-group-1-config.json,test-group-2-config.json
[
{
"key": "enabled",
"value": true
},
{
"key": "destination",
"value": {
"provider": "aws",
"service": "kinesis",
"resourceUrl": "https://firehose.ap-northeast-1.amazonaws.com/xxxxx"
}
},
{
"key": "credentialsId",
"value": "soracom_test"
},
{
"key": "contentType",
"value": "json"
}
]
SIM グループの一括作成
cat groups.txt | xargs -L 1 -I @ \
soracom groups create \
--body '{ "tags": { "owner": "daisuke-araki", "name": "@", "env": "trial" } }' \
--profile sandbox
SIM グループのコンフィグレーションの一括設定
ここでは、Funnelのコンフィグレーションを行っています。
グループ作成時に行わないのであれば namespace
毎に設定が必要です。
コンフィグレーションをテキストで管理できるのでバージョン管理もできますね。
soracom groups list --profile sandbox | \
jq -r '.[] | select(.tags.env == "trial") | .groupId, .tags.name' | \
xargs -L 2 -n 2 -t \
sh -c 'soracom groups put-config --group-id $0 --namespace SoracomFunnel --body @$1-config.json --profile sandbox'
SIM グループの一括削除
jq
コマンドを利用し env
タグに trial
が設定されたグループを一括削除します。
soracom groups list --profile sandbox | \
jq -r '.[] | select(.tags.env == "trial") | .groupId' | \
xargs -L 1 -I @ soracom groups delete --group-id @ --profile sandbox