Skip to content

Commit

Permalink
serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
Arunsai14 committed Nov 14, 2024
1 parent 961c798 commit e36890f
Show file tree
Hide file tree
Showing 29 changed files with 1,891 additions and 661 deletions.
221 changes: 79 additions & 142 deletions README.md

Large diffs are not rendered by default.

47 changes: 5 additions & 42 deletions example/public/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Terraform module example for supporting AWS OpenSearch.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_opensearch"></a> [opensearch](#module\_opensearch) | ../.. | n/a |
| <a name="module_opensearch_serverless"></a> [opensearch\_serverless](#module\_opensearch\_serverless) | ../.. | n/a |
| <a name="module_tags"></a> [tags](#module\_tags) | sourcefuse/arc-tags/aws | 1.2.6 |

## Resources
Expand All @@ -34,12 +35,12 @@ Terraform module example for supporting AWS OpenSearch.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | OpenSearch or Elasticsearch engine version | `string` | `"OpenSearch_1.0"` | no |
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | OpenSearch or Elasticsearch engine version | `string` | `"OpenSearch_2.15"` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `"dev"` | no |
| <a name="input_instance_count"></a> [instance\_count](#input\_instance\_count) | Number of instances in the cluster | `number` | `2` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Instance type for the OpenSearch domain | `string` | `"m5.large.search"` | no |
| <a name="input_name"></a> [name](#input\_name) | Name of the OpenSearch domain | `string` | n/a | yes |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace of the project, i.e. refarch | `string` | `"arc"` | no |
| <a name="input_project_name"></a> [project\_name](#input\_project\_name) | Project name | `string` | `"sourcefuse"` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS region | `string` | `"us-east-1"` | no |

## Outputs
Expand All @@ -49,44 +50,6 @@ Terraform module example for supporting AWS OpenSearch.
| <a name="output_opensearch_domain_arn"></a> [opensearch\_domain\_arn](#output\_opensearch\_domain\_arn) | The ARN of the OpenSearch domain. |
| <a name="output_opensearch_domain_endpoint"></a> [opensearch\_domain\_endpoint](#output\_opensearch\_domain\_endpoint) | The endpoint of the OpenSearch domain. |
| <a name="output_opensearch_domain_id"></a> [opensearch\_domain\_id](#output\_opensearch\_domain\_id) | The unique identifier for the OpenSearch domain. |
| <a name="output_opensearch_serverless_arn"></a> [opensearch\_serverless\_arn](#output\_opensearch\_serverless\_arn) | The ARN of the OpenSearch Serverless collection. |
| <a name="output_opensearch_serverless_collection_id"></a> [opensearch\_serverless\_collection\_id](#output\_opensearch\_serverless\_collection\_id) | The ID of the OpenSearch Serverless collection |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.7 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.64 |

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_opensearch"></a> [opensearch](#module\_opensearch) | ../.. | n/a |
| <a name="module_tags"></a> [tags](#module\_tags) | sourcefuse/arc-tags/aws | 1.2.6 |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_access_policy"></a> [access\_policy](#input\_access\_policy) | Access policy for the OpenSearch domain | `string` | n/a | yes |
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | OpenSearch or Elasticsearch engine version | `string` | `"OpenSearch_1.0"` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `"dev"` | no |
| <a name="input_instance_count"></a> [instance\_count](#input\_instance\_count) | Number of instances in the cluster | `number` | `2` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Instance type for the OpenSearch domain | `string` | `"m4.large.search"` | no |
| <a name="input_project_name"></a> [project\_name](#input\_project\_name) | Project name | `string` | `"sourcefuse"` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS region | `string` | `"us-east-1"` | no |

## Outputs

No outputs.
<!-- END_TF_DOCS -->
1 change: 1 addition & 0 deletions example/public/dev.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ project_name = "arc"
engine_version = "OpenSearch_2.15"
instance_type = "m5.large.search"
instance_count = 2
name = "arc-opensearch"
22 changes: 22 additions & 0 deletions example/public/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
locals {

## OpenSearch Serverless Domain
access_policy_rules = [
{
resource_type = "collection"
resource = ["collection/${var.name}"]
permissions = ["aoss:CreateCollectionItems", "aoss:DeleteCollectionItems", "aoss:UpdateCollectionItems", "aoss:DescribeCollectionItems"]
},
]

data_lifecycle_policy_rules = [
{
indexes = ["index1", "index2"]
retention = "30d"
},
{
indexes = ["index3"]
retention = "24h"
}
]
}
30 changes: 24 additions & 6 deletions example/public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ terraform {
}
}

data "aws_caller_identity" "current" {}

provider "aws" {
region = var.region
Expand All @@ -29,18 +30,16 @@ module "tags" {
}
}

data "aws_caller_identity" "current" {}

################################################################################
## opensearch
############################### opensearch #################################
################################################################################
module "opensearch" {
source = "../.."

namespace = var.namespace
environment = var.environment

name = "${var.project_name}-${var.environment}-opensearch"
namespace = var.namespace
environment = var.environment
name = var.name
engine_version = var.engine_version
instance_type = var.instance_type
instance_count = var.instance_count
Expand All @@ -49,3 +48,22 @@ module "opensearch" {
advanced_security_enabled = true
tags = module.tags.tags
}


##################################################
######## OpenSearch Serverless Domain ###########
##################################################

module "opensearch_serverless" {
source = "../.."

enable_opensearch_serverless = true
namespace = var.namespace
environment = var.environment
name = var.name
enable_public_access = true
data_lifecycle_policy_rules = local.data_lifecycle_policy_rules
access_policy_rules = local.access_policy_rules

tags = module.tags.tags
}
14 changes: 0 additions & 14 deletions example/public/output.tf

This file was deleted.

28 changes: 28 additions & 0 deletions example/public/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
output "opensearch_domain_endpoint" {
description = "The endpoint of the OpenSearch domain."
value = module.opensearch.opensearch_domain_endpoint
}

output "opensearch_domain_arn" {
description = "The ARN of the OpenSearch domain."
value = module.opensearch.opensearch_domain_arn
}

output "opensearch_domain_id" {
description = "The unique identifier for the OpenSearch domain."
value = trimprefix(module.opensearch.opensearch_domain_id, "${data.aws_caller_identity.current.account_id}/")
}

###############################################
## Outputs for OpenSearch Serverless Module
###############################################

output "opensearch_serverless_arn" {
description = "The ARN of the OpenSearch Serverless collection."
value = module.opensearch_serverless.opensearch_serverless_collection_arn
}

output "opensearch_serverless_collection_id" {
description = "The ID of the OpenSearch Serverless collection"
value = module.opensearch_serverless.opensearch_serverless_collection_id
}
12 changes: 5 additions & 7 deletions example/public/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ variable "region" {
default = "us-east-1" # Change as needed
}

variable "project_name" {
type = string
default = "sourcefuse"
description = "Project name"
}

variable "environment" {
type = string
default = "dev"
Expand All @@ -22,11 +16,15 @@ variable "namespace" {
default = "arc"
}

variable "name" {
description = "Name of the OpenSearch domain"
type = string
}

variable "engine_version" {
description = "OpenSearch or Elasticsearch engine version"
type = string
default = "OpenSearch_1.0"
default = "OpenSearch_2.15"
}

variable "instance_type" {
Expand Down
64 changes: 5 additions & 59 deletions example/vpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Terraform module example for supporting AWS OpenSearch.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_opensearch"></a> [opensearch](#module\_opensearch) | ../.. | n/a |
| <a name="module_opensearch_serverless"></a> [opensearch\_serverless](#module\_opensearch\_serverless) | ../.. | n/a |
| <a name="module_tags"></a> [tags](#module\_tags) | sourcefuse/arc-tags/aws | 1.2.6 |

## Resources
Expand All @@ -37,12 +37,12 @@ Terraform module example for supporting AWS OpenSearch.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | OpenSearch or Elasticsearch engine version | `string` | `"OpenSearch_1.0"` | no |
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | OpenSearch or Elasticsearch engine version | `string` | `"OpenSearch_2.15"` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `"dev"` | no |
| <a name="input_instance_count"></a> [instance\_count](#input\_instance\_count) | Number of instances in the cluster | `number` | `2` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Instance type for the OpenSearch domain | `string` | `"m5.large.search"` | no |
| <a name="input_name"></a> [name](#input\_name) | Name of the OpenSearch domain | `string` | n/a | yes |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace of the project, i.e. arc | `string` | `"arc"` | no |
| <a name="input_project_name"></a> [project\_name](#input\_project\_name) | Project name | `string` | `"sourcefuse"` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS region | `string` | `"us-east-1"` | no |
| <a name="input_subnet_names"></a> [subnet\_names](#input\_subnet\_names) | List of subnet names to lookup | `list(string)` | <pre>[<br> "arc-poc-private-subnet-private-us-east-1a",<br> "arc-poc-private-subnet-private-us-east-1b"<br>]</pre> | no |
| <a name="input_vpc_name"></a> [vpc\_name](#input\_vpc\_name) | Name of the VPC to add the resources | `string` | `"arc-poc-vpc"` | no |
Expand All @@ -51,60 +51,6 @@ Terraform module example for supporting AWS OpenSearch.

| Name | Description |
|------|-------------|
| <a name="output_opensearch_domain_arn"></a> [opensearch\_domain\_arn](#output\_opensearch\_domain\_arn) | The ARN of the OpenSearch domain. |
| <a name="output_opensearch_domain_endpoint"></a> [opensearch\_domain\_endpoint](#output\_opensearch\_domain\_endpoint) | The endpoint of the OpenSearch domain. |
| <a name="output_opensearch_domain_id"></a> [opensearch\_domain\_id](#output\_opensearch\_domain\_id) | The unique identifier for the OpenSearch domain. |
| <a name="output_opensearch_serverless_arn"></a> [opensearch\_serverless\_arn](#output\_opensearch\_serverless\_arn) | The ARN of the OpenSearch Serverless collection. |
| <a name="output_opensearch_serverless_collection_id"></a> [opensearch\_serverless\_collection\_id](#output\_opensearch\_serverless\_collection\_id) | The ID of the OpenSearch Serverless collection |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.7 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.64 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.74.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_opensearch"></a> [opensearch](#module\_opensearch) | ../.. | n/a |
| <a name="module_tags"></a> [tags](#module\_tags) | sourcefuse/arc-tags/aws | 1.2.6 |

## Resources

| Name | Type |
|------|------|
| [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_subnet.private](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet) | data source |
| [aws_subnets.private](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnets) | data source |
| [aws_vpc.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_access_policy"></a> [access\_policy](#input\_access\_policy) | Access policy for the OpenSearch domain | `string` | n/a | yes |
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | Name of the OpenSearch domain | `string` | n/a | yes |
| <a name="input_egress_rules"></a> [egress\_rules](#input\_egress\_rules) | A list of egress rules for the security group. | <pre>list(object({<br> from_port = number<br> to_port = number<br> protocol = string<br> cidr_blocks = list(string)<br> }))</pre> | n/a | yes |
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | OpenSearch or Elasticsearch engine version | `string` | `"OpenSearch_1.0"` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `"dev"` | no |
| <a name="input_ingress_rules"></a> [ingress\_rules](#input\_ingress\_rules) | A list of ingress rules for the security group. | <pre>list(object({<br> from_port = number<br> to_port = number<br> protocol = string<br> cidr_blocks = list(string)<br> }))</pre> | n/a | yes |
| <a name="input_instance_count"></a> [instance\_count](#input\_instance\_count) | Number of instances in the cluster | `number` | `2` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Instance type for the OpenSearch domain | `string` | `"m4.large.search"` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace of the project, i.e. arc | `string` | `"arc"` | no |
| <a name="input_project_name"></a> [project\_name](#input\_project\_name) | Project name | `string` | `"sourcefuse"` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS region | `string` | `"us-east-1"` | no |
| <a name="input_subnet_names"></a> [subnet\_names](#input\_subnet\_names) | List of subnet names to lookup | `list(string)` | <pre>[<br> "arc-poc-private-subnet-private-us-east-1a",<br> "arc-poc-private-subnet-private-us-east-1b"<br>]</pre> | no |
| <a name="input_vpc_name"></a> [vpc\_name](#input\_vpc\_name) | Name of the VPC to add the resources | `string` | `"arc-poc-vpc"` | no |

## Outputs

No outputs.
<!-- END_TF_DOCS -->
3 changes: 3 additions & 0 deletions example/vpc/dev.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ project_name = "arc"
engine_version = "OpenSearch_2.15"
instance_type = "m5.large.search"
instance_count = 2
name = "arc-opensearch"
vpc_name = "vpc-test"
subnet_names = ["test_subnet-0", "test_subnet-1"]
20 changes: 20 additions & 0 deletions example/vpc/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,24 @@ locals {
cidr_blocks = ["0.0.0.0/0"]
}
]

## OpenSearch Serverless Domain
access_policy_rules = [
{
resource_type = "collection"
resource = ["collection/${var.name}"]
permissions = ["aoss:CreateCollectionItems", "aoss:DeleteCollectionItems", "aoss:UpdateCollectionItems", "aoss:DescribeCollectionItems"]
},
]

data_lifecycle_policy_rules = [
{
indexes = ["index1", "index2"]
retention = "30d"
},
{
indexes = ["index3"]
retention = "24h"
}
]
}
Loading

0 comments on commit e36890f

Please sign in to comment.