Skip to content

Commit 2095c3d

Browse files
chore: added missing examples and plugged test gaps (#384)
1 parent b36fe15 commit 2095c3d

File tree

16 files changed

+262
-74
lines changed

16 files changed

+262
-74
lines changed

.secrets.baseline

Lines changed: 1 addition & 1 deletion
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": "2025-01-27T10:25:29Z",
6+
"generated_at": "2025-02-05T07:22:24Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"

examples/backup-restore/README.MD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Restore from backup example
2+
3+
This example provides an end-to-end executable flow of how a Elasticsearch DB instance 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 restored ICD Elasticsearch database instance pointing to the lastest backup of the existing Elasticsearch database instance crn passed.
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
data "ibm_database_backups" "backup_database" {
14+
deployment_id = var.existing_database_crn
15+
}
16+
# New elasticsearch instance pointing to the backup instance
17+
module "restored_icd_elasticsearch" {
18+
source = "../.."
19+
resource_group_id = module.resource_group.resource_group_id
20+
name = "${var.prefix}-elasticsearch-restored"
21+
elasticsearch_version = var.elasticsearch_version
22+
region = var.region
23+
tags = var.resource_tags
24+
access_tags = var.access_tags
25+
member_host_flavor = "multitenant"
26+
backup_crn = data.ibm_database_backups.backup_database.backups[0].backup_id
27+
}

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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
25+
variable "resource_group" {
26+
type = string
27+
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
28+
default = null
29+
}
30+
31+
variable "resource_tags" {
32+
type = list(string)
33+
description = "Optional list of tags to be added to created resources"
34+
default = []
35+
}
36+
37+
variable "access_tags" {
38+
type = list(string)
39+
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"
40+
default = []
41+
}
42+
43+
variable "existing_database_crn" {
44+
type = string
45+
description = "The existing CRN of a backup resource to restore from."
46+
default = null
47+
}

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+
}

examples/basic/main.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ module "resource_group" {
1313
# Elasticsearch Instance
1414
##############################################################################
1515

16-
module "icd_elasticsearch" {
16+
module "database" {
1717
source = "../../"
1818
resource_group_id = module.resource_group.resource_group_id
19-
name = "${var.prefix}-elasticsearch"
19+
name = "${var.prefix}-data-store"
2020
region = var.region
2121
elasticsearch_version = var.elasticsearch_version
2222
tags = var.resource_tags
2323
access_tags = var.access_tags
24+
service_endpoints = var.service_endpoints
25+
member_host_flavor = var.member_host_flavor
2426
service_credential_names = {
2527
"elasticsearch_admin" : "Administrator",
2628
"elasticsearch_operator" : "Operator",
@@ -32,7 +34,7 @@ module "icd_elasticsearch" {
3234
# wait 60 secs to allow IAM credential access to kick in before configuring instance
3335
# without the wait, you can intermittently get "Error 401 (Unauthorized)"
3436
resource "time_sleep" "wait" {
35-
depends_on = [module.icd_elasticsearch]
37+
depends_on = [module.database]
3638
create_duration = "60s"
3739
}
3840

0 commit comments

Comments
 (0)