Skip to content

Commit

Permalink
test: new host model with 4G memory PITR (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ak-sky authored Aug 19, 2024
1 parent a8d8073 commit 65c9967
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -106,7 +107,7 @@ To attach access management tags to resources in this module, you need the follo
| <a name="input_name"></a> [name](#input\_name) | The name to give the Postgresql instance. | `string` | n/a | yes |
| <a name="input_pg_version"></a> [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 |
| <a name="input_pitr_id"></a> [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 |
| <a name="input_pitr_time"></a> [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 <deployment name or CRN>). 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 |
| <a name="input_pitr_time"></a> [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 <deployment name or CRN>). 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 |
| <a name="input_region"></a> [region](#input\_region) | The region where you want to deploy your instance. | `string` | `"us-south"` | no |
| <a name="input_remote_leader_crn"></a> [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 |
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where the PostgreSQL instance will be created. | `string` | n/a | yes |
Expand All @@ -128,6 +129,7 @@ To attach access management tags to resources in this module, you need the follo
| <a name="output_guid"></a> [guid](#output\_guid) | Postgresql instance guid |
| <a name="output_hostname"></a> [hostname](#output\_hostname) | Database connection hostname |
| <a name="output_id"></a> [id](#output\_id) | Postgresql instance id |
| <a name="output_pitr_time"></a> [pitr\_time](#output\_pitr\_time) | Postgresql instance id |
| <a name="output_port"></a> [port](#output\_port) | Database connection port |
| <a name="output_service_credentials_json"></a> [service\_credentials\_json](#output\_service\_credentials\_json) | Service credentials json map |
| <a name="output_service_credentials_object"></a> [service\_credentials\_object](#output\_service\_credentials\_object) | Service credentials object |
Expand Down
6 changes: 3 additions & 3 deletions examples/pitr/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
9 changes: 4 additions & 5 deletions examples/pitr/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
7 changes: 6 additions & 1 deletion examples/pitr/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ 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 <deployment name or CRN>). 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 <deployment name or CRN>). 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."
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)"
}
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 5 additions & 4 deletions tests/other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 <deployment name or CRN>). 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 <deployment name or CRN>). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr"
default = null
}

0 comments on commit 65c9967

Please sign in to comment.