Skip to content

Commit 3d7f248

Browse files
committed
added aws elasticserach module
1 parent c2c662f commit 3d7f248

File tree

7 files changed

+404
-7
lines changed

7 files changed

+404
-7
lines changed

EC2withJenkins/ec2_jenkins.tf

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11

22
resource "aws_instance" "ec2_jenkins" {
3-
ami = lookup(var.ami_id, var.region)
4-
instance_type = var.instance_type
5-
# subnet_id = aws_subnet.public_1.id
6-
3+
ami = "${lookup(var.ami_id, var.region)}"
4+
instance_type = "${var.instance_type}"
75
# Security group assign to instance
86
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
97

108
# key name
11-
key_name = var.key_name
9+
key_name = "${var.key_name}"
1210

1311
user_data = <<EOF
1412
#! /bin/bash
@@ -26,7 +24,7 @@ resource "aws_instance" "ec2_jenkins" {
2624
systemctl status jenkins
2725
systemctl enable jenkins
2826
29-
EOF
27+
EOF
3028

3129
tags = {
3230
Name = "Ec2-User-data"
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
provider "aws" {
2-
region = var.region
2+
region = "${var.region}"
3+
version = "~> 2.0"
34
}

terraform-aws-elasticsearch/README.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Terraform-Tutorial
2+
3+
4+
## Introduction
5+
6+
This module will create:
7+
- Elasticsearch cluster with the specified node count in aws
8+
- Elasticsearch domain policy that accepts a list of IAM role ARNs from which to permit management traffic to the cluster
9+
10+
__NOTE:__ To enable [zone awareness](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-managedomains.html#es-managedomains-zoneawareness) to deploy Elasticsearch nodes into two different Availability Zones, you need to set `zone_awareness_enabled` to `true`
11+
If you don't enable zone awareness, Amazon ES places an endpoint into only one subnet.
12+
13+
## Usage
14+
15+
Basic [example](examples/basic)
16+
17+
```hcl
18+
module "elasticsearch" {
19+
source = "git::https://github.com/easyawslearn/Terraform-Tutorial/terraform-aws-elasticsearch.git"
20+
domain_name = "eg"
21+
elasticsearch_version = "6.5"
22+
zone_awareness_enabled = "false"
23+
instance_type = "t2.small.elasticsearch"
24+
instance_count = 2
25+
encrypt_at_rest_enabled = true
26+
27+
advanced_options {
28+
"rest.action.multi.allow_explicit_index" = "true"
29+
}
30+
}
31+
```
32+
33+
34+
## Developing
35+
36+
- **Terraform**: v0.11.14
37+
- **Terraform Docs**: https://www.terraform.io/docs/configuration-0-11/index.html
38+
39+
40+
41+
## Inputs
42+
43+
| Name | Description | Type | Default | Required |
44+
|------|-------------|:----:|:-----:|:-----:|
45+
| advanced_options | Key-value string pairs to specify advanced configuration options | map(string) | `<map>` | no |
46+
| automated_snapshot_start_hour | Hour at which automated snapshots are taken, in UTC | number | `0` | no |
47+
| availability_zone_count | Number of Availability Zones for the domain to use. | number | `2` | no |
48+
| dedicated_master_count | Number of dedicated master nodes in the cluster | number | `0` | no |
49+
| dedicated_master_enabled | Indicates whether dedicated master nodes are enabled for the cluster | bool | `false` | no |
50+
| dedicated_master_type | Instance type of the dedicated master nodes in the cluster | string | `t2.small.elasticsearch` | no |
51+
| ebs_iops | The baseline input/output (I/O) performance of EBS volumes attached to data nodes. Applicable only for the Provisioned IOPS EBS volume type | number | `0` | no |
52+
| ebs_volume_size | EBS volumes for data storage in GB | number | `0` | no |
53+
| ebs_volume_type | Storage type of EBS volumes | string | `gp2` | no |
54+
| elasticsearch_version | Version of Elasticsearch to deploy | string | `6.5` | no |
55+
| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no |
56+
| encrypt_at_rest_enabled | Whether to enable encryption at rest | bool | `true` | no |
57+
| encrypt_at_rest_kms_key_id | The KMS key ID to encrypt the Elasticsearch domain with. If not specified, then it defaults to using the AWS/Elasticsearch service KMS key | string | `` | no |
58+
| instance_count | Number of data nodes in the cluster | number | `4` | no |
59+
| instance_type | Elasticsearch instance type for data nodes in the cluster | string | `t2.small.elasticsearch` | no |
60+
| log_publishing_application_cloudwatch_log_group_arn | ARN of the CloudWatch log group to which log for ES_APPLICATION_LOGS needs to be published | string | `` | no |
61+
| log_publishing_application_enabled | Specifies whether log publishing option for ES_APPLICATION_LOGS is enabled or not | bool | `false` | no |
62+
| log_publishing_index_cloudwatch_log_group_arn | ARN of the CloudWatch log group to which log for INDEX_SLOW_LOGS needs to be published | string | `` | no |
63+
| log_publishing_index_enabled | Specifies whether log publishing option for INDEX_SLOW_LOGS is enabled or not | bool | `false` | no |
64+
| log_publishing_search_cloudwatch_log_group_arn | ARN of the CloudWatch log group to which log for SEARCH_SLOW_LOGS needs to be published | string | `` | no |
65+
| log_publishing_search_enabled | Specifies whether log publishing option for SEARCH_SLOW_LOGS is enabled or not | bool | `false` | no |
66+
| domain_name | Name of the application | string | - | yes |
67+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
68+
| node_to_node_encryption_enabled | Whether to enable node-to-node encryption | bool | `false` | no |
69+
| zone_awareness_enabled | Enable zone awareness for Elasticsearch cluster | bool | `true` | no |
70+
71+
## Outputs
72+
73+
| Name | Description |
74+
|------|-------------|
75+
| domain_arn | ARN of the Elasticsearch domain |
76+
| domain_endpoint | Domain-specific endpoint used to submit index, search, and data upload requests |
77+
| domain_hostname | Elasticsearch domain hostname to submit index, search, and data upload requests |
78+
| domain_id | Unique identifier for the Elasticsearch domain |
79+
| elasticsearch_user_iam_role_arn | The ARN of the IAM role to allow access to Elasticsearch cluster |
80+
| elasticsearch_user_iam_role_name | The name of the IAM role to allow access to Elasticsearch cluster |
81+
82+
83+
84+
85+
86+
## References
87+
88+
For additional context, refer to some of these links.
89+
90+
- [What is Amazon Elasticsearch Service](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/what-is-amazon-elasticsearch-service.html) - Complete description of Amazon Elasticsearch Service
91+
- [Amazon Elasticsearch Service Access Control](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-ac.html) - Describes several ways of controlling access to Elasticsearch domains
92+
- [VPC Support for Amazon Elasticsearch Service Domains](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-vpc.html) - Describes Elasticsearch Service VPC Support and VPC architectures with and without zone awareness
93+
- [Creating and Configuring Amazon Elasticsearch Service Domains](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-createupdatedomains.html) - Provides a complete description on how to create and configure Amazon Elasticsearch Service (Amazon ES) domains
94+
- [Kibana and Logstash](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-kibana.html) - Describes some considerations for using Kibana and Logstash with Amazon Elasticsearch Service
95+
- [Control Access to Amazon Elasticsearch Service Domain](https://aws.amazon.com/blogs/security/how-to-control-access-to-your-amazon-elasticsearch-service-domain/) - Describes how to Control Access to Amazon Elasticsearch Service Domain
96+
- [elasticsearch_domain](https://www.terraform.io/docs/providers/aws/r/elasticsearch_domain.html) - Terraform reference documentation for the `elasticsearch_domain` resource
97+
- [elasticsearch_domain_policy](https://www.terraform.io/docs/providers/aws/r/elasticsearch_domain_policy.html) - Terraform reference documentation for the `elasticsearch_domain_policy` resource
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
# Role that pods can assume for access to elasticsearch and kibana
3+
resource "aws_iam_role" "elasticsearch_user" {
4+
name = "module.user_label.id"
5+
assume_role_policy = join("", data.aws_iam_policy_document.assume_role.*.json)
6+
description = "IAM Role to assume to access the Elasticsearch module.label.id cluster"
7+
8+
tags = {
9+
tag-key = "tag-value"
10+
}
11+
}
12+
13+
data "aws_iam_policy_document" "assume_role" {
14+
15+
statement {
16+
actions = [
17+
"sts:AssumeRole"
18+
]
19+
20+
principals {
21+
type = "Service"
22+
identifiers = ["ec2.amazonaws.com"]
23+
}
24+
25+
principals {
26+
type = "AWS"
27+
identifiers = ["*"]
28+
}
29+
30+
effect = "Allow"
31+
}
32+
}
33+
34+
35+
data "aws_iam_policy_document" "default" {
36+
37+
statement {
38+
actions = ["es:*", ]
39+
resources = [
40+
join("", aws_elasticsearch_domain.default.*.arn),
41+
"${join("", aws_elasticsearch_domain.default.*.arn)}/*"
42+
]
43+
44+
principals {
45+
type = "AWS"
46+
identifiers = ["*"]
47+
}
48+
}
49+
}
50+
51+
resource "aws_elasticsearch_domain_policy" "default" {
52+
domain_name = "easyaws"
53+
access_policies = join("", data.aws_iam_policy_document.default.*.json)
54+
}

terraform-aws-elasticsearch/main.tf

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
provider "aws" {
2+
region = var.region
3+
version = "~> 2.0"
4+
}
5+
6+
resource "aws_elasticsearch_domain" "default" {
7+
domain_name = var.domain_name
8+
elasticsearch_version = var.elasticsearch_version
9+
10+
advanced_options = var.advanced_options
11+
12+
ebs_options {
13+
ebs_enabled = var.ebs_volume_size > 0 ? true : false
14+
volume_size = var.ebs_volume_size
15+
volume_type = var.ebs_volume_type
16+
iops = var.ebs_iops
17+
}
18+
19+
encrypt_at_rest {
20+
enabled = var.encrypt_at_rest_enabled
21+
kms_key_id = var.encrypt_at_rest_kms_key_id
22+
}
23+
24+
cluster_config {
25+
instance_count = var.instance_count
26+
instance_type = var.instance_type
27+
dedicated_master_enabled = var.dedicated_master_enabled
28+
dedicated_master_count = var.dedicated_master_count
29+
dedicated_master_type = var.dedicated_master_type
30+
zone_awareness_enabled = var.zone_awareness_enabled
31+
32+
zone_awareness_config {
33+
availability_zone_count = var.availability_zone_count
34+
}
35+
}
36+
37+
node_to_node_encryption {
38+
enabled = var.node_to_node_encryption_enabled
39+
}
40+
41+
snapshot_options {
42+
automated_snapshot_start_hour = var.automated_snapshot_start_hour
43+
}
44+
45+
log_publishing_options {
46+
enabled = var.log_publishing_index_enabled
47+
log_type = "INDEX_SLOW_LOGS"
48+
cloudwatch_log_group_arn = var.log_publishing_index_cloudwatch_log_group_arn
49+
}
50+
51+
log_publishing_options {
52+
enabled = var.log_publishing_search_enabled
53+
log_type = "SEARCH_SLOW_LOGS"
54+
cloudwatch_log_group_arn = var.log_publishing_search_cloudwatch_log_group_arn
55+
}
56+
57+
log_publishing_options {
58+
enabled = var.log_publishing_application_enabled
59+
log_type = "ES_APPLICATION_LOGS"
60+
cloudwatch_log_group_arn = var.log_publishing_application_cloudwatch_log_group_arn
61+
}
62+
63+
tags = {
64+
Domain = "TestDomain"
65+
}
66+
67+
}

terraform-aws-elasticsearch/output.tf

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
output "domain_arn" {
3+
value = join("", aws_elasticsearch_domain.default.*.arn)
4+
description = "ARN of the Elasticsearch domain"
5+
}
6+
7+
output "domain_id" {
8+
value = join("", aws_elasticsearch_domain.default.*.domain_id)
9+
description = "Unique identifier for the Elasticsearch domain"
10+
}
11+
12+
output "domain_endpoint" {
13+
value = join("", aws_elasticsearch_domain.default.*.endpoint)
14+
description = "Domain-specific endpoint used to submit index, search, and data upload requests"
15+
}
16+
17+
output "elasticsearch_user_iam_role_name" {
18+
value = join(",", aws_iam_role.elasticsearch_user.*.name)
19+
description = "The name of the IAM role to allow access to Elasticsearch cluster"
20+
}
21+
22+
output "elasticsearch_user_iam_role_arn" {
23+
value = join(",", aws_iam_role.elasticsearch_user.*.arn)
24+
description = "The ARN of the IAM role to allow access to Elasticsearch cluster"
25+
}

0 commit comments

Comments
 (0)