Skip to content

Commit 0468012

Browse files
authored
chore: added elasticsearch_index and elasticsearch_cluster_settings resource block to basic example (#246)
1 parent 18786b5 commit 0468012

File tree

10 files changed

+64
-50
lines changed

10 files changed

+64
-50
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* [Submodules](./modules)
1414
* [fscloud](./modules/fscloud)
1515
* [Examples](./examples)
16-
* [Basic example](./examples/basic)
17-
* [Complete example with autoscaling, BYOK encryption, service credentials creation, index creation and updates to cluster-wide settings](./examples/complete)
16+
* [Basic example with index creation and updates to cluster-wide settings](./examples/basic)
17+
* [Complete example with autoscaling, BYOK encryption and service credentials creation](./examples/complete)
1818
* [Financial Services Cloud profile example with autoscaling enabled](./examples/fscloud)
1919
* [Contributing](#contributing)
2020
<!-- END OVERVIEW HOOK -->

examples/basic/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Basic example
1+
# Basic example with index creation and updates to cluster-wide settings
22

33
An end-to-end example that creates the following infrastructure:
44

55
- A resource group, if one is not passed in.
66
- An ICD Elasticsearch database instance.
7+
- An Elasticsearch index
8+
- Updates to the cluster-wide settings

examples/basic/main.tf

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,33 @@ module "resource_group" {
1414
##############################################################################
1515

1616
module "icd_elasticsearch" {
17-
source = "../../"
18-
resource_group_id = module.resource_group.resource_group_id
19-
name = "${var.prefix}-elasticsearch"
20-
region = var.region
21-
elasticsearch_version = var.elasticsearch_version
22-
tags = var.resource_tags
23-
access_tags = var.access_tags
17+
source = "../../"
18+
resource_group_id = module.resource_group.resource_group_id
19+
name = "${var.prefix}-elasticsearch"
20+
region = var.region
21+
elasticsearch_version = var.elasticsearch_version
22+
tags = var.resource_tags
23+
access_tags = var.access_tags
24+
service_credential_names = var.service_credential_names
25+
}
26+
27+
# wait 15 secs to allow IAM credential access to kick in before configuring instance
28+
# without the wait, you can intermittently get "Error 401 (Unauthorized)"
29+
resource "time_sleep" "wait" {
30+
depends_on = [module.icd_elasticsearch]
31+
create_duration = "15s"
32+
}
33+
34+
resource "elasticsearch_index" "test" {
35+
depends_on = [time_sleep.wait]
36+
name = "terraform-test"
37+
number_of_shards = 1
38+
number_of_replicas = 1
39+
force_destroy = true
40+
}
41+
42+
resource "elasticsearch_cluster_settings" "global" {
43+
depends_on = [time_sleep.wait]
44+
cluster_max_shards_per_node = 10
45+
action_auto_create_index = "my-index-000001,index10,-index1*,+ind*"
2446
}

examples/basic/provider.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@ provider "ibm" {
22
ibmcloud_api_key = var.ibmcloud_api_key
33
region = var.region
44
}
5+
6+
provider "elasticsearch" {
7+
username = module.icd_elasticsearch.service_credentials_object.credentials["elasticsearch_admin"].username
8+
password = module.icd_elasticsearch.service_credentials_object.credentials["elasticsearch_admin"].password
9+
url = "https://${module.icd_elasticsearch.service_credentials_object.hostname}:${module.icd_elasticsearch.service_credentials_object.port}"
10+
cacert_file = base64decode(module.icd_elasticsearch.service_credentials_object.certificate)
11+
}

examples/basic/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,14 @@ variable "resource_tags" {
3939
description = "Optional list of tags to be added to created resources"
4040
default = []
4141
}
42+
43+
variable "service_credential_names" {
44+
description = "Map of name, role for service credentials that you want to create for the database"
45+
type = map(string)
46+
default = {
47+
"elasticsearch_admin" : "Administrator",
48+
"elasticsearch_operator" : "Operator",
49+
"elasticsearch_viewer" : "Viewer",
50+
"elasticsearch_editor" : "Editor",
51+
}
52+
}

examples/basic/version.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,16 @@ terraform {
66
source = "IBM-Cloud/ibm"
77
version = "1.65.0"
88
}
9+
# The elasticsearch provider is not actually required by the module itself, just this example, so OK to use ">=" here instead of locking into a version
10+
elasticsearch = {
11+
source = "phillbaker/elasticsearch"
12+
version = ">= 2.0.7"
13+
}
14+
15+
# The time provider is not actually required by the module itself, just this example, so OK to use ">=" here instead of locking into a version
16+
time = {
17+
source = "hashicorp/time"
18+
version = ">= 0.9.1"
19+
}
920
}
1021
}

examples/complete/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Complete example with autoscaling, BYOK encryption, service credentials creation, index creation and updates to cluster-wide settings
1+
# Complete example with autoscaling, BYOK encryption and service credentials creation
22

33
An end-to-end example that provisions the following infrastructure:
44

@@ -8,5 +8,3 @@ An end-to-end example that provisions the following infrastructure:
88
- A Secrets Manager instance if one is not passed in.
99
- Service credentials for the database instance.
1010
- A Secrets Manager secret containing the service credentials.
11-
- An Elasticsearch index
12-
- Updates to the cluster-wide settings

examples/complete/main.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,6 @@ module "icd_elasticsearch" {
6565
member_memory_mb = 4096
6666
}
6767

68-
# wait 15 secs to allow IAM credential access to kick in before configuring instance
69-
# without the wait, you can intermittently get "Error 401 (Unauthorized)"
70-
resource "time_sleep" "wait" {
71-
depends_on = [module.icd_elasticsearch]
72-
create_duration = "15s"
73-
}
74-
75-
resource "elasticsearch_index" "test" {
76-
depends_on = [time_sleep.wait]
77-
name = "terraform-test"
78-
number_of_shards = 1
79-
number_of_replicas = 1
80-
force_destroy = true
81-
}
82-
83-
resource "elasticsearch_cluster_settings" "global" {
84-
depends_on = [time_sleep.wait]
85-
cluster_max_shards_per_node = 10
86-
action_auto_create_index = "my-index-000001,index10,-index1*,+ind*"
87-
}
8868

8969
##############################################################################
9070
## Secrets Manager layer

examples/complete/provider.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,3 @@ provider "ibm" {
22
ibmcloud_api_key = var.ibmcloud_api_key
33
region = var.region
44
}
5-
6-
provider "elasticsearch" {
7-
username = module.icd_elasticsearch.service_credentials_object.credentials["es_admin"].username
8-
password = module.icd_elasticsearch.service_credentials_object.credentials["es_admin"].password
9-
url = "https://${module.icd_elasticsearch.service_credentials_object.hostname}:${module.icd_elasticsearch.service_credentials_object.port}"
10-
cacert_file = base64decode(module.icd_elasticsearch.service_credentials_object.certificate)
11-
}

examples/complete/version.tf

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,5 @@ terraform {
66
source = "IBM-Cloud/ibm"
77
version = ">=1.65.0, <2.0.0"
88
}
9-
# The elasticsearch provider is not actually required by the module itself, just this example, so OK to use ">=" here instead of locking into a version
10-
elasticsearch = {
11-
source = "phillbaker/elasticsearch"
12-
version = ">= 2.0.7"
13-
}
14-
# The time provider is not actually required by the module itself, just this example, so OK to use ">=" here instead of locking into a version
15-
time = {
16-
source = "hashicorp/time"
17-
version = ">= 0.9.1"
18-
}
199
}
2010
}

0 commit comments

Comments
 (0)