1 Star 1 Fork 0

WeBank/delivery-by-terraform

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gen_asset_json.sh 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
广意 提交于 2024-11-14 16:32 . add gen asset id shell
#!/bin/bash
TFSTATE=`cat ./terraform.tfstate`
REGION=`echo $TFSTATE | jq -r '.outputs.region.value'`
WECUBE_VPC_ASSET_ID=`echo $TFSTATE | jq -r '.resources | .[] | select(.type == "tencentcloud_vpc") | .instances | .[0].attributes.id // empty'`
WECUBE_SUBNET_ASSET_ID=`echo $TFSTATE | jq -r '.resources | .[] | select(.type == "tencentcloud_subnet") | .instances | .[0].attributes.id // empty'`
WECUBE_SUBNET_2_ASSET_ID=`echo $TFSTATE | jq -r '.resources | .[] | select(.type == "tencentcloud_subnet") | .instances | .[1].attributes.id // empty'`
AZ=`echo $TFSTATE | jq -r '.resources | .[] | select(.type == "tencentcloud_subnet") | .instances | .[0].attributes.availability_zone // empty'`
AZ2=`echo $TFSTATE | jq -r '.resources | .[] | select(.type == "tencentcloud_subnet") | .instances | .[1].attributes.availability_zone // empty'`
WECUBE_ROUTE_TABLE_ASSET_ID=`echo $TFSTATE | jq -r '.resources | .[] | select(.type == "tencentcloud_route_table") | .instances | .[0].attributes.id // empty'`
WECUBE_HOST_ASSET_ID=`echo $TFSTATE | jq -r '.resources | .[] | select(.name == "vm_instances") | .instances | .[0].attributes.id // empty'`
INITIAL_PASSWORD=`echo $TFSTATE | jq -r '.resources | .[] | select(.name == "vm_instances") | .instances | .[0].attributes.password // empty'`
WECUBE_HOST_2_ASSET_ID=`echo $TFSTATE | jq -r '.resources | .[] | select(.name == "vm_instances") | .instances | .[1].attributes.id // empty'`
read -d '' CONTENT_TPL <<-EOF || true
{
"dataCenterRegionAssetId": "${REGION}",
"dataCenterAZ1AssetId": "${AZ}",
"dataCenterAZ2AssetId": "${AZ2}",
"networkZoneAssetId": "${WECUBE_VPC_ASSET_ID}",
"networkSubZone1AssetId": "${WECUBE_SUBNET_ASSET_ID}",
"networkSubZone2AssetId": "${WECUBE_SUBNET_2_ASSET_ID}",
"routeTableAssetId": "${WECUBE_ROUTE_TABLE_ASSET_ID}",
"wecubeHost1AssetId": "${WECUBE_HOST_ASSET_ID}",
"wecubeHost1Password": "${INITIAL_PASSWORD}",
"wecubeHost2AssetId": "${WECUBE_HOST_2_ASSET_ID}",
"wecubeHost2Password": "${INITIAL_PASSWORD}"
}
EOF
echo $CONTENT_TPL > ./wecube_import_asset.json
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/WeBank/delivery-by-terraform.git
[email protected]:WeBank/delivery-by-terraform.git
WeBank
delivery-by-terraform
delivery-by-terraform
master

搜索帮助