From bd1f3d87d02bf67417d917507278c8a758022cbf Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Fri, 23 Jun 2023 13:59:53 +0530 Subject: [PATCH 1/6] refactor: pitr_time fix in tests --- README.md | 2 +- examples/pitr/main.tf | 6 +----- examples/pitr/outputs.tf | 2 +- examples/pitr/variables.tf | 7 +++++++ module-metadata.json | 2 +- tests/other_test.go | 6 ++++++ variables.tf | 2 +- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c43154b5..258cfdce 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ To attach access management tags to resources in this module, you need the follo | [name](#input\_name) | The name to give the Postgresql instance. | `string` | n/a | yes | | [pg\_version](#input\_pg\_version) | Version of the PostgreSQL instance to provision. If no value is passed, the current preferred version of IBM Cloud Databases is used. | `string` | `null` | no | | [pitr\_id](#input\_pitr\_id) | (Optional) The ID of the source deployment PostgreSQL instance that you want to recover back to. The PostgreSQL instance is expected to be in an up and in running state. | `string` | `null` | no | -| [pitr\_time](#input\_pitr\_time) | (Optional) The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) that you want to restore to. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr | `string` | `null` | no | +| [pitr\_time](#input\_pitr\_time) | (Optional) The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr | `string` | `null` | no | | [plan\_validation](#input\_plan\_validation) | Enable or disable validating the database parameters for PostgreSQL during the plan phase. | `bool` | `true` | no | | [region](#input\_region) | The region where you want to deploy your instance. | `string` | `"us-south"` | no | | [remote\_leader\_crn](#input\_remote\_leader\_crn) | A CRN of the leader database to make the replica(read-only) deployment. The leader database is created by a database deployment with the same service ID. A read-only replica is set up to replicate all of your data from the leader deployment to the replica deployment by using asynchronous replication. For more information, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-read-only-replicas | `string` | `null` | no | diff --git a/examples/pitr/main.tf b/examples/pitr/main.tf index 4a0a7874..919cfddc 100644 --- a/examples/pitr/main.tf +++ b/examples/pitr/main.tf @@ -10,10 +10,6 @@ module "resource_group" { existing_resource_group_name = var.resource_group } -data "ibm_database_point_in_time_recovery" "database_pitr" { - deployment_id = var.pitr_id -} - # New ICD postgresql database instance pointing to a PITR time module "postgresql_db_pitr" { source = "../.." @@ -28,5 +24,5 @@ module "postgresql_db_pitr" { members = var.members pg_version = var.pg_version pitr_id = var.pitr_id - pitr_time = data.ibm_database_point_in_time_recovery.database_pitr.earliest_point_in_time_recovery_time + pitr_time = var.pitr_time } diff --git a/examples/pitr/outputs.tf b/examples/pitr/outputs.tf index a2b13432..9ff73d40 100644 --- a/examples/pitr/outputs.tf +++ b/examples/pitr/outputs.tf @@ -14,5 +14,5 @@ output "pitr_postgresql_db_version" { output "pitr_time" { description = "PITR timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) used to create PITR instance" - value = data.ibm_database_point_in_time_recovery.database_pitr.earliest_point_in_time_recovery_time + value = var.pitr_time } diff --git a/examples/pitr/variables.tf b/examples/pitr/variables.tf index 46ee2980..92406068 100644 --- a/examples/pitr/variables.tf +++ b/examples/pitr/variables.tf @@ -45,6 +45,13 @@ variable "pitr_id" { description = "The ID of the source deployment PostgreSQL instance that you want to recover back to. The PostgreSQL instance is expected to be in an up and in running state." } +variable "pitr_time" { + type = string + description = "The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr" + default = null +} + + variable "members" { type = number description = "Allocated number of members. Members must be same or higher than the source deployment PostgreSQL instance." diff --git a/module-metadata.json b/module-metadata.json index 5e041ac0..895728a1 100644 --- a/module-metadata.json +++ b/module-metadata.json @@ -216,7 +216,7 @@ "pitr_time": { "name": "pitr_time", "type": "string", - "description": "(Optional) The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) that you want to restore to. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp \u003cdeployment name or CRN\u003e). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr", + "description": "(Optional) The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp \u003cdeployment name or CRN\u003e). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr", "source": [ "ibm_database.postgresql_db.point_in_time_recovery_time" ], diff --git a/tests/other_test.go b/tests/other_test.go index 6332bf0b..0f5e6c26 100644 --- a/tests/other_test.go +++ b/tests/other_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper" "testing" + "time" ) func TestRunRestoredDBExample(t *testing.T) { @@ -28,6 +29,10 @@ func TestRunRestoredDBExample(t *testing.T) { } func TestRunPointInTimeRecoveryDBExample(t *testing.T) { + getCurrDate := time.Now() + subDate := getCurrDate.AddDate(0, 0, -1) // Subtracting 1 day from the current time considering this as latest available point + pitrTime := subDate.UTC().Format(time.RFC3339) + t.Parallel() options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{ @@ -38,6 +43,7 @@ func TestRunPointInTimeRecoveryDBExample(t *testing.T) { Region: fmt.Sprint(permanentResources["postgresqlPITRRegion"]), TerraformVars: map[string]interface{}{ "pitr_id": permanentResources["postgresqlPITRCrn"], + "pitr_time": pitrTime, "pg_version": permanentResources["postgresqlPITRVersion"], "members": "3", // Lock members to 3 as the permanent postgres instances has 3 members }, diff --git a/variables.tf b/variables.tf index 80de3939..5ebaa9b8 100644 --- a/variables.tf +++ b/variables.tf @@ -277,6 +277,6 @@ variable "pitr_id" { variable "pitr_time" { type = string - description = "(Optional) The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) that you want to restore to. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr" + description = "(Optional) The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr" default = null } From 48990ef597459747b3f846e28b4dd9b2861e362c Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Fri, 23 Jun 2023 16:24:48 +0530 Subject: [PATCH 2/6] refactor: pitr_time fix in tests --- examples/pitr/main.tf | 6 +++++- examples/pitr/variables.tf | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/pitr/main.tf b/examples/pitr/main.tf index 919cfddc..03a4cb9e 100644 --- a/examples/pitr/main.tf +++ b/examples/pitr/main.tf @@ -10,6 +10,10 @@ module "resource_group" { existing_resource_group_name = var.resource_group } +data "ibm_database_point_in_time_recovery" "database_pitr" { + deployment_id = var.pitr_id +} + # New ICD postgresql database instance pointing to a PITR time module "postgresql_db_pitr" { source = "../.." @@ -24,5 +28,5 @@ module "postgresql_db_pitr" { members = var.members pg_version = var.pg_version pitr_id = var.pitr_id - pitr_time = var.pitr_time + pitr_time = var.pitr_time == "" ? data.ibm_database_point_in_time_recovery.database_pitr.earliest_point_in_time_recovery_time : var.pitr_time } diff --git a/examples/pitr/variables.tf b/examples/pitr/variables.tf index 92406068..c9373355 100644 --- a/examples/pitr/variables.tf +++ b/examples/pitr/variables.tf @@ -47,8 +47,7 @@ variable "pitr_id" { variable "pitr_time" { type = string - description = "The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr" - default = null + description = "The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. If no value is passed, earliest_point_in_time_recovery_time will be used as pitr_time. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr" } From f6b88f888d11a6e164c8997e931caf2d8ea5175c Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Mon, 14 Aug 2023 19:29:35 +0530 Subject: [PATCH 3/6] test: pitr test added latest point of recovery time for PITR --- examples/pitr/main.tf | 6 +----- examples/pitr/variables.tf | 3 +-- tests/other_test.go | 6 ------ 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/examples/pitr/main.tf b/examples/pitr/main.tf index 46416825..62e514a5 100644 --- a/examples/pitr/main.tf +++ b/examples/pitr/main.tf @@ -10,10 +10,6 @@ module "resource_group" { existing_resource_group_name = var.resource_group } -data "ibm_database_point_in_time_recovery" "database_pitr" { - deployment_id = var.pitr_id -} - # New ICD postgresql database instance pointing to a PITR time module "postgresql_db_pitr" { source = "../.." @@ -28,5 +24,5 @@ module "postgresql_db_pitr" { members = var.members pg_version = var.pg_version pitr_id = var.pitr_id - pitr_time = var.pitr_time == "" ? data.ibm_database_point_in_time_recovery.database_pitr.earliest_point_in_time_recovery_time : var.pitr_time + pitr_time = var.pitr_time == "" ? "" : var.pitr_time } diff --git a/examples/pitr/variables.tf b/examples/pitr/variables.tf index c9373355..f9cbb527 100644 --- a/examples/pitr/variables.tf +++ b/examples/pitr/variables.tf @@ -47,10 +47,9 @@ variable "pitr_id" { variable "pitr_time" { type = string - description = "The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. If no value is passed, earliest_point_in_time_recovery_time will be used as pitr_time. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr" + description = "The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. If no value is passed, latest_point_in_time_recovery_time will be used as pitr_time. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr" } - variable "members" { type = number description = "Allocated number of members. Members must be same or higher than the source deployment PostgreSQL instance." diff --git a/tests/other_test.go b/tests/other_test.go index 0f5e6c26..6332bf0b 100644 --- a/tests/other_test.go +++ b/tests/other_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper" "testing" - "time" ) func TestRunRestoredDBExample(t *testing.T) { @@ -29,10 +28,6 @@ func TestRunRestoredDBExample(t *testing.T) { } func TestRunPointInTimeRecoveryDBExample(t *testing.T) { - getCurrDate := time.Now() - subDate := getCurrDate.AddDate(0, 0, -1) // Subtracting 1 day from the current time considering this as latest available point - pitrTime := subDate.UTC().Format(time.RFC3339) - t.Parallel() options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{ @@ -43,7 +38,6 @@ func TestRunPointInTimeRecoveryDBExample(t *testing.T) { Region: fmt.Sprint(permanentResources["postgresqlPITRRegion"]), TerraformVars: map[string]interface{}{ "pitr_id": permanentResources["postgresqlPITRCrn"], - "pitr_time": pitrTime, "pg_version": permanentResources["postgresqlPITRVersion"], "members": "3", // Lock members to 3 as the permanent postgres instances has 3 members }, From b814c0512adaaaf78122d874b84b19f054dedb8d Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Mon, 14 Aug 2023 20:13:14 +0530 Subject: [PATCH 4/6] test: restore to the latest available point-in-time using single space --- examples/pitr/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pitr/main.tf b/examples/pitr/main.tf index 62e514a5..fb1d3401 100644 --- a/examples/pitr/main.tf +++ b/examples/pitr/main.tf @@ -24,5 +24,5 @@ module "postgresql_db_pitr" { members = var.members pg_version = var.pg_version pitr_id = var.pitr_id - pitr_time = var.pitr_time == "" ? "" : var.pitr_time + pitr_time = var.pitr_time == "" ? " " : var.pitr_time } From 3de65db9f5bd6f445f4a8d70fc2a0a1788889c1b Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Mon, 21 Aug 2023 21:12:06 +0530 Subject: [PATCH 5/6] test: updated pitr_time variable descroption --- examples/pitr/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pitr/variables.tf b/examples/pitr/variables.tf index f9cbb527..41df341d 100644 --- a/examples/pitr/variables.tf +++ b/examples/pitr/variables.tf @@ -47,7 +47,7 @@ variable "pitr_id" { variable "pitr_time" { type = string - description = "The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. If no value is passed, latest_point_in_time_recovery_time will be used as pitr_time. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr" + description = "The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. If empty string (\"\") or spaced string (\" \") is passed, latest_point_in_time_recovery_time will be used as pitr_time. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp ). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr" } variable "members" { From c9f8b6e49a19228a64ca5a79d68c590b18fb3ccb Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Mon, 21 Aug 2023 21:35:04 +0530 Subject: [PATCH 6/6] test: fixed pitr_time in other_test --- tests/other_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/other_test.go b/tests/other_test.go index 6332bf0b..088acb59 100644 --- a/tests/other_test.go +++ b/tests/other_test.go @@ -38,6 +38,7 @@ func TestRunPointInTimeRecoveryDBExample(t *testing.T) { Region: fmt.Sprint(permanentResources["postgresqlPITRRegion"]), TerraformVars: map[string]interface{}{ "pitr_id": permanentResources["postgresqlPITRCrn"], + "pitr_time": " ", "pg_version": permanentResources["postgresqlPITRVersion"], "members": "3", // Lock members to 3 as the permanent postgres instances has 3 members },