From 35d4fa34422aeef45dd8310aa56906779142f669 Mon Sep 17 00:00:00 2001 From: Piotr Stawarski Date: Tue, 2 Apr 2024 11:49:19 +0200 Subject: [PATCH 1/9] fix: example source and name --- examples/create_postgresql_database/main.tf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/create_postgresql_database/main.tf b/examples/create_postgresql_database/main.tf index c0bfadd..f8a7cd1 100644 --- a/examples/create_postgresql_database/main.tf +++ b/examples/create_postgresql_database/main.tf @@ -1,5 +1,6 @@ -module "Digitalocean_postgresql_example" { - source = "github.com/opsd-io/terraform-module-digitalocean-postgresql?ref=2-create-postgresql-terraform-module" +module "example" { + source = "github.com/opsd-io/terraform-module-digitalocean-postgresql?ref=main" + cluster_name = "example-postgresql-cluster" postgresql_version = "16" node_size = "db-s-1vcpu-1gb" From 80162d258c9f126c20e181170d76fcb041def98e Mon Sep 17 00:00:00 2001 From: Piotr Stawarski Date: Tue, 2 Apr 2024 11:50:18 +0200 Subject: [PATCH 2/9] rename terraform --- examples/create_postgresql_database/{versions.tf => terraform.tf} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/create_postgresql_database/{versions.tf => terraform.tf} (100%) diff --git a/examples/create_postgresql_database/versions.tf b/examples/create_postgresql_database/terraform.tf similarity index 100% rename from examples/create_postgresql_database/versions.tf rename to examples/create_postgresql_database/terraform.tf From 4a707110bde3d07b4232fde4c24f4d65c46ecae6 Mon Sep 17 00:00:00 2001 From: Piotr Stawarski Date: Tue, 2 Apr 2024 11:52:40 +0200 Subject: [PATCH 3/9] no pinning in modules --- README.md | 10 +++++----- versions.tf | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 68e7332..edd9bd4 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,13 @@ module "terraform-module-digitalocean-postgresql" { | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.5.5 | -| [digitalocean](#requirement\_digitalocean) | 2.34.1 | +| [digitalocean](#requirement\_digitalocean) | >= 2.34.1 | ## Providers | Name | Version | |------|---------| -| [digitalocean](#provider\_digitalocean) | 2.34.1 | +| [digitalocean](#provider\_digitalocean) | >= 2.34.1 | ## Modules @@ -55,9 +55,9 @@ No modules. | Name | Type | |------|------| -| [digitalocean_database_cluster.main](https://registry.terraform.io/providers/digitalocean/digitalocean/2.34.1/docs/resources/database_cluster) | resource | -| [digitalocean_database_firewall.main](https://registry.terraform.io/providers/digitalocean/digitalocean/2.34.1/docs/resources/database_firewall) | resource | -| [digitalocean_database_user.main](https://registry.terraform.io/providers/digitalocean/digitalocean/2.34.1/docs/resources/database_user) | resource | +| [digitalocean_database_cluster.main](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/database_cluster) | resource | +| [digitalocean_database_firewall.main](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/database_firewall) | resource | +| [digitalocean_database_user.main](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/database_user) | resource | ## Inputs diff --git a/versions.tf b/versions.tf index 11027eb..045d2f3 100644 --- a/versions.tf +++ b/versions.tf @@ -3,7 +3,7 @@ terraform { required_providers { digitalocean = { source = "digitalocean/digitalocean" - version = "2.34.1" + version = ">= 2.34.1" } } } From 4eb0558a325550e4d8b87331564db27fde39df32 Mon Sep 17 00:00:00 2001 From: Piotr Stawarski Date: Tue, 2 Apr 2024 11:54:58 +0200 Subject: [PATCH 4/9] newlines --- variables.tf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/variables.tf b/variables.tf index d17a1c7..d7b3278 100644 --- a/variables.tf +++ b/variables.tf @@ -3,11 +3,13 @@ variable "cluster_name" { type = string nullable = false } + variable "node_count" { description = "Number of mysql nodes that will be created." type = number default = 1 } + variable "node_size" { description = "The mysql node instance size." type = string From ee3c4bac3b2fc46c8c100a5add07c4441cc93c06 Mon Sep 17 00:00:00 2001 From: Piotr Stawarski Date: Tue, 2 Apr 2024 11:56:08 +0200 Subject: [PATCH 5/9] missing default and dots --- README.md | 6 +++--- variables.tf | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index edd9bd4..96b0c4f 100644 --- a/README.md +++ b/README.md @@ -64,9 +64,9 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [cluster\_name](#input\_cluster\_name) | The name of the database cluster. | `string` | n/a | yes | -| [common\_tags](#input\_common\_tags) | A list of tag names to be applied to the database cluster | `set(string)` | n/a | yes | -| [database\_users](#input\_database\_users) | List of users | `set(string)` | `[]` | no | -| [firewall\_rules](#input\_firewall\_rules) | List of trusted sources associated with the cluster | `set(string)` | `[]` | no | +| [common\_tags](#input\_common\_tags) | A list of tag names to be applied to the database cluster. | `set(string)` | `[]` | no | +| [database\_users](#input\_database\_users) | List of users. | `set(string)` | `[]` | no | +| [firewall\_rules](#input\_firewall\_rules) | List of trusted sources associated with the cluster. | `set(string)` | `[]` | no | | [node\_count](#input\_node\_count) | Number of mysql nodes that will be created. | `number` | `1` | no | | [node\_size](#input\_node\_size) | The mysql node instance size. | `string` | `"db-s-1vcpu-1gb"` | no | | [postgresql\_version](#input\_postgresql\_version) | Engine version used by the cluster. | `number` | `16` | no | diff --git a/variables.tf b/variables.tf index d7b3278..8ede2f3 100644 --- a/variables.tf +++ b/variables.tf @@ -29,18 +29,19 @@ variable "region" { } variable "common_tags" { - description = "A list of tag names to be applied to the database cluster" + description = "A list of tag names to be applied to the database cluster." type = set(string) + default = [] } variable "firewall_rules" { - description = "List of trusted sources associated with the cluster" + description = "List of trusted sources associated with the cluster." type = set(string) default = [] } variable "database_users" { - description = "List of users" + description = "List of users." type = set(string) default = [] } From e9403ac4f8e5c9e89ec00dc580b8af87547be453 Mon Sep 17 00:00:00 2001 From: Piotr Stawarski Date: Tue, 2 Apr 2024 11:57:41 +0200 Subject: [PATCH 6/9] formatting --- main.tf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 03aeeac..da0ac85 100644 --- a/main.tf +++ b/main.tf @@ -9,11 +9,14 @@ resource "digitalocean_database_firewall" "main" { } } } + resource "digitalocean_database_user" "main" { - for_each = var.database_users + for_each = var.database_users + cluster_id = digitalocean_database_cluster.main.id name = each.key } + resource "digitalocean_database_cluster" "main" { name = var.cluster_name engine = "pg" From 110fe008206a9e7df8a5b01707cfb7ac25a2fd44 Mon Sep 17 00:00:00 2001 From: Piotr Stawarski Date: Tue, 2 Apr 2024 11:58:59 +0200 Subject: [PATCH 7/9] formatting --- README.md | 4 ++-- outputs.tf | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 96b0c4f..bd2a3df 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ No modules. | Name | Description | |------|-------------| -| [firewall\_id](#output\_firewall\_id) | A unique identifier for the firewall | +| [firewall\_id](#output\_firewall\_id) | A unique identifier for the firewall. | | [main\_default\_database](#output\_main\_default\_database) | Name of the cluster's default database. | | [main\_default\_user](#output\_main\_default\_user) | Username for the cluster's default user. | | [main\_default\_user\_password](#output\_main\_default\_user\_password) | Password for the cluster's default user. | @@ -86,7 +86,7 @@ No modules. | [main\_private\_host](#output\_main\_private\_host) | Same as host, but only accessible from resources within the account and in the same region. | | [main\_private\_uri](#output\_main\_private\_uri) | Same as uri, but only accessible from resources within the account and in the same region. | | [main\_uri](#output\_main\_uri) | The full URI for connecting to the database cluster. | -| [user\_ids](#output\_user\_ids) | A unique identifier for database users | +| [user\_ids](#output\_user\_ids) | A unique identifier for database users. | ## Examples of usage diff --git a/outputs.tf b/outputs.tf index d1900a0..01b0392 100644 --- a/outputs.tf +++ b/outputs.tf @@ -20,14 +20,14 @@ output "main_port" { output "main_uri" { description = "The full URI for connecting to the database cluster." - value = digitalocean_database_cluster.main.uri sensitive = true + value = digitalocean_database_cluster.main.uri } output "main_private_uri" { description = "Same as uri, but only accessible from resources within the account and in the same region." - value = digitalocean_database_cluster.main.private_uri sensitive = true + value = digitalocean_database_cluster.main.private_uri } output "main_default_database" { @@ -42,17 +42,16 @@ output "main_default_user" { output "main_default_user_password" { description = "Password for the cluster's default user." - value = digitalocean_database_cluster.main.password sensitive = true + value = digitalocean_database_cluster.main.password } output "firewall_id" { + description = "A unique identifier for the firewall." value = digitalocean_database_firewall.main.id - description = "A unique identifier for the firewall" } output "user_ids" { - description = "A unique identifier for database users" + description = "A unique identifier for database users." value = [for id in var.database_users : digitalocean_database_user.main[id].id] - } From 41841349791242a1588928500303818dadaf0fe5 Mon Sep 17 00:00:00 2001 From: Piotr Stawarski Date: Tue, 2 Apr 2024 11:59:46 +0200 Subject: [PATCH 8/9] no versions.tf --- main.tf | 10 ++++++++++ versions.tf | 9 --------- 2 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 versions.tf diff --git a/main.tf b/main.tf index da0ac85..4104b12 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,13 @@ +terraform { + required_version = ">= 1.5.5" + required_providers { + digitalocean = { + source = "digitalocean/digitalocean" + version = ">= 2.34.1" + } + } +} + resource "digitalocean_database_firewall" "main" { cluster_id = digitalocean_database_cluster.main.id diff --git a/versions.tf b/versions.tf deleted file mode 100644 index 045d2f3..0000000 --- a/versions.tf +++ /dev/null @@ -1,9 +0,0 @@ -terraform { - required_version = ">= 1.5.5" - required_providers { - digitalocean = { - source = "digitalocean/digitalocean" - version = ">= 2.34.1" - } - } -} From 082a05a5db86c51e8467a7d584ddafb56404a237 Mon Sep 17 00:00:00 2001 From: Piotr Stawarski Date: Tue, 2 Apr 2024 12:00:08 +0200 Subject: [PATCH 9/9] reorder --- main.tf | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.tf b/main.tf index 4104b12..374f43c 100644 --- a/main.tf +++ b/main.tf @@ -8,6 +8,16 @@ terraform { } } +resource "digitalocean_database_cluster" "main" { + name = var.cluster_name + engine = "pg" + version = var.postgresql_version + size = var.node_size + region = var.region + node_count = var.node_count + tags = var.common_tags +} + resource "digitalocean_database_firewall" "main" { cluster_id = digitalocean_database_cluster.main.id @@ -26,13 +36,3 @@ resource "digitalocean_database_user" "main" { cluster_id = digitalocean_database_cluster.main.id name = each.key } - -resource "digitalocean_database_cluster" "main" { - name = var.cluster_name - engine = "pg" - version = var.postgresql_version - size = var.node_size - region = var.region - node_count = var.node_count - tags = var.common_tags -}