@@ -4,16 +4,15 @@ locals {
44 repository = lookup (local. helm_charts [index (local. helm_charts . * . id , " elk" )], " repository" , null )
55 chart_version = lookup (local. helm_charts [index (local. helm_charts . * . id , " elk" )], " version" , null )
66 }
7- kibana_domain_name = " kibana-${ local . domain_suffix } "
8- apm_domain_name = " apm-${ local . domain_suffix } "
9- elastic_stack_bucket_name = data. terraform_remote_state . layer1-aws . outputs . elastic_stack_bucket_name
7+ kibana_domain_name = " kibana-${ local . domain_suffix } "
8+ apm_domain_name = " apm-${ local . domain_suffix } "
109}
1110
1211data "template_file" "elk" {
1312 template = file (" ${ path . module } /templates/elk-values.yaml" )
1413
1514 vars = {
16- bucket_name = local.elastic_stack_bucket_name
15+ bucket_name = aws_s3_bucket.elastic_stack.id
1716 storage_class_name = kubernetes_storage_class.elk.id
1817 snapshot_retention_days = var.elk_snapshot_retention_days
1918 index_retention_days = var.elk_index_retention_days
@@ -136,6 +135,36 @@ resource "random_string" "kibana_password" {
136135 upper = true
137136}
138137
138+ resource "aws_s3_bucket" "elastic_stack" {
139+ bucket = " ${ local . name } -elastic-stack"
140+ acl = " private"
141+
142+ server_side_encryption_configuration {
143+ rule {
144+ apply_server_side_encryption_by_default {
145+ sse_algorithm = " aws:kms"
146+ }
147+ }
148+ }
149+
150+ tags = {
151+ Name = " ${ local . name } -elastic-stack"
152+ Environment = local.env
153+ }
154+ }
155+
156+ resource "aws_s3_bucket_public_access_block" "elastic_stack_public_access_block" {
157+ bucket = aws_s3_bucket. elastic_stack . id
158+ # Block new public ACLs and uploading public objects
159+ block_public_acls = true
160+ # Retroactively remove public access granted through public ACLs
161+ ignore_public_acls = true
162+ # Block new public bucket policies
163+ block_public_policy = true
164+ # Retroactivley block public and cross-account access if bucket has public policies
165+ restrict_public_buckets = true
166+ }
167+
139168module "aws_iam_elastic_stack" {
140169 source = " ../modules/aws-iam-user-with-policy"
141170
@@ -152,7 +181,7 @@ module "aws_iam_elastic_stack" {
152181 " s3:ListBucketVersions"
153182 ],
154183 " Resource" : [
155- " arn:aws:s3:::${ local . elastic_stack_bucket_name } "
184+ " arn:aws:s3:::${ aws_s3_bucket . elastic_stack . id } "
156185 ]
157186 },
158187 {
@@ -165,7 +194,7 @@ module "aws_iam_elastic_stack" {
165194 " s3:ListMultipartUploadParts"
166195 ],
167196 " Resource" : [
168- " arn:aws:s3:::${ local . elastic_stack_bucket_name } /*"
197+ " arn:aws:s3:::${ aws_s3_bucket . elastic_stack . id } /*"
169198 ]
170199 }
171200 ]
@@ -187,3 +216,8 @@ output "elasticsearch_elastic_password" {
187216 sensitive = true
188217 description = " Password of the superuser 'elastic'"
189218}
219+
220+ output "elastic_stack_bucket_name" {
221+ value = aws_s3_bucket. elastic_stack . id
222+ description = " Name of the bucket for ELKS snapshots"
223+ }
0 commit comments