ClusterNest Provider
Setup ClusterNest services with Terraform using this provider. For details about each API parameter refer to the API Reference documentation
Authentication
Section titled “Authentication”You will need to configure the provider with your email and an app password (your regular account password will not work). Generate an app password from the MFA settings page.
NOTE: An app password is always required - the provider authenticates via a machine-to-machine token exchange that does not support interactive/MFA login.
terraform {
required_providers {
clusternest = {
source = "tf.clusternest.com/clusternest/clusternest"
version = "~> 1.0"
}
}
}
provider "clusternest" {
email = "[email protected]"
app_password = "app-password"
}
It’s best practice not to store the credentials in plain text. As an alternative, the provider can source the email and app password from CLUSTERNEST_EMAIL & CLUSTERNEST_APP_PASSWORD environment variables respectively. If you choose to do this, you can omit the email and app_password variables from the configuration block above.
terraform {
required_providers {
clusternest = {
source = "tf.clusternest.com/clusternest/clusternest"
version = "~> 1.0"
}
}
}
provider "clusternest" {}
Example Usage
Section titled “Example Usage”Example Terraform code that launches an OpenSearch cluster and creates an index template and ISM policy for fluent-bit.
terraform {
required_providers {
clusternest = {
source = "tf.clusternest.com/clusternest/clusternest"
version = "~> 1.0"
}
opensearch = {
source = "opensearch-project/opensearch"
version = ">= 2.2.0"
}
}
}
provider "clusternest" {
email = "[email protected]"
app_password = "app-password"
}
resource "clusternest_opensearch" "test" {
name = "test"
tier = "standard"
organization_id = 123
}
data "clusternest_opensearch_credentials" "test" {
cluster_id = clusternest_opensearch.test.id
}
provider "opensearch" {
url = clusternest_opensearch.test.url
username = data.clusternest_opensearch_credentials.test.username
password = data.clusternest_opensearch_credentials.test.password
}
# Create an index template
resource "opensearch_index_template" "fluent-bit" {
name = "fluent-bit"
body = <<EOF
{
"index_patterns": [
"fluent-bit-*"
],
"template": {
"settings": {
"index": {
"number_of_shards": "1",
"number_of_replicas": "1",
"plugins" : {
"index_state_management": {
"rollover_alias": "fluent-bit"
}
}
}
}
},
"_meta": {
"flow": "simple"
},
"priority": 1
}
EOF
}
# Create an ISM policy
resource "opensearch_ism_policy" "rotation" {
policy_id = "rotation"
body = <<EOF
{
"policy": {
"description": "A sample description of the policy",
"default_state": "hot",
"states": [
{
"name": "hot",
"actions": [
{
"retry": {
"count": 3,
"backoff": "exponential",
"delay": "1m"
},
"replica_count": {
"number_of_replicas": 1
}
}
],
"transitions": [
{
"state_name": "rollover",
"conditions": {
"min_index_age": "1d"
}
}
]
},
{
"name": "rollover",
"actions": [
{
"retry": {
"count": 3,
"backoff": "exponential",
"delay": "1m"
},
"rollover": {
"min_doc_count": 5
}
}
],
"transitions": [
{
"state_name": "delete",
"conditions": {
"min_index_age": "30d"
}
}
]
},
{
"name": "delete",
"actions": [
{
"retry": {
"count": 3,
"backoff": "exponential",
"delay": "1m"
},
"delete": {}
}
],
"transitions": []
}
],
"ism_template": [
{
"index_patterns": [
"fluent-bit-*"
],
"priority": 1
}
]
}
}
EOF
}
# resource "opensearch_ism_policy_mapping" "fluent-bit" {
# policy_id = opensearch_ism_policy.rotation.policy_id
# indexes = "fluent-bit-*"
# }
# Create the initial index
resource "opensearch_index" "fluent-bit-000001" {
name = "fluent-bit-000001"
number_of_shards = 1
number_of_replicas = 1
rollover_alias = "fluent-bit"
aliases = <<EOF
{
"fluent-bit": {
"is_write_index": false
}
}
EOF
}
Schema
Section titled “Schema”Required
Section titled “Required”app_password(String, Sensitive) App password generated from the MFA settings page. Your regular account password will not work.email(String) Email address of the account. Can also be set with the CLUSTERNEST_EMAIL environment variable.
Optional
Section titled “Optional”api_base_url(String) Base URL of the API. Can also be set with the CLUSTERNEST_URL environment variable.