最近、GCPで環境を作ることになったのだけどCloud Deployment Managerが中々便利。IaCはすばらです。
ただ、構成図をいちいち描くのがめんどくさい。今の所draw.ioやパワポで描いてるのだけど実設定との整合性を取らなくなるのは火を見るより明らか。サボる自信がある。
なので、Cloud Deployment Managerをビジュアルに表示するツールくらい当然あるだろうと探してみたのだけど意外と無い。AWSだとCloudMapperってのがあるみたいだけどGCPは対応してなさそう。
と言うわけで仕方無いから作ってみようかと思い立ったので、まずは手始めにGraphvizでGCPの構成図を描いてみました。
元のdotファイルはこんな感じ。
digraph G {
layout=dot;
labeljust=l;
color=white;
internet [
label=<<table border="0"><tr><td fixedsize="true" width="32" height="32"><img src="gcp/internet.png" /></td><td>Internet</td></tr></table>>,
shape=record, color=black, style = "filled", fillcolor=white
];
subgraph cluster_gcp {
label=<<table border="0"><tr><td fixedsize="true" width="32" height="32"><img src="gcp/Extras/Google Cloud Platform.png" /></td><td>Google Cloud</td></tr></table>>;
bgcolor=lightgrey;
subgraph cluster_vpc1 {
label=<<table border="0"><tr><td fixedsize="true" width="32" height="32"><img src="gcp/Networking/Virtual Private Cloud.png" /></td><td>Virtual Private Cloud</td></tr></table>>;
bgcolor="#e1f6fe";
subgraph cluster_region1 {
label="Region 1";
bgcolor="#e2ffec";
internet_gw [
label=<<table border="0"><tr><td fixedsize="true" width="32" height="32"><img src="gcp/Networking/Cloud Load Balancing.png" /></td><td>Internet Gateway</td></tr></table>>,
shape=record,
color=black,
style = "filled",
fillcolor=white
];
subgraph cluster_zonea {
label="Zone a";
style="dashed"
color=green;
subgraph cluster_subnet1 {
label="subnet: 10.0.0.0/24";
bgcolor="#ede7f7";
style="solid";
color=white;
compute1 [
label=<<table border="0"><tr><td fixedsize="true" width="32" height="32"><img src="gcp/Compute/Compute Engine.png" /></td><td>10.0.0.1</td></tr></table>>,
shape=record,
color=black,
style = "filled",
fillcolor=white
];
compute2 [
label=<<table border="0"><tr><td fixedsize="true" width="32" height="32"><img src="gcp/Compute/Compute Engine.png" /></td><td>10.0.0.2</td></tr></table>>,
shape=record,
color=black,
style = "filled",
fillcolor=white
];
}
}
}
}
}
internet -> internet_gw;
internet_gw -> compute1;
internet_gw -> compute2;
}
改善するところは多そうだけど、とりあえずそれっぽく描けた感じですね。Graphviz便利ですね。
まとめ
割とGCPの構成図っぽいものが簡単に描けました。
あとは、肝心のCloud Deployment Managerとの連携なんだけど、Deployment Managerのスクリプトを解析するのはちょっと大変そうだから、JSONかYAMLでサブセット言語を作ってそこからDOTファイルとDeployment ManagerのYAMLを作るのがとりあえず良いかも。
それではHappy Hacking!