Skip to content

michelia-io/terraform-kubernetes-postgresql

 
 

Repository files navigation

Kubernetes PostgreSQL Service

Terraform module which deploys containerized PostgreSQL on Kubernetes, powered by Bitnami Charts/PostgreSQL.

  • Support standalone(one read-write instance) and replication(one read-write instance and multiple read-only instances, for read write splitting).
  • Support database seeding.

Usage

module "postgresql" {
  source = "..."

  infrastructure = {
    namespace = "default"
  }

  architecture   = "replication"
  engine_version = "13"         # https://hub.docker.com/r/bitnami/postgresql/tags
}

Examples

Contributing

Please read our contributing guide if you're interested in contributing to Walrus template.

Requirements

Name Version
terraform >= 1.0
helm >= 2.11.0
kubernetes >= 2.23.0
random >= 3.5.1

Providers

Name Version
helm >= 2.11.0
kubernetes >= 2.23.0
random >= 3.5.1

Modules

No modules.

Resources

Name Type
helm_release.postgresql resource
kubernetes_config_map_v1.text_seeding resource
kubernetes_persistent_volume_claim_v1.url_seeding resource
random_password.password resource
random_string.name_suffix resource

Inputs

Name Description Type Default Required
architecture Specify the deployment architecture, select from standalone or replication. string "standalone" no
context Receive contextual information. When Walrus deploys, Walrus will inject specific contextual information into this field.

Examples:
context:
project:
name: string
id: string
environment:
name: string
id: string
resource:
name: string
id: string
map(any) {} no
database Specify the database name. The database name must be 2-64 characters long and start with any lower letter, combined with number, or symbols: - _.
The database name cannot be PostgreSQL forbidden keyword.
string "mydb" no
engine_version Specify the deployment engine version, select from https://hub.docker.com/r/bitnami/postgresql/tags. string "16.0" no
infrastructure Specify the infrastructure information for deploying.

Examples:
infrastructure:
namespace: string, optional
image_registry: string, optional
domain_suffix: string, optional
service_type: string, optional
object({
namespace = optional(string)
image_registry = optional(string, "registry-1.docker.io")
domain_suffix = optional(string, "cluster.local")
service_type = optional(string, "ClusterIP")
})
{} no
password Specify the account password. The password must be 8-32 characters long and start with any letter, number, or symbols: ! # $ % ^ & * ( ) _ + - =.
If not specified, it will generate a random password.
string null no
replication_readonly_replicas Specify the number of read-only replicas under the replication deployment. number 1 no
resources Specify the computing resources.

Examples:
resources:
cpu: number, optional
memory: number, optional # in megabyte
object({
cpu = optional(number, 0.25)
memory = optional(number, 512)
})
{
"cpu": 0.25,
"memory": 512
}
no
seeding Specify the configuration to seed the database at first-time creating.

Seeding increases the startup time waiting and also needs proper permission,
like root account.

Examples:
seeding:
type: none/url/text
url: # store the content to a volume
location: string
storage: # convert to dynamic volume claim template
class: string, optional
size: number, optional # in megabyte
text: # store the content to a configmap
content: string
object({
type = optional(string, "none")
url = optional(object({
location = string
storage = optional(object({
class = optional(string)
size = optional(number, 10 * 1024)
}))
}))
text = optional(object({
content = string
}))
})
{} no
storage Specify the storage resources.

Examples:
storage:                         # convert to empty_dir volume or dynamic volume claim template
class: string, optional
size: number, optional # in megabyte
object({
class = optional(string)
size = optional(number, 10 * 1024)
})
null no
username Specify the account username. The username must be 2-16 characters long and start with lower letter, combined with number, or symbol: _.
The username cannot be PostgreSQL forbidden keyword.
string "rdsuser" no

Outputs

Name Description
address The address, a string only has host, might be a comma separated string or a single string.
address_readonly The readonly address, a string only has host, might be a comma separated string or a single string.
connection The connection, a string combined host and port, might be a comma separated string or a single string.
connection_readonly The readonly connection, a string combined host and port, might be a comma separated string or a single string.
context The input context, a map, which is used for orchestration.
database The name of PostgreSQL database to access.
password The password of the account to access the database.
port The port of the service.
refer The refer, a map, including hosts, ports and account, which is used for dependencies or collaborations.
username The username of the account to access the database.

License

Copyright (c) 2023 Seal, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at LICENSE file for details.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Packages

No packages published

Languages

  • Shell 61.7%
  • HCL 34.7%
  • Makefile 3.6%