generated from terraform-ibm-modules/terraform-ibm-module-template
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: backup_id #51
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
feat: backup_id #51
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c48956a
feat: backup_id
rajatagarwal-ibm ee2e92e
feat: backup_id
rajatagarwal-ibm a4d32a3
Merge branch 'main' of github.com:terraform-ibm-modules/terraform-ibm…
rajatagarwal-ibm 4a25d1d
Merge branch 'main' into backup-support
rajatagarwal-ibm a76093f
Merge branch 'backup-support' of github.com:terraform-ibm-modules/ter…
rajatagarwal-ibm c7d1d5c
feat: backup_id
rajatagarwal-ibm b70ccd8
feat: backup_id
rajatagarwal-ibm 31001b1
feat: backup_id
rajatagarwal-ibm 975071a
Merge branch 'main' into backup-support
rajatagarwal-ibm fb03895
feat: backup_id
rajatagarwal-ibm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Restore from backup example | ||
|
|
||
| This example provides an end-to-end executable flow of how a PostgreSQL DB can be created from a backup instance. This example uses the IBM Cloud terraform provider to: | ||
|
|
||
| - Create a new resource group if one is not passed in. | ||
| - Create a new ICD Postgresql database instance if no existing backup crn is provided. | ||
| - Create a restored ICD Postgresql database instance pointing to the backup of the first instance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| ############################################################################## | ||
| # Resource Group | ||
| ############################################################################## | ||
|
|
||
| module "resource_group" { | ||
| source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-resource-group.git?ref=v1.0.5" | ||
| # if an existing resource group is not set (null) create a new one using prefix | ||
| resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null | ||
| existing_resource_group_name = var.resource_group | ||
| } | ||
|
|
||
| module "postgresql_db" { | ||
| count = var.postgresql_db_backup_crn != null ? 0 : 1 | ||
| source = "../.." | ||
| resource_group_id = module.resource_group.resource_group_id | ||
| name = "${var.prefix}-postgres" | ||
| region = var.region | ||
| resource_tags = var.resource_tags | ||
| } | ||
|
|
||
| data "ibm_database_backups" "backup_database" { | ||
| count = var.postgresql_db_backup_crn != null ? 0 : 1 | ||
| deployment_id = module.postgresql_db[0].id | ||
| } | ||
|
|
||
| # New postgresql instance pointing to the backup instance | ||
| module "restored_postgresql_db" { | ||
| source = "../.." | ||
| resource_group_id = module.resource_group.resource_group_id | ||
| name = "${var.prefix}-postgres-restored" | ||
| region = var.region | ||
| resource_tags = var.resource_tags | ||
| backup_crn = var.postgresql_db_backup_crn == null ? data.ibm_database_backups.backup_database[0].backups[0].backup_id : var.postgresql_db_backup_crn | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| ############################################################################## | ||
| # Outputs | ||
| ############################################################################## | ||
| output "id" { | ||
| description = "Postgresql instance id" | ||
| value = var.postgresql_db_backup_crn == null ? module.postgresql_db[0].id : null | ||
| } | ||
|
|
||
| output "restored_postgresql_db_id" { | ||
| description = "Restored Postgresql instance id" | ||
| value = module.restored_postgresql_db.id | ||
| } | ||
|
|
||
| output "restored_postgresql_db_version" { | ||
| description = "Restored Postgresql instance version" | ||
| value = module.restored_postgresql_db.version | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| provider "ibm" { | ||
| ibmcloud_api_key = var.ibmcloud_api_key | ||
| region = var.region | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| variable "ibmcloud_api_key" { | ||
| type = string | ||
| description = "The IBM Cloud API Key" | ||
| sensitive = true | ||
| } | ||
|
|
||
| variable "region" { | ||
| type = string | ||
| description = "Region to provision all resources created by this example." | ||
| default = "us-south" | ||
| } | ||
|
|
||
| variable "prefix" { | ||
| type = string | ||
| description = "Prefix to append to all resources created by this example" | ||
| default = "pg-res" | ||
| } | ||
|
|
||
| variable "resource_group" { | ||
| type = string | ||
| description = "An existing resource group name to use for this example, if unset a new resource group will be created" | ||
| default = null | ||
| } | ||
|
|
||
| variable "resource_tags" { | ||
| type = list(string) | ||
| description = "Optional list of tags to be added to created resources" | ||
| default = [] | ||
| } | ||
|
|
||
| variable "postgresql_db_backup_crn" { | ||
| type = string | ||
| description = "The existing CRN of a backup resource to restore from. If null then it will create a new instance first and then create another instance pointing to the backup of the first instance." | ||
| default = null | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| terraform { | ||
| required_version = ">= 1.3.0" | ||
| required_providers { | ||
| # Pin to the lowest provider version of the range defined in the main module's version.tf to ensure lowest version still works | ||
| ibm = { | ||
| source = "IBM-Cloud/ibm" | ||
| version = "1.49.0" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Tests in this file are NOT run in the PR pipeline. They are run in the continuous testing pipeline along with the ones in pr_test.go | ||
| package test | ||
|
|
||
| import ( | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper" | ||
| "testing" | ||
| ) | ||
|
|
||
| const restoredTerraformDir = "examples/backup" | ||
|
|
||
| func TestRunRestoredDBExample(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{ | ||
| Testing: t, | ||
| TerraformDir: restoredTerraformDir, | ||
| Prefix: "pg-backup", | ||
| ResourceGroup: resourceGroup, | ||
| }) | ||
|
|
||
| output, err := options.RunTestConsistency() | ||
| assert.Nil(t, err, "This should not have errored") | ||
| assert.NotNil(t, output, "Expected some output") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.