Skip to content

Commit 84d2abb

Browse files
cyclimseCopilotthomas-tacquet
authored
feat(containers): add metabase with VPC example (#111)
* feat(containers): add metabase example * Update containers/vpc-metabase/variables.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update containers/vpc-metabase/variables.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: bump postgres version to 16 Co-authored-by: Thomas TACQUET <thomas@tacquet.net> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Thomas TACQUET <thomas@tacquet.net>
1 parent e6d6143 commit 84d2abb

File tree

6 files changed

+171
-0
lines changed

6 files changed

+171
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Table of Contents:
8080
| **[.NET C#](containers/csharp-hello-world)** <br/> A .NET C# Container hello world | C# .NET | [CLI] |
8181
| **[Ruby Hello World](containers/ruby-hello-world/)** <br/> A simple Ruby Hello world Container | Ruby | [CLI] |
8282
| **[Deploy Memos app](containers/memos-terraform/)** <br/> A journaling application with its database deployed with Terraform | Terraform | [Terraform] |
83+
| **[Metabase on VPC](containers/vpc-metabase/README.md)** <br/> A Metabase instance running in a private network with a PostgreSQL database. | N/A | [Terraform] |
8384

8485
### ⚙️ Jobs
8586

containers/vpc-metabase/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Metabase on VPC
2+
3+
This example shows how to deploy a Metabase instance on Serverless Containers that connects to a PostgreSQL database running in a private network. The setup uses Terraform to manage the infrastructure.
4+
5+
## Prerequisites
6+
7+
- A Scaleway account
8+
- [Terraform](https://www.terraform.io/downloads.html) installed
9+
10+
## Setup
11+
12+
Deploy the PostgreSQL database and private network:
13+
14+
```bash
15+
cd containers/vpc-metabase
16+
terraform init
17+
terraform apply
18+
```
19+
20+
After, the deployment, you can find the Metabase URL in the output:
21+
22+
```bash
23+
terraform output metabase_container_url
24+
```
25+
26+
That's it! You can now access your Metabase instance at the provided URL 🎉. Please refer to the official [Metabase documentation](https://www.metabase.com/docs/latest/) for more information.

containers/vpc-metabase/main.tf

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
locals {
2+
name = "metabase-example"
3+
db_postgres_version = "16"
4+
base_tags = ["metabase", "vpc"]
5+
}
6+
7+
resource "scaleway_vpc" "main" {
8+
name = local.name
9+
}
10+
11+
resource "scaleway_vpc_private_network" "main" {
12+
name = local.name
13+
vpc_id = scaleway_vpc.main.id
14+
}
15+
16+
resource "scaleway_rdb_instance" "main" {
17+
name = "db-${local.name}"
18+
tags = concat(local.base_tags, ["pg-${local.db_postgres_version}"])
19+
20+
node_type = "db-play2-nano"
21+
22+
is_ha_cluster = false
23+
private_network {
24+
pn_id = scaleway_vpc_private_network.main.id
25+
enable_ipam = true
26+
}
27+
28+
encryption_at_rest = true
29+
volume_size_in_gb = 10
30+
volume_type = "sbs_5k"
31+
32+
engine = "PostgreSQL-${local.db_postgres_version}"
33+
34+
user_name = var.db_admin_username
35+
password = var.db_admin_password
36+
}
37+
38+
resource "scaleway_rdb_database" "main" {
39+
instance_id = scaleway_rdb_instance.main.id
40+
name = local.name
41+
}
42+
43+
resource "scaleway_rdb_user" "main" {
44+
instance_id = scaleway_rdb_instance.main.id
45+
46+
name = var.db_username
47+
password = var.db_password
48+
}
49+
50+
resource "scaleway_rdb_privilege" "main" {
51+
instance_id = scaleway_rdb_instance.main.id
52+
user_name = scaleway_rdb_user.main.name
53+
database_name = scaleway_rdb_database.main.name
54+
permission = "all"
55+
}
56+
57+
resource "scaleway_container_namespace" "main" {
58+
name = local.name
59+
description = "Namespace for the Metabase container"
60+
tags = local.base_tags
61+
62+
activate_vpc_integration = true
63+
}
64+
65+
locals {
66+
db_endpoint = scaleway_rdb_instance.main.private_network[0]
67+
rdb_instance_id = split("/", scaleway_rdb_instance.main.id)[1] # To remove the `<region>/` prefix
68+
}
69+
70+
resource "scaleway_container" "main" {
71+
name = local.name
72+
description = "Metabase container running in VPC"
73+
tags = local.base_tags
74+
75+
namespace_id = scaleway_container_namespace.main.id
76+
registry_image = "metabase/metabase:v0.55.x"
77+
78+
private_network_id = scaleway_vpc_private_network.main.id
79+
80+
cpu_limit = 4000
81+
memory_limit = 4000
82+
sandbox = "v1"
83+
84+
http_option = "redirected" # Only allow HTTPs traffic
85+
port = 3000
86+
87+
max_scale = 1 # No real need to have more than one instance running
88+
deploy = true
89+
90+
environment_variables = {
91+
MB_ANON_TRACKING_ENABLED : "false"
92+
MB_CHECK_FOR_UPDATES : "false"
93+
94+
MB_JETTY_HOST : "0.0.0.0"
95+
96+
MB_DB_TYPE : "postgres"
97+
MB_DB_CONNECTION_TIMEOUT_MS : "2000" # Down from 10s for faster feedback loop
98+
99+
# Within a private network, we can refer to resources using their internal hostname
100+
# The format is `<resource_id>.<private_network_name>.internal` or `<resource_name>.<private_network_name>.internal`
101+
MB_DB_HOST : "${local.rdb_instance_id}.${scaleway_vpc_private_network.main.name}.internal"
102+
MB_DB_PORT : local.db_endpoint.port
103+
104+
MB_DB_DBNAME : scaleway_rdb_database.main.name
105+
MB_DB_USER : scaleway_rdb_user.main.name # Referencing the user directly to create a Terraform dependency
106+
}
107+
108+
secret_environment_variables = {
109+
MB_DB_PASS : var.db_password
110+
}
111+
}

containers/vpc-metabase/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "metabase_container_url" {
2+
description = "The URL to connect to Metabase"
3+
value = "https://${scaleway_container.main.domain_name}"
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
scaleway = {
4+
source = "scaleway/scaleway"
5+
version = "~> 2.57"
6+
}
7+
}
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
variable "db_admin_username" {
2+
type = string
3+
default = "admin"
4+
}
5+
6+
variable "db_admin_password" {
7+
type = string
8+
sensitive = true
9+
description = "The password for the database administrator. This value is sensitive and should be kept secure."
10+
}
11+
12+
variable "db_username" {
13+
type = string
14+
default = "metabase"
15+
}
16+
17+
variable "db_password" {
18+
type = string
19+
sensitive = true
20+
description = "The password for the Metabase database user."
21+
}

0 commit comments

Comments
 (0)