8000 PSQL firewall rules should support tags, ips, droplet and k8s by michaltomczuk · Pull Request #19 · opsd-io/terraform-module-digitalocean-postgresql · GitHub
[go: up one dir, main page]

Skip to content

PSQL firewall rules should support tags, ips, droplet and k8s #19

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 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,40 @@ What does the module provide?
## Usage

```hcl
module "terraform-module-digitalocean-postgresql" {
module "postgresql" {
source = "https://github.com/opsd-io/terraform-module-digitalocean-postgresql?ref=main"

cluster_name = "example-postgresql-cluster"
engine = "pg"
postgresql_version = "11"
postgresql_version = "16"
node_size = "db-s-1vcpu-1gb"
region = "nyc1"
node_count = 1
common_tags = ["production"]
common_tags = ["postgresql", "production"]
database_users = ["Admin", "Mark", "Robert"]
firewall_rules = ["192.168.0.1", "192.168.0.2", "192.168.0.8"]
firewall_rules = [
{
type = "ip_addr"
value = "172.168.0.1"
},
{
type = "tag"
value = "app"
}
]
replica_enable = true
replica_node_size = "db-s-1vcpu-1gb"
replica_cluster_name = "example-postgresql-replica-cluster"
replica_region = "nyc1"
firewall_rules_replica = ["172.168.0.1", "172.168.0.2", "172.168.0.8"]

firewall_rules = [
{
type = "ip_addr"
value = "172.168.0.1"
},
{
type = "tag"
value = "app"
}
]
}
```

Expand Down Expand Up @@ -72,14 +89,14 @@ No modules.
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The name of the database cluster. | `string` | n/a | yes |
| <a name="input_common_tags"></a> [common\_tags](#input\_common\_tags) | A list of tag names to be applied to the database cluster. | `set(string)` | `[]` | no |
| <a name="input_database_users"></a> [database\_users](#input\_database\_users) | List of users. | `set(string)` | `[]` | no |
| <a name="input_firewall_rules"></a> [firewall\_rules](#input\_firewall\_rules) | List of trusted sources associated with the cluster. | `set(string)` | `[]` | no |
| <a name="input_firewall_rules"></a> [firewall\_rules](#input\_firewall\_rules) | List of trusted sources associated with the cluster. | <pre>list(object({<br> type = string<br> value = string<br> }))</pre> | `[]` | no |
| <a name="input_node_count"></a> [node\_count](#input\_node\_count) | Number of postgresql nodes that will be created. | `number` | `1` | no |
| <a name="input_node_size"></a> [node\_size](#input\_node\_size) | The postgresql node instance size. | `string` | `"db-s-1vcpu-1gb"` | no |
| <a name="input_postgresql_version"></a> [postgresql\_version](#input\_postgresql\_version) | Engine version used by the cluster. | `number` | `16` | no |
| <a name="input_region"></a> [region](#input\_region) | DigitalOcean region where the cluster will reside. | `string` | n/a | yes |
| <a name="input_replica_cluster_name"></a> [replica\_cluster\_name](#input\_replica\_cluster\_name) | The name of the replica database cluster. | `string` | `null` | no |
| <a name="input_replica_enable"></a> [replica\_enable](#input\_replica\_enable) | Flag to control the replica creation. | `bool` | `false` | no |
| <a name="input_replica_firewall_rules"></a> [replica\_firewall\_rules](#input\_replica\_firewall\_rules) | List of trusted sources associated with the replica cluster. | `set(string)` | `[]` | no |
| <a name="input_replica_firewall_rules"></a> [replica\_firewall\_rules](#input\_replica\_firewall\_rules) | List of trusted sources associated with the replica cluster. | <pre>list(object({<br> type = string<br> value = string<br> }))</pre> | `[]` | no |
| <a name="input_replica_node_size"></a> [replica\_node\_size](#input\_replica\_node\_size) | The postgresql replica node instance size. | `string` | `"db-s-1vcpu-1gb"` | no |
| <a name="input_replica_region"></a> [replica\_region](#input\_replica\_region) | DigitalOcean replica region where the cluster will reside. | `string` | `null` | no |
| <a name="input_vpc_uuid"></a> [vpc\_uuid](#input\_vpc\_uuid) | The ID of the VPC where the load balancer will be located. | `string` | `null` | no |
Expand Down
46 changes: 32 additions & 14 deletions examples/create_postgresql_database/main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
module "example" {
source = "github.com/opsd-io/terraform-module-digitalocean-postgresql?ref=9-feature-add-database_clusterurn-output"
module "postgresql" {
source = "https://github.com/opsd-io/terraform-module-digitalocean-postgresql?ref=main"

cluster_name = "opsd-main"
postgresql_version = "16"
node_size = "db-s-1vcpu-1gb"
region = "nyc1"
node_count = 1
common_tags = ["production"]
database_users = ["Admin", "Mark", "Robert"]
firewall_rules = ["192.168.0.1", "192.168.0.2", "192.168.0.8"]
replica_enable = true
replica_node_size = "db-s-1vcpu-1gb"
replica_region = "nyc1"
replica_firewall_rules = ["172.168.0.1", "172.168.0.2", "172.168.0.8"]
cluster_name = "opsd-main"
postgresql_version = "16"
node_size = "db-s-1vcpu-1gb"
region = "nyc1"
node_count = 1
common_tags = ["production"]
database_users = ["Admin", "Mark", "Robert"]
firewall_rules = [
{
type = "ip_addr"
value = "172.168.0.1"
},
{
type = "tag"
value = "app"
}
]
replica_enable = true
replica_node_size = "db-s-1vcpu-1gb"
replica_region = "nyc1"
replica_firewall_rules = [
{
type = "ip_addr"
value = "172.168.0.1"
},
{
type = "tag"
value = "app"
}
]
}
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ resource "digitalocean_database_firewall" "main" {
dynamic "rule" {
for_each = var.firewall_rules
content {
type = "ip_addr"
value = rule.value
type = rule.value.type
value = rule.value.value
}
}
}
Expand All @@ -38,8 +38,8 @@ resource "digitalocean_database_firewall" "replica_fw" {
dynamic "rule& 8000 quot; {
for_each = var.replica_firewall_rules
content {
type = "ip_addr"
value = rule.value
type = rule.value.type
value = rule.value.value
}
}
depends_on = [digitalocean_database_replica.main]
Expand Down
14 changes: 10 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,20 @@ variable "common_tags" {

variable "firewall_rules" {
description = "List of trusted sources associated with the cluster."
type = set(string)
default = []
type = list(object({
type = string
value = string
}))
default = []
}

variable "replica_firewall_rules" {
description = "List of trusted sources associated with the replica cluster."
5F59 type = set(string)
default = []
type = list(object({
type = string
value = string
}))
default = []
}

variable "database_users" {
Expand Down
Loading
0