Skip to content

Commit 32a34ec

Browse files
feat: added missing examples and plugged test gaps
1 parent 54cf5c5 commit 32a34ec

File tree

12 files changed

+144
-8
lines changed

12 files changed

+144
-8
lines changed

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2024-12-09T17:04:45Z",
6+
"generated_at": "2025-01-09T06:09:34Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -82,7 +82,7 @@
8282
"hashed_secret": "33da8d0e8af2efc260f01d8e5edfcc5c5aba44ad",
8383
"is_secret": true,
8484
"is_verified": false,
85-
"line_number": 35,
85+
"line_number": 36,
8686
"type": "Secret Keyword",
8787
"verified_result": null
8888
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [Basic example with index creation and updates to cluster-wide settings](./examples/basic)
1717
* [Complete example with autoscaling, BYOK encryption and service credentials creation](./examples/complete)
1818
* [Financial Services Cloud profile example with autoscaling enabled](./examples/fscloud)
19+
* [Restore from backup example](./examples/backup-restore)
1920
* [Contributing](#contributing)
2021
<!-- END OVERVIEW HOOK -->
2122

examples/backup-restore/README.MD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Restore from backup example
2+
3+
This example provides an end-to-end executable flow of how a Elasticsearch DB can be created from a backup instance. This example uses the IBM Cloud terraform provider to:
4+
5+
- Create a new resource group if one is not passed in.
6+
- Create a new ICD Elasticsearch database instance if no existing backup crn is provided.
7+
- Create a restored ICD Elasticsearch database instance pointing to the backup of the first instance.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ibmcloud_api_key": $VALIDATION_APIKEY,
3+
"region": "us-south",
4+
"resource_tags": $TAGS,
5+
"prefix": $PREFIX
6+
}

examples/backup-restore/main.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
##############################################################################
2+
# Resource Group
3+
##############################################################################
4+
5+
module "resource_group" {
6+
source = "terraform-ibm-modules/resource-group/ibm"
7+
version = "1.1.6"
8+
# if an existing resource group is not set (null) create a new one using prefix
9+
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
10+
existing_resource_group_name = var.resource_group
11+
}
12+
13+
14+
data "ibm_database_backups" "backup_database" {
15+
deployment_id = var.elasticsearch_db_backup_crn
16+
}
17+
# New elasticsearch instance pointing to the backup instance
18+
module "restored_icd_elasticsearch" {
19+
source = "../.."
20+
resource_group_id = module.resource_group.resource_group_id
21+
name = "${var.prefix}-elasticsearch-restored"
22+
elasticsearch_version = var.elasticsearch_version
23+
region = var.region
24+
tags = var.resource_tags
25+
access_tags = var.access_tags
26+
member_host_flavor = "multitenant"
27+
backup_crn = data.ibm_database_backups.backup_database.backups[0].backup_id
28+
}

examples/backup-restore/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
##############################################################################
2+
# Outputs
3+
##############################################################################
4+
output "restored_icd_elasticsearch_id" {
5+
description = "Restored elasticsearch instance id"
6+
value = module.restored_icd_elasticsearch.id
7+
}
8+
9+
output "restored_icd_elasticsearch_version" {
10+
description = "Restored elasticsearch instance version"
11+
value = module.restored_icd_elasticsearch.version
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "ibm" {
2+
ibmcloud_api_key = var.ibmcloud_api_key
3+
region = var.region
4+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
variable "ibmcloud_api_key" {
2+
type = string
3+
description = "The IBM Cloud API Key"
4+
sensitive = true
5+
}
6+
7+
variable "region" {
8+
type = string
9+
description = "Region to provision all resources created by this example."
10+
default = "us-south"
11+
}
12+
13+
variable "prefix" {
14+
type = string
15+
description = "Prefix to append to all resources created by this example"
16+
default = "backup"
17+
}
18+
19+
variable "elasticsearch_version" {
20+
type = string
21+
description = "Version of the elasticsearch instance. If no value passed, the current ICD preferred version is used."
22+
default = null
23+
}
24+
variable "resource_group" {
25+
type = string
26+
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
27+
default = null
28+
}
29+
30+
variable "resource_tags" {
31+
type = list(string)
32+
description = "Optional list of tags to be added to created resources"
33+
default = []
34+
}
35+
36+
variable "access_tags" {
37+
type = list(string)
38+
description = "A list of access tags to apply to the elasticsearch instance created by the module, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial for more details"
39+
default = []
40+
}
41+
42+
variable "elasticsearch_db_backup_crn" {
43+
type = string
44+
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."
45+
default = null
46+
}

examples/backup-restore/version.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_version = ">= 1.3.0"
3+
required_providers {
4+
# Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main
5+
# module's version.tf (basic example), and 1 example that will always use the latest provider version (complete example).
6+
ibm = {
7+
source = "IBM-Cloud/ibm"
8+
version = ">=1.70.0, <2.0.0"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)