-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmetabase-rancheros.tf
250 lines (210 loc) · 7.06 KB
/
metabase-rancheros.tf
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
### 概要
#
# データベースアプライアンス(PostgreSQL)とRancherOSでMetabase実行環境を構築するテンプレート
#
# このテンプレートはRancherOS上のDockerでMetabaseを実行する構成となっています。
# Metabaseのバックエンドとしてデータベースアプライアンス(PostgreSQL)を利用します。
#
# ※このテンプレートは石狩第2ゾーン/東京第1ゾーンでのみご利用いただけます。
#
# <事前準備>
#
# - さくらのクラウド上にSSH用の公開鍵を登録しておきます。
# 参考: https://manual.sakura.ad.jp/cloud/controlpanel/settings/public-key.html#id5
#
# <構築手順>
#
# 1) tffile編集画面の"変数定義"タブにて以下の値を編集します。
# - サーバ管理者のパスワード(server_password)
# - データベース接続ユーザーのパスワード(database_password)
# - さくらのクラウドに登録済みの公開鍵の名称(ssh_public_key_name)
# 2) リソースマネージャー画面にて"計画/反映"を実行
#
# <動作確認>
#
# ブラウザから以下のURLにアクセスするとMetabaseの画面が開きます。
# http://<作成したサーバーのグローバルIPアドレス>/
#
# <サーバへのSSH接続>
#
# サーバへのSSH接続は、指定した公開鍵による公開鍵認証のみ許可されるようになっています。
# デバッグなどでSSH接続を行う際は秘密鍵を指定して接続してください。
#
# > usacloudでのSSH接続例
# $ usacloud server ssh -i <your-private-key-file> <your-server-name>
#
# SSH接続後はdocker logsコマンドなどでMetabaseコンテナのログを確認可能です。
#
### 変数定義
locals {
#*********************************************
# パスワード/公開鍵関連(要変更)
#*********************************************
# サーバ管理者のパスワード
server_password = "<put-your-password-here>"
# データベース接続ユーザーのパスワード
database_password = "<put-your-password-here>"
# さくらのクラウドに登録済みの公開鍵の名称
ssh_public_key_name = "<put-your-public-key-name>"
#*********************************************
# サーバ/ディスク
#*********************************************
# サーバ名
server_name = "metabase"
# サーバホスト名
host_name = local.server_name
# サーバ コア数
server_core = 2
# サーバ メモリサイズ(GB)
server_memory = 4
# ディスクサイズ
disk_size = 20
#*********************************************
# ネットワーク(スイッチ/パケットフィルタ)
#*********************************************
# スイッチ名
switch_name = "metabase-internal"
# パケットフィルタ名
packet_filter_name = "metabase-filter"
#*********************************************
# データベースアプライアンス
#*********************************************
# データベースアプライアンス名
database_name = "metabase-db"
# プラン
database_plan = "30g" # 10g/30g/90g/240g
# 接続ユーザー名
database_user_name = "metabase"
# バックアップ時刻
database_backup_time = "01:00"
# バックアップ取得曜日
database_backup_weekdays = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
}
### サーバ/ディスク
# パブリックアーカイブ(OS)のID参照用のデータソース(RancherOS)
data "sakuracloud_archive" "rancheros" {
os_type = "rancheros"
}
# 公開鍵のID参照用のデータソース
data "sakuracloud_ssh_key" "ssh_public_key" {
# TF-UPGRADE-TODO: In Terraform v0.10 and earlier, it was sometimes necessary to
# force an interpolation expression to be interpreted as a list by wrapping it
# in an extra set of list brackets. That form was supported for compatibilty in
# v0.11, but is no longer supported in Terraform v0.12.
#
# If the expression in the following list itself returns a list, remove the
# brackets to avoid interpretation as a list of lists. If the expression
# returns a single list item then leave it as-is and remove this TODO comment.
name_selectors = [local.ssh_public_key_name]
}
# ディスク
resource "sakuracloud_disk" "disk" {
name = local.server_name
source_archive_id = data.sakuracloud_archive.rancheros.id
lifecycle {
ignore_changes = [source_archive_id]
}
}
# サーバ
resource "sakuracloud_server" "server" {
name = local.server_name
disks = [sakuracloud_disk.disk.id]
core = local.server_core
memory = local.server_memory
packet_filter_ids = [sakuracloud_packet_filter.filter.id]
additional_nics = [sakuracloud_switch.sw.id]
hostname = local.host_name
password = local.server_password
note_ids = [sakuracloud_note.provisioning.id]
ssh_key_ids = [data.sakuracloud_ssh_key.ssh_public_key.id]
disable_pw_auth = true
}
# スタートアップスクリプト(IP設定、metabaseコンテナ起動)
resource "sakuracloud_note" "provisioning" {
name = "provisioning-metabase"
class = "yaml_cloud_config"
content = <<EOF
#cloud-config
rancher:
console: default
docker:
engine: docker-17.09.1-ce
network:
interfaces:
eth1:
address: 192.168.100.10/28
dhcp: false
services:
metabase:
image: metabase/metabase:latest
ports:
- "80:3000"
environment:
MB_DB_TYPE: postgres
MB_DB_DBNAME: ${local.database_user_name}
MB_DB_PORT: 5432
MB_DB_USER: ${local.database_user_name}
MB_DB_PASS: ${local.database_password}
MB_DB_HOST: 192.168.100.2
restart: always
EOF
}
### データベースアプライアンス
resource "sakuracloud_database" "db" {
name = local.database_name
database_type = "postgresql"
plan = local.database_plan
user_name = local.database_user_name
user_password = local.database_password
allow_networks = ["192.168.100.0/28"]
port = 5432
backup_time = local.database_backup_time
backup_weekdays = local.database_backup_weekdays
switch_id = sakuracloud_switch.sw.id
ipaddress1 = "192.168.100.2"
nw_mask_len = 28
default_route = "192.168.100.1"
}
### パケットフィルタ
resource "sakuracloud_packet_filter" "filter" {
name = local.packet_filter_name
expressions {
protocol = "tcp"
dest_port = "22"
description = "Allow external:SSH"
}
expressions {
protocol = "tcp"
dest_port = "80"
description = "Allow external:HTTP"
}
expressions {
protocol = "icmp"
}
expressions {
protocol = "fragment"
}
expressions {
protocol = "udp"
source_port = "123"
}
expressions {
protocol = "tcp"
dest_port = "32768-61000"
description = "Allow from server"
}
expressions {
protocol = "udp"
dest_port = "32768-61000"
description = "Allow from server"
}
expressions {
protocol = "ip"
allow = false
description = "Deny ALL"
}
}
### スイッチ
resource "sakuracloud_switch" "sw" {
name = local.switch_name
}