Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions terraform/layer1-aws/examples/aws-s3-bucket-elastic-stack.tf

This file was deleted.

51 changes: 0 additions & 51 deletions terraform/layer1-aws/examples/aws-s3-bucket-gitlab-runner-cache.tf

This file was deleted.

46 changes: 40 additions & 6 deletions terraform/layer2-k8s/examples/eks-elk.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ locals {
repository = lookup(local.helm_charts[index(local.helm_charts.*.id, "elk")], "repository", null)
chart_version = lookup(local.helm_charts[index(local.helm_charts.*.id, "elk")], "version", null)
}
kibana_domain_name = "kibana-${local.domain_suffix}"
apm_domain_name = "apm-${local.domain_suffix}"
elastic_stack_bucket_name = data.terraform_remote_state.layer1-aws.outputs.elastic_stack_bucket_name
kibana_domain_name = "kibana-${local.domain_suffix}"
apm_domain_name = "apm-${local.domain_suffix}"
}

data "template_file" "elk" {
template = file("${path.module}/templates/elk-values.yaml")

vars = {
bucket_name = local.elastic_stack_bucket_name
bucket_name = aws_s3_bucket.elastic_stack.id
storage_class_name = kubernetes_storage_class.elk.id
snapshot_retention_days = var.elk_snapshot_retention_days
index_retention_days = var.elk_index_retention_days
Expand Down Expand Up @@ -136,6 +135,36 @@ resource "random_string" "kibana_password" {
upper = true
}

resource "aws_s3_bucket" "elastic_stack" {
bucket = "${local.name}-elastic-stack"
acl = "private"

server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
}
}
}

tags = {
Name = "${local.name}-elastic-stack"
Environment = local.env
}
}

resource "aws_s3_bucket_public_access_block" "elastic_stack_public_access_block" {
bucket = aws_s3_bucket.elastic_stack.id
# Block new public ACLs and uploading public objects
block_public_acls = true
# Retroactively remove public access granted through public ACLs
ignore_public_acls = true
# Block new public bucket policies
block_public_policy = true
# Retroactivley block public and cross-account access if bucket has public policies
restrict_public_buckets = true
}

module "aws_iam_elastic_stack" {
source = "../modules/aws-iam-user-with-policy"

Expand All @@ -152,7 +181,7 @@ module "aws_iam_elastic_stack" {
"s3:ListBucketVersions"
],
"Resource" : [
"arn:aws:s3:::${local.elastic_stack_bucket_name}"
"arn:aws:s3:::${aws_s3_bucket.elastic_stack.id}"
]
},
{
Expand All @@ -165,7 +194,7 @@ module "aws_iam_elastic_stack" {
"s3:ListMultipartUploadParts"
],
"Resource" : [
"arn:aws:s3:::${local.elastic_stack_bucket_name}/*"
"arn:aws:s3:::${aws_s3_bucket.elastic_stack.id}/*"
]
}
]
Expand All @@ -187,3 +216,8 @@ output "elasticsearch_elastic_password" {
sensitive = true
description = "Password of the superuser 'elastic'"
}

output "elastic_stack_bucket_name" {
value = aws_s3_bucket.elastic_stack.id
description = "Name of the bucket for ELKS snapshots"
}
59 changes: 52 additions & 7 deletions terraform/layer2-k8s/examples/eks-gitlab-runner.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ locals {
repository = lookup(local.helm_charts[index(local.helm_charts.*.id, "gitlab-runner")], "repository", null)
chart_version = lookup(local.helm_charts[index(local.helm_charts.*.id, "gitlab-runner")], "version", null)
}
gitlab_runner_cache_bucket_name = data.terraform_remote_state.layer1-aws.outputs.gitlab_runner_cache_bucket_name

gitlab_runner_template = templatefile("${path.module}/templates/gitlab-runner-values.tmpl",
gitlab_runner_template = templatefile("${path.module}/templates/gitlab-runner-values.yaml",
{
registration_token = local.gitlab_registration_token
namespace = module.ci_namespace.name
role_arn = module.aws_iam_gitlab_runner.role_arn
bucket_name = local.gitlab_runner_cache_bucket_name
bucket_name = aws_s3_bucket.gitlab_runner_cache.id
region = local.region
})

}

module "gitlab_runner_namespace" {
Expand All @@ -36,6 +33,49 @@ resource "helm_release" "gitlab_runner" {
]
}

resource "aws_s3_bucket" "gitlab_runner_cache" {
bucket = "${local.name}-gitlab-runner-cache"
acl = "private"

server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
}
}
}

lifecycle_rule {
id = "gitlab-runner-cache-lifecycle-rule"
enabled = true

tags = {
"rule" = "gitlab-runner-cache-lifecycle-rule"
}

expiration {
days = 120
}
}

tags = {
Name = "${local.name}-gitlab-runner-cache"
Environment = local.env
}
}

resource "aws_s3_bucket_public_access_block" "gitlab_runner_cache_public_access_block" {
bucket = aws_s3_bucket.gitlab_runner_cache.id
# Block new public ACLs and uploading public objects
block_public_acls = true
# Retroactively remove public access granted through public ACLs
ignore_public_acls = true
# Block new public bucket policies
block_public_policy = true
# Retroactivley block public and cross-account access if bucket has public policies
restrict_public_buckets = true
}

module "aws_iam_gitlab_runner" {
source = "../modules/aws-iam-eks-trusted"

Expand All @@ -58,10 +98,15 @@ module "aws_iam_gitlab_runner" {
"s3:*"
],
"Resource" : [
"arn:aws:s3:::${local.gitlab_runner_cache_bucket_name}",
"arn:aws:s3:::${local.gitlab_runner_cache_bucket_name}/*"
"arn:aws:s3:::${aws_s3_bucket.gitlab_runner_cache.id}",
"arn:aws:s3:::${aws_s3_bucket.gitlab_runner_cache.id}/*"
]
}
]
})
}

output "gitlab_runner_cache_bucket_name" {
value = aws_s3_bucket.gitlab_runner_cache.id
description = "Name of the s3 bucket for gitlab-runner cache"
}