-
Notifications
You must be signed in to change notification settings - Fork 12
feat(containers): memos example terraform #106
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 2 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,35 @@ | ||
| # Memos application deployment using Terraform | ||
|
|
||
| [Memos](https://github.com/usememos/memos) is "an open-source, lightweight note-taking solution. The pain-less way to create your meaningful notes." | ||
|
|
||
| ## Context | ||
|
|
||
| Memos requires a database and can be deployed on Serverless Containers. For cost optimised setup, for persistent storage this tutorial takes advantage of Scaleway Serverless SQL Database. Serverless Containers associated with Serverless Databases makes the setup cost efficient due to pay per use products. | ||
thomas-tacquet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Requirements | ||
|
|
||
| - [Terraform installed](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli#install-terraform), more information about Scaleway Terraform Quickstart [here](https://www.scaleway.com/en/docs/terraform/quickstart/) | ||
| - Terraform requires configuration to access Scaleway ressource, [follow this reference documentation](https://www.scaleway.com/en/docs/terraform/reference-content/scaleway-configuration-file/) | ||
|
|
||
| ## Usage | ||
|
|
||
| `main.tf` will: | ||
| * Create a new `memos` project | ||
| * Create required IAM permissions and key | ||
| * Create the Serverless SQL Database (postgres) | ||
| * Create the Serverless Container running `memos` configured to use the created SQL Database | ||
thomas-tacquet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Deploy the project using Terraform: | ||
|
|
||
| ```bash | ||
| terraform init | ||
| terraform apply | ||
| ``` | ||
|
|
||
| ## Delete changes | ||
|
|
||
| In case you need to delete everything created before (Database, Container, IAM configuration and Project), run: | ||
thomas-tacquet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| terraform destroy | ||
| ``` | ||
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,93 @@ | ||
| terraform { | ||
| required_providers { | ||
| scaleway = { | ||
| source = "scaleway/scaleway" | ||
| } | ||
| } | ||
| required_version = ">= 0.13" | ||
| } | ||
|
|
||
| # This Terraform configuration deploys a Memos instance on Scaleway. | ||
| # Memos is an "open-source, lightweight note-taking solution. The pain-less way to create your meaningful notes. Your Notes, Your Way." | ||
| # | ||
| # This configuration creates the necessary resources, including: | ||
| # - A Scaleway project | ||
| # - An IAM application and policy for Serverless SQL Database access | ||
| # - A Serverless SQL database (postgres) | ||
| # - A Serverless Container to run Memos | ||
|
|
||
| # Create a new project "memos" | ||
| resource "scaleway_account_project" "project" { | ||
| name = "memos" | ||
| } | ||
|
|
||
| # Create a new IAM Application called "memos" | ||
| resource "scaleway_iam_application" "app" { | ||
| name = "memos" | ||
| } | ||
|
|
||
| # Create a new IAM Policy that will give the API Key access to the Database | ||
| resource "scaleway_iam_policy" "db_access" { | ||
| name = "memos_policy" | ||
| description = "access to serverless database in project" | ||
| application_id = scaleway_iam_application.app.id | ||
| rule { | ||
| project_ids = [scaleway_account_project.project.id] | ||
| permission_set_names = ["ServerlessSQLDatabaseReadWrite"] | ||
| } | ||
| } | ||
|
|
||
| # Create API Key | ||
| resource "scaleway_iam_api_key" "api_key" { | ||
| application_id = scaleway_iam_application.app.id | ||
| } | ||
|
|
||
| # Create a new SQL Serverless Database in the "memos" project | ||
| resource "scaleway_sdb_sql_database" "database" { | ||
| name = "memos" | ||
| min_cpu = 0 | ||
| max_cpu = 1 | ||
| project_id = scaleway_account_project.project.id | ||
| } | ||
|
|
||
| locals { | ||
| # This connection string provides access to the Memos database. | ||
| # It will be used to inject in the Serverless Container | ||
| database_connection_string = format("postgres://%s:%s@%s", | ||
| scaleway_iam_application.app.id, | ||
| scaleway_iam_api_key.api_key.secret_key, | ||
| trimprefix(scaleway_sdb_sql_database.database.endpoint, "postgres://"), | ||
| ) | ||
| } | ||
|
|
||
| # Create namespace for the Serverless Container | ||
| resource "scaleway_container_namespace" "main" { | ||
| name = "memos-container" | ||
| project_id = scaleway_account_project.project.id | ||
| } | ||
|
|
||
| # Create the container with memos image. You can adjust cpu and memory | ||
| # depending the traffic on your application. | ||
| # Do not change the port | ||
| resource "scaleway_container" "main" { | ||
| name = "memos" | ||
| namespace_id = scaleway_container_namespace.main.id | ||
| registry_image = "neosmemo/memos:stable" | ||
| port = 5230 | ||
| cpu_limit = 1000 | ||
| memory_limit = 2048 | ||
| min_scale = 0 | ||
| max_scale = 5 | ||
| privacy = "public" | ||
| protocol = "http1" | ||
| deploy = true | ||
|
|
||
| environment_variables = { | ||
| # Specifies the database driver to use. | ||
| "MEMOS_DRIVER" = "postgres" | ||
| } | ||
| secret_environment_variables = { | ||
| # Provides the database connection string for Memos to connect to the database. | ||
| "MEMOS_DSN" = local.database_connection_string | ||
| } | ||
| } |
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.