diff --git a/README.md b/README.md
index 36058716..68ffc5c8 100644
--- a/README.md
+++ b/README.md
@@ -83,6 +83,7 @@ To attach access management tags to resources in this module, you need the follo
| [ibm_resource_tag.postgresql_tag](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_tag) | resource |
| [time_sleep.wait_for_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
| [ibm_database_connection.database_connection](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/database_connection) | data source |
+| [ibm_database_point_in_time_recovery.source_db_earliest_pitr_time](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/database_point_in_time_recovery) | data source |
### Inputs
@@ -106,7 +107,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. 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) 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 |
+| [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. If empty string ("") 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 | `string` | `null` | 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 |
| [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where the PostgreSQL instance will be created. | `string` | n/a | yes |
@@ -128,6 +129,7 @@ To attach access management tags to resources in this module, you need the follo
| [guid](#output\_guid) | Postgresql instance guid |
| [hostname](#output\_hostname) | Database connection hostname |
| [id](#output\_id) | Postgresql instance id |
+| [pitr\_time](#output\_pitr\_time) | Postgresql instance id |
| [port](#output\_port) | Database connection port |
| [service\_credentials\_json](#output\_service\_credentials\_json) | Service credentials json map |
| [service\_credentials\_object](#output\_service\_credentials\_object) | Service credentials object |
diff --git a/examples/pitr/main.tf b/examples/pitr/main.tf
index 40bce1f1..e4193f27 100644
--- a/examples/pitr/main.tf
+++ b/examples/pitr/main.tf
@@ -18,13 +18,13 @@ module "postgresql_db_pitr" {
region = var.region
resource_tags = var.resource_tags
access_tags = var.access_tags
- member_memory_mb = 3072
+ member_memory_mb = 12288
member_disk_mb = 15360
- member_cpu_count = 9
+ member_cpu_count = var.member_cpu_count
member_host_flavor = "multitenant"
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
}
diff --git a/examples/pitr/outputs.tf b/examples/pitr/outputs.tf
index 9ff73d40..db8c7d3f 100644
--- a/examples/pitr/outputs.tf
+++ b/examples/pitr/outputs.tf
@@ -2,6 +2,10 @@
# Outputs
##############################################################################
+output "pitr_time" {
+ description = "PITR timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) used to create PITR instance"
+ value = module.postgresql_db_pitr.pitr_time
+}
output "pitr_postgresql_db_id" {
description = "PITR Postgresql instance id"
value = module.postgresql_db_pitr.id
@@ -11,8 +15,3 @@ output "pitr_postgresql_db_version" {
description = "PITR Postgresql instance version"
value = module.postgresql_db_pitr.version
}
-
-output "pitr_time" {
- description = "PITR timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) used to create PITR instance"
- value = var.pitr_time
-}
diff --git a/examples/pitr/variables.tf b/examples/pitr/variables.tf
index f3fb3838..98488d55 100644
--- a/examples/pitr/variables.tf
+++ b/examples/pitr/variables.tf
@@ -45,7 +45,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 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"
+ 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 (\"\") is passed, earliest_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" {
@@ -53,3 +53,8 @@ variable "members" {
description = "Allocated number of members. Members must be same or higher than the source deployment PostgreSQL instance."
default = 2
}
+
+variable "member_cpu_count" {
+ type = number
+ description = "Allocated dedicated CPU per member. For shared CPU, set to 0. [Learn more](https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-resources-scaling)"
+}
diff --git a/main.tf b/main.tf
index 79d0b448..92073de6 100644
--- a/main.tf
+++ b/main.tf
@@ -278,3 +278,8 @@ data "ibm_database_connection" "database_connection" {
user_id = ibm_database.postgresql_db.adminuser
user_type = "database"
}
+
+data "ibm_database_point_in_time_recovery" "source_db_earliest_pitr_time" {
+ count = var.pitr_time != "" ? 0 : 1
+ deployment_id = var.pitr_id
+}
diff --git a/outputs.tf b/outputs.tf
index f26aa280..a314d105 100644
--- a/outputs.tf
+++ b/outputs.tf
@@ -59,3 +59,8 @@ output "certificate_base64" {
value = data.ibm_database_connection.database_connection.postgres[0].certificate[0].certificate_base64
sensitive = true
}
+
+output "pitr_time" {
+ description = "Postgresql instance id"
+ value = var.pitr_time != "" ? var.pitr_time : data.ibm_database_point_in_time_recovery.source_db_earliest_pitr_time[0].earliest_point_in_time_recovery_time
+}
diff --git a/tests/other_test.go b/tests/other_test.go
index 5efe48b2..36a5d839 100644
--- a/tests/other_test.go
+++ b/tests/other_test.go
@@ -39,10 +39,11 @@ func TestRunPointInTimeRecoveryDBExample(t *testing.T) {
ResourceGroup: resourceGroup,
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
+ "pitr_id": permanentResources["postgresqlPITRCrn"],
+ "pitr_time": "", // if blank string is passed, earliest_point_in_time_recovery_time will be used to restore
+ "pg_version": permanentResources["postgresqlPITRVersion"],
+ "members": "3", // Lock members to 3 as the permanent postgres instances has 3 members
+ "member_cpu_count": 0, // Lock cpu to 0 as the permanent postgres instances has 0 cpu
},
CloudInfoService: sharedInfoSvc,
})
diff --git a/variables.tf b/variables.tf
index 15a75ebe..f6ec1170 100644
--- a/variables.tf
+++ b/variables.tf
@@ -353,6 +353,6 @@ variable "pitr_id" {
variable "pitr_time" {
type = string
- 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"
+ 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. If empty string (\"\") 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"
default = null
}