Skip to content

Commit 5b260ae

Browse files
Add var.create_elasticsearch_user_role (#161)
* Add var.create_elasticsearch_user_role * Update README.md * Modify count condition for assume_role resource * Use splat expression for default policy document * Run make github/init
1 parent dda8ef4 commit 5b260ae

File tree

7 files changed

+37
-7
lines changed

7 files changed

+37
-7
lines changed

.github/mergify.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ pull_request_rules:
44
- name: "approve automated PRs that have passed checks"
55
conditions:
66
- "author~=^(cloudpossebot|renovate\\[bot\\])$"
7-
- "base=master"
87
- "-closed"
98
- "head~=^(auto-update|renovate)/.*"
109
- "check-success=test/bats"
1110
- "check-success=test/readme"
1211
- "check-success=test/terratest"
1312
- "check-success=validate-codeowners"
13+
- or:
14+
- "base=master"
15+
- "base=main"
16+
- "base~=^release/v\\d{1,2}$"
17+
1418
actions:
1519
review:
1620
type: "APPROVE"
@@ -20,7 +24,6 @@ pull_request_rules:
2024
- name: "merge automated PRs when approved and tests pass"
2125
conditions:
2226
- "author~=^(cloudpossebot|renovate\\[bot\\])$"
23-
- "base=master"
2427
- "-closed"
2528
- "head~=^(auto-update|renovate)/.*"
2629
- "check-success=test/bats"
@@ -30,6 +33,11 @@ pull_request_rules:
3033
- "#approved-reviews-by>=1"
3134
- "#changes-requested-reviews-by=0"
3235
- "#commented-reviews-by=0"
36+
- or:
37+
- "base=master"
38+
- "base=main"
39+
- "base~=^release/v\\d{1,2}$"
40+
3341
actions:
3442
merge:
3543
method: "squash"
@@ -50,7 +58,10 @@ pull_request_rules:
5058

5159
- name: "remove outdated reviews"
5260
conditions:
53-
- "base=master"
61+
- or:
62+
- "base=master"
63+
- "base=main"
64+
- "base~=^release/v\\d{1,2}$"
5465
actions:
5566
dismiss_reviews:
5667
changes_requested: true

.github/renovate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"config:base",
44
":preserveSemverRanges"
55
],
6+
"baseBranches": ["main", "master", "/^release\\/v\\d{1,2}$/"],
67
"labels": ["auto-update"],
78
"dependencyDashboardAutoclose": true,
89
"enabledManagers": ["terraform"],

.github/workflows/auto-context.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v2
1313

14+
- name: Find default branch name
15+
id: defaultBranch
16+
shell: bash
17+
env:
18+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
19+
run: |
20+
default_branch=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name)
21+
echo "defaultBranch=${default_branch}" >> "$GITHUB_OUTPUT"
22+
printf "defaultBranchRef.name=%s\n" "${default_branch}"
23+
1424
- name: Update context.tf
1525
shell: bash
1626
id: update
@@ -50,7 +60,7 @@ jobs:
5060
To support all the features of the `context` interface.
5161
5262
branch: auto-update/context.tf
53-
base: master
63+
base: ${{ steps.defaultBranch.outputs.defaultBranch }}
5464
delete-branch: true
5565
labels: |
5666
auto-update

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ Available targets:
224224
| <a name="input_cognito_user_pool_id"></a> [cognito\_user\_pool\_id](#input\_cognito\_user\_pool\_id) | The ID of the Cognito User Pool to use | `string` | `""` | no |
225225
| <a name="input_cold_storage_enabled"></a> [cold\_storage\_enabled](#input\_cold\_storage\_enabled) | Enables cold storage support. | `bool` | `false` | no |
226226
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
227+
| <a name="input_create_elasticsearch_user_role"></a> [create\_elasticsearch\_user\_role](#input\_create\_elasticsearch\_user\_role) | Whether to create an IAM role for Users/EC2 to assume to access the Elasticsearch domain. Set it to `false` if you already manage access through other means. | `bool` | `true` | no |
227228
| <a name="input_create_iam_service_linked_role"></a> [create\_iam\_service\_linked\_role](#input\_create\_iam\_service\_linked\_role) | Whether to create `AWSServiceRoleForAmazonElasticsearchService` service-linked role. Set it to `false` if you already have an ElasticSearch cluster created in the AWS account and AWSServiceRoleForAmazonElasticsearchService already exists. See https://github.com/terraform-providers/terraform-provider-aws/issues/5218 for more info | `bool` | `true` | no |
228229
| <a name="input_create_security_group"></a> [create\_security\_group](#input\_create\_security\_group) | Whether to create a dedicated security group for the Elasticsearch domain. Set it to `false` if you already have security groups that you want to attach to the domain and specify them in the `security_groups` variable. | `bool` | `true` | no |
229230
| <a name="input_custom_endpoint"></a> [custom\_endpoint](#input\_custom\_endpoint) | Fully qualified domain for custom endpoint. | `string` | `""` | no |

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
| <a name="input_cognito_user_pool_id"></a> [cognito\_user\_pool\_id](#input\_cognito\_user\_pool\_id) | The ID of the Cognito User Pool to use | `string` | `""` | no |
6262
| <a name="input_cold_storage_enabled"></a> [cold\_storage\_enabled](#input\_cold\_storage\_enabled) | Enables cold storage support. | `bool` | `false` | no |
6363
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
64+
| <a name="input_create_elasticsearch_user_role"></a> [create\_elasticsearch\_user\_role](#input\_create\_elasticsearch\_user\_role) | Whether to create an IAM role for Users/EC2 to assume to access the Elasticsearch domain. Set it to `false` if you already manage access through other means. | `bool` | `true` | no |
6465
| <a name="input_create_iam_service_linked_role"></a> [create\_iam\_service\_linked\_role](#input\_create\_iam\_service\_linked\_role) | Whether to create `AWSServiceRoleForAmazonElasticsearchService` service-linked role. Set it to `false` if you already have an ElasticSearch cluster created in the AWS account and AWSServiceRoleForAmazonElasticsearchService already exists. See https://github.com/terraform-providers/terraform-provider-aws/issues/5218 for more info | `bool` | `true` | no |
6566
| <a name="input_create_security_group"></a> [create\_security\_group](#input\_create\_security\_group) | Whether to create a dedicated security group for the Elasticsearch domain. Set it to `false` if you already have security groups that you want to attach to the domain and specify them in the `security_groups` variable. | `bool` | `true` | no |
6667
| <a name="input_custom_endpoint"></a> [custom\_endpoint](#input\_custom\_endpoint) | Fully qualified domain for custom endpoint. | `string` | `""` | no |

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ resource "aws_iam_service_linked_role" "default" {
7070

7171
# Role that pods can assume for access to elasticsearch and kibana
7272
resource "aws_iam_role" "elasticsearch_user" {
73-
count = module.this.enabled && (length(var.iam_authorizing_role_arns) > 0 || length(var.iam_role_arns) > 0) ? 1 : 0
73+
count = module.this.enabled && var.create_elasticsearch_user_role && (length(var.iam_authorizing_role_arns) > 0 || length(var.iam_role_arns) > 0) ? 1 : 0
7474
name = module.user_label.id
7575
assume_role_policy = join("", data.aws_iam_policy_document.assume_role.*.json)
7676
description = "IAM Role to assume to access the Elasticsearch ${module.this.id} cluster"
@@ -82,7 +82,7 @@ resource "aws_iam_role" "elasticsearch_user" {
8282
}
8383

8484
data "aws_iam_policy_document" "assume_role" {
85-
count = module.this.enabled && (length(var.iam_authorizing_role_arns) > 0 || length(var.iam_role_arns) > 0) ? 1 : 0
85+
count = module.this.enabled && var.create_elasticsearch_user_role && (length(var.iam_authorizing_role_arns) > 0 || length(var.iam_role_arns) > 0) ? 1 : 0
8686

8787
statement {
8888
actions = [
@@ -255,7 +255,7 @@ data "aws_iam_policy_document" "default" {
255255

256256
principals {
257257
type = "AWS"
258-
identifiers = distinct(compact(concat(var.iam_role_arns, aws_iam_role.elasticsearch_user.*.arn)))
258+
identifiers = distinct(compact(concat(var.iam_role_arns, aws_iam_role.elasticsearch_user[*].arn)))
259259
}
260260
}
261261

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ variable "create_security_group" {
1010
description = "Whether to create a dedicated security group for the Elasticsearch domain. Set it to `false` if you already have security groups that you want to attach to the domain and specify them in the `security_groups` variable."
1111
}
1212

13+
variable "create_elasticsearch_user_role" {
14+
type = bool
15+
default = true
16+
description = "Whether to create an IAM role for Users/EC2 to assume to access the Elasticsearch domain. Set it to `false` if you already manage access through other means."
17+
}
18+
1319
variable "ingress_port_range_start" {
1420
type = number
1521
default = 0

0 commit comments

Comments
 (0)