-
Notifications
You must be signed in to change notification settings - Fork 12
feat(containers): add metabase with VPC example #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Metabase on VPC | ||
|
||
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. | ||
|
||
## Prerequisites | ||
|
||
- A Scaleway account | ||
- [Terraform](https://www.terraform.io/downloads.html) installed | ||
|
||
## Setup | ||
|
||
Deploy the PostgreSQL database and private network: | ||
|
||
```bash | ||
cd containers/vpc-metabase | ||
terraform init | ||
terraform apply | ||
``` | ||
|
||
After, the deployment, you can find the Metabase URL in the output: | ||
|
||
```bash | ||
terraform output metabase_container_url | ||
``` | ||
|
||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
locals { | ||
name = "metabase-example" | ||
db_postgres_version = "16" | ||
base_tags = ["metabase", "vpc"] | ||
} | ||
|
||
resource "scaleway_vpc" "main" { | ||
name = local.name | ||
} | ||
|
||
resource "scaleway_vpc_private_network" "main" { | ||
name = local.name | ||
vpc_id = scaleway_vpc.main.id | ||
} | ||
|
||
resource "scaleway_rdb_instance" "main" { | ||
name = "db-${local.name}" | ||
tags = concat(local.base_tags, ["pg-${local.db_postgres_version}"]) | ||
|
||
node_type = "db-play2-nano" | ||
|
||
is_ha_cluster = false | ||
private_network { | ||
pn_id = scaleway_vpc_private_network.main.id | ||
enable_ipam = true | ||
} | ||
|
||
encryption_at_rest = true | ||
volume_size_in_gb = 10 | ||
volume_type = "sbs_5k" | ||
|
||
engine = "PostgreSQL-${local.db_postgres_version}" | ||
|
||
user_name = var.db_admin_username | ||
password = var.db_admin_password | ||
} | ||
|
||
resource "scaleway_rdb_database" "main" { | ||
instance_id = scaleway_rdb_instance.main.id | ||
name = local.name | ||
} | ||
|
||
resource "scaleway_rdb_user" "main" { | ||
instance_id = scaleway_rdb_instance.main.id | ||
|
||
name = var.db_username | ||
password = var.db_password | ||
} | ||
|
||
resource "scaleway_rdb_privilege" "main" { | ||
instance_id = scaleway_rdb_instance.main.id | ||
user_name = scaleway_rdb_user.main.name | ||
database_name = scaleway_rdb_database.main.name | ||
permission = "all" | ||
} | ||
|
||
resource "scaleway_container_namespace" "main" { | ||
name = local.name | ||
description = "Namespace for the Metabase container" | ||
tags = local.base_tags | ||
|
||
activate_vpc_integration = true | ||
} | ||
|
||
locals { | ||
db_endpoint = scaleway_rdb_instance.main.private_network[0] | ||
rdb_instance_id = split("/", scaleway_rdb_instance.main.id)[1] # To remove the `<region>/` prefix | ||
} | ||
|
||
resource "scaleway_container" "main" { | ||
name = local.name | ||
description = "Metabase container running in VPC" | ||
tags = local.base_tags | ||
|
||
namespace_id = scaleway_container_namespace.main.id | ||
registry_image = "metabase/metabase:v0.55.x" | ||
cyclimse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private_network_id = scaleway_vpc_private_network.main.id | ||
|
||
cpu_limit = 4000 | ||
memory_limit = 4000 | ||
sandbox = "v1" | ||
|
||
http_option = "redirected" # Only allow HTTPs traffic | ||
port = 3000 | ||
|
||
max_scale = 1 # No real need to have more than one instance running | ||
deploy = true | ||
|
||
environment_variables = { | ||
MB_ANON_TRACKING_ENABLED : "false" | ||
MB_CHECK_FOR_UPDATES : "false" | ||
|
||
MB_JETTY_HOST : "0.0.0.0" | ||
|
||
MB_DB_TYPE : "postgres" | ||
MB_DB_CONNECTION_TIMEOUT_MS : "2000" # Down from 10s for faster feedback loop | ||
|
||
# Within a private network, we can refer to resources using their internal hostname | ||
# The format is `<resource_id>.<private_network_name>.internal` or `<resource_name>.<private_network_name>.internal` | ||
MB_DB_HOST : "${local.rdb_instance_id}.${scaleway_vpc_private_network.main.name}.internal" | ||
MB_DB_PORT : local.db_endpoint.port | ||
|
||
MB_DB_DBNAME : scaleway_rdb_database.main.name | ||
MB_DB_USER : scaleway_rdb_user.main.name # Referencing the user directly to create a Terraform dependency | ||
} | ||
|
||
secret_environment_variables = { | ||
MB_DB_PASS : var.db_password | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "metabase_container_url" { | ||
description = "The URL to connect to Metabase" | ||
value = "https://${scaleway_container.main.domain_name}" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
terraform { | ||
required_providers { | ||
scaleway = { | ||
source = "scaleway/scaleway" | ||
version = "~> 2.57" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
variable "db_admin_username" { | ||
type = string | ||
default = "admin" | ||
} | ||
|
||
variable "db_admin_password" { | ||
type = string | ||
sensitive = true | ||
description = "The password for the database administrator. This value is sensitive and should be kept secure." | ||
} | ||
|
||
variable "db_username" { | ||
type = string | ||
default = "metabase" | ||
} | ||
|
||
variable "db_password" { | ||
type = string | ||
sensitive = true | ||
description = "The password for the Metabase database user." | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.