Skip to content

Commit f5961de

Browse files
committed
feat: Add support for OpenSearch serverless as separate sub-module
1 parent d1b068e commit f5961de

File tree

21 files changed

+651
-6
lines changed

21 files changed

+651
-6
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ repos:
33
rev: v1.83.6
44
hooks:
55
- id: terraform_fmt
6+
- id: terraform_wrapper_module_for_each
67
- id: terraform_validate
78
- id: terraform_docs
89
args:

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Terraform module which creates AWS OpenSearch resources.
44

5+
[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
6+
57
## Usage
68

79
See [`examples`](https://github.com/terraform-aws-modules/terraform-aws-opensearch/tree/master/examples) directory for working examples to reference:
@@ -29,13 +31,13 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
2931
| Name | Version |
3032
|------|---------|
3133
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
32-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.29 |
34+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.24 |
3335

3436
## Providers
3537

3638
| Name | Version |
3739
|------|---------|
38-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.29 |
40+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.24 |
3941

4042
## Modules
4143

examples/complete/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ Note that this example may create resources which will incur monetary charges on
2222
| Name | Version |
2323
|------|---------|
2424
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
25-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.29 |
25+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.24 |
2626

2727
## Providers
2828

2929
| Name | Version |
3030
|------|---------|
31-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.29 |
31+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.24 |
3232

3333
## Modules
3434

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.29"
7+
version = ">= 5.24"
88
}
99
}
1010
}

modules/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# AWS OpenSearch Terraform sub-module(s)

modules/serverless/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# AWS OpenSearch Serverless Terraform module
2+
3+
Terraform module which creates AWS OpenSearch Serverless resources.
4+
5+
## Usage
6+
7+
See [`examples`](https://github.com/terraform-aws-modules/terraform-aws-opensearch/tree/master/examples) directory for working examples to reference:
8+
9+
```hcl
10+
module "opensearch_serverless" {
11+
source = "terraform-aws-modules/opensearch/aws//modules/serverless"
12+
13+
tags = {
14+
Terraform = "true"
15+
Environment = "dev"
16+
}
17+
}
18+
```
19+
20+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
21+
## Requirements
22+
23+
| Name | Version |
24+
|------|---------|
25+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
26+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.24 |
27+
28+
## Providers
29+
30+
| Name | Version |
31+
|------|---------|
32+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.24 |
33+
34+
## Modules
35+
36+
No modules.
37+
38+
## Resources
39+
40+
| Name | Type |
41+
|------|------|
42+
| [aws_opensearchserverless_collection.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/opensearchserverless_collection) | resource |
43+
| [aws_opensearchserverless_security_policy.encryption](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/opensearchserverless_security_policy) | resource |
44+
| [aws_opensearchserverless_security_policy.network](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/opensearchserverless_security_policy) | resource |
45+
46+
## Inputs
47+
48+
| Name | Description | Type | Default | Required |
49+
|------|-------------|------|---------|:--------:|
50+
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no |
51+
| <a name="input_create_encryption_policy"></a> [create\_encryption\_policy](#input\_create\_encryption\_policy) | Determines whether an encryption policy will be created | `bool` | `true` | no |
52+
| <a name="input_create_network_policy"></a> [create\_network\_policy](#input\_create\_network\_policy) | Determines whether an network policy will be created | `bool` | `true` | no |
53+
| <a name="input_description"></a> [description](#input\_description) | Description of the collection | `string` | `null` | no |
54+
| <a name="input_encryption_security_policy"></a> [encryption\_security\_policy](#input\_encryption\_security\_policy) | Encryption security policy to apply to the collection - this is merged with the default policy provided | `any` | `{}` | no |
55+
| <a name="input_encryption_security_policy_description"></a> [encryption\_security\_policy\_description](#input\_encryption\_security\_policy\_description) | Description of the encryption security policy | `string` | `null` | no |
56+
| <a name="input_encryption_security_policy_name"></a> [encryption\_security\_policy\_name](#input\_encryption\_security\_policy\_name) | Name of the encryption security policy | `string` | `null` | no |
57+
| <a name="input_name"></a> [name](#input\_name) | Name of the collection | `string` | `""` | no |
58+
| <a name="input_network_security_policy"></a> [network\_security\_policy](#input\_network\_security\_policy) | Network security policy to apply to the collection - this is merged with the default policy provided | `any` | `{}` | no |
59+
| <a name="input_network_security_policy_description"></a> [network\_security\_policy\_description](#input\_network\_security\_policy\_description) | Description of the network security policy | `string` | `null` | no |
60+
| <a name="input_network_security_policy_name"></a> [network\_security\_policy\_name](#input\_network\_security\_policy\_name) | Name of the network security policy | `string` | `null` | no |
61+
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
62+
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Create and delete timeout configurations for the collection | `map(string)` | `{}` | no |
63+
| <a name="input_type"></a> [type](#input\_type) | Type of collection. One of `SEARCH`, `TIMESERIES`, or `VECTORSEARCH`. Defaults to `TIMESERIES` | `string` | `null` | no |
64+
65+
## Outputs
66+
67+
| Name | Description |
68+
|------|-------------|
69+
| <a name="output_arn"></a> [arn](#output\_arn) | Amazon Resource Name (ARN) of the collection |
70+
| <a name="output_dashboard_endpoint"></a> [dashboard\_endpoint](#output\_dashboard\_endpoint) | Collection-specific endpoint used to access OpenSearch Dashboards |
71+
| <a name="output_encryption_security_policy"></a> [encryption\_security\_policy](#output\_encryption\_security\_policy) | The JSON policy document of the security policy |
72+
| <a name="output_encryption_security_policy_version"></a> [encryption\_security\_policy\_version](#output\_encryption\_security\_policy\_version) | The version of the security policy |
73+
| <a name="output_endpoint"></a> [endpoint](#output\_endpoint) | Collection-specific endpoint used to submit index, search, and data upload requests to an OpenSearch Serverless collection |
74+
| <a name="output_id"></a> [id](#output\_id) | Unique identifier for the collection |
75+
| <a name="output_kms_key_arn"></a> [kms\_key\_arn](#output\_kms\_key\_arn) | The ARN of the Amazon Web Services KMS key used to encrypt the collection |
76+
| <a name="output_network_security_policy"></a> [network\_security\_policy](#output\_network\_security\_policy) | The JSON policy document of the security policy |
77+
| <a name="output_network_security_policy_version"></a> [network\_security\_policy\_version](#output\_network\_security\_policy\_version) | The version of the security policy |
78+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
79+
80+
## License
81+
82+
Apache-2.0 Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-aws-opensearch/blob/master/LICENSE).

modules/serverless/main.tf

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
################################################################################
2+
# Collection
3+
################################################################################
4+
5+
resource "aws_opensearchserverless_collection" "this" {
6+
count = var.create ? 1 : 0
7+
8+
description = var.description
9+
name = var.name
10+
type = var.type
11+
12+
tags = var.tags
13+
14+
timeouts {
15+
create = try(var.timeouts.delete, null)
16+
delete = try(var.timeouts.delete, null)
17+
}
18+
19+
depends_on = [
20+
aws_opensearchserverless_security_policy.encryption
21+
]
22+
}
23+
24+
################################################################################
25+
# Security Policy - Encryption
26+
################################################################################
27+
28+
resource "aws_opensearchserverless_security_policy" "encryption" {
29+
count = var.create && var.create_encryption_policy ? 1 : 0
30+
31+
description = coalesce(var.encryption_security_policy_description, "Encryption policy for ${var.name} collection")
32+
name = coalesce(var.encryption_security_policy_name, "${var.name}-encryption")
33+
policy = jsonencode(merge(
34+
{
35+
Rules = [
36+
{
37+
Resource = ["collection/${var.name}"]
38+
ResourceType = "collection"
39+
}
40+
]
41+
AWSOwnedKey = true
42+
},
43+
var.encryption_security_policy
44+
))
45+
type = "encryption"
46+
}
47+
48+
################################################################################
49+
# Security Policy - Network
50+
################################################################################
51+
52+
resource "aws_opensearchserverless_security_policy" "network" {
53+
count = var.create && var.create_network_policy ? 1 : 0
54+
55+
description = coalesce(var.network_security_policy_description, "Newtwork policy for ${var.name} collection")
56+
name = coalesce(var.network_security_policy_name, "${var.name}-network")
57+
policy = jsonencode(merge(
58+
{
59+
Rules = [
60+
{
61+
Resource = ["collection/${var.name}"]
62+
ResourceType = "collection"
63+
}
64+
]
65+
AllowFromPublic = true
66+
},
67+
var.network_security_policy
68+
))
69+
type = "network"
70+
}

modules/serverless/outputs.tf

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
################################################################################
2+
# Collection
3+
################################################################################
4+
5+
output "arn" {
6+
description = "Amazon Resource Name (ARN) of the collection"
7+
value = try(aws_opensearchserverless_collection.this[0].arn, null)
8+
}
9+
10+
output "endpoint" {
11+
description = "Collection-specific endpoint used to submit index, search, and data upload requests to an OpenSearch Serverless collection"
12+
value = try(aws_opensearchserverless_collection.this[0].collection_endpoint, null)
13+
}
14+
15+
output "dashboard_endpoint" {
16+
description = "Collection-specific endpoint used to access OpenSearch Dashboards"
17+
value = try(aws_opensearchserverless_collection.this[0].dashboard_endpoint, null)
18+
}
19+
20+
output "kms_key_arn" {
21+
description = "The ARN of the Amazon Web Services KMS key used to encrypt the collection"
22+
value = try(aws_opensearchserverless_collection.this[0].kms_key_arn, null)
23+
}
24+
25+
output "id" {
26+
description = "Unique identifier for the collection"
27+
value = try(aws_opensearchserverless_collection.this[0].id, null)
28+
}
29+
30+
################################################################################
31+
# Security Policy - Encryption
32+
################################################################################
33+
34+
output "encryption_security_policy_version" {
35+
description = "The version of the security policy"
36+
value = try(aws_opensearchserverless_security_policy.encryption[0].policy_version, null)
37+
}
38+
39+
output "encryption_security_policy" {
40+
description = "The JSON policy document of the security policy"
41+
value = try(aws_opensearchserverless_security_policy.encryption[0].policy, null)
42+
}
43+
44+
################################################################################
45+
# Security Policy - Network
46+
################################################################################
47+
48+
output "network_security_policy_version" {
49+
description = "The version of the security policy"
50+
value = try(aws_opensearchserverless_security_policy.network[0].policy_version, null)
51+
}
52+
53+
output "network_security_policy" {
54+
description = "The JSON policy document of the security policy"
55+
value = try(aws_opensearchserverless_security_policy.network[0].policy, null)
56+
}

modules/serverless/variables.tf

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
variable "create" {
2+
description = "Determines whether resources will be created (affects all resources)"
3+
type = bool
4+
default = true
5+
}
6+
7+
variable "tags" {
8+
description = "A map of tags to add to all resources"
9+
type = map(string)
10+
default = {}
11+
}
12+
13+
################################################################################
14+
# Collection
15+
################################################################################
16+
17+
variable "description" {
18+
description = "Description of the collection"
19+
type = string
20+
default = null
21+
}
22+
23+
variable "name" {
24+
description = "Name of the collection"
25+
type = string
26+
default = ""
27+
}
28+
29+
variable "type" {
30+
description = "Type of collection. One of `SEARCH`, `TIMESERIES`, or `VECTORSEARCH`. Defaults to `TIMESERIES`"
31+
type = string
32+
default = null
33+
}
34+
35+
variable "timeouts" {
36+
description = "Create and delete timeout configurations for the collection"
37+
type = map(string)
38+
default = {}
39+
}
40+
41+
################################################################################
42+
# Security Policy - Encryption
43+
################################################################################
44+
45+
variable "create_encryption_policy" {
46+
description = "Determines whether an encryption policy will be created"
47+
type = bool
48+
default = true
49+
}
50+
51+
variable "encryption_security_policy_description" {
52+
description = "Description of the encryption security policy"
53+
type = string
54+
default = null
55+
}
56+
57+
variable "encryption_security_policy_name" {
58+
description = "Name of the encryption security policy"
59+
type = string
60+
default = null
61+
}
62+
63+
variable "encryption_security_policy" {
64+
description = "Encryption security policy to apply to the collection - this is merged with the default policy provided"
65+
type = any
66+
default = {}
67+
}
68+
69+
################################################################################
70+
# Security Policy - Network
71+
################################################################################
72+
73+
variable "create_network_policy" {
74+
description = "Determines whether an network policy will be created"
75+
type = bool
76+
default = true
77+
}
78+
79+
variable "network_security_policy_description" {
80+
description = "Description of the network security policy"
81+
type = string
82+
default = null
83+
}
84+
85+
variable "network_security_policy_name" {
86+
description = "Name of the network security policy"
87+
type = string
88+
default = null
89+
}
90+
91+
variable "network_security_policy" {
92+
description = "Network security policy to apply to the collection - this is merged with the default policy provided"
93+
type = any
94+
default = {}
95+
}

modules/serverless/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.24"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)