Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to US2 region and add option to use custom coralogix arn[CDS-552] #78

Merged
merged 3 commits into from
Aug 17, 2023
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
19 changes: 19 additions & 0 deletions examples/s3-archive/varibales.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ variable "bypass_valid_region" {
default = false
}

variable "custom_coralogix_arn" {
type = string
description = "In case that you want to use a custom coralogix arn enter the aws account id that you want to use"
default = ""
}

variable "coralogix_arn_mapping" {
type = map(string)
default = {
"eu-west-1" = "625240141681"
"eu-north-1" = "625240141681"
"ap-southeast-1" = "625240141681"
"ap-south-1" = "625240141681"
"us-east-2" = "625240141681"
"us-west-2" = "739076534691"
"default" = "625240141681"
}
}

variable "logs_bucket_name" {
type = string
description = "The name of the S3 bucket to create for the logs archive (Leave empty if not needed)"
Expand Down
4 changes: 2 additions & 2 deletions modules/provisioning/s3-archive/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

## S3-archive

### version / full date
* [Update/Bug fix] massage describe the changes
### 0.0.1 / 17.8.2023
* [Update] Add support to US2, and add an option to use custom coalogix arn.
26 changes: 13 additions & 13 deletions modules/provisioning/s3-archive/main.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
locals {
is_logs_bucket_name_empty = var.logs_bucket_name != ""
is_logs_bucket_name_empty = var.logs_bucket_name != ""
is_metrics_bucket_name_empty = var.metrics_bucket_name != ""
is_same_bucket_name = var.logs_bucket_name == var.metrics_bucket_name
is_valid_region = contains(["eu-west-1", "eu-north-1", "ap-southeast-1", "ap-south-1", "us-east-2"], var.coralogix_region) && data.aws_region.current.name == var.coralogix_region
is_valid_region = contains(["eu-west-1", "eu-north-1", "ap-southeast-1", "ap-south-1", "us-east-2", "us-west-2"], var.coralogix_region) && data.aws_region.current.name == var.coralogix_region

logs_validations = local.is_logs_bucket_name_empty && !local.is_same_bucket_name && (local.is_valid_region || var.bypass_valid_region)
metrics_validations = local.is_metrics_bucket_name_empty && !local.is_same_bucket_name && (local.is_valid_region || var.bypass_valid_region)
kms_logs_validation = local.logs_validations && var.logs_kms_arn != "" && contains(split(":", var.logs_kms_arn), var.coralogix_region)
kms_metrics_validation = local.metrics_validations && var.metrics_kms_arn != "" && contains(split(":", var.metrics_kms_arn), var.coralogix_region)
coralogix_arn = "arn:aws:iam::625240141681:root"
logs_validations = local.is_logs_bucket_name_empty && !local.is_same_bucket_name && (local.is_valid_region || var.bypass_valid_region)
metrics_validations = local.is_metrics_bucket_name_empty && !local.is_same_bucket_name && (local.is_valid_region || var.bypass_valid_region)
kms_logs_validation = local.logs_validations && var.logs_kms_arn != "" && contains(split(":", var.logs_kms_arn), var.coralogix_region)
kms_metrics_validation = local.metrics_validations && var.metrics_kms_arn != "" && contains(split(":", var.metrics_kms_arn), var.coralogix_region)
coralogix_arn = var.custom_coralogix_arn != "" ? "arn:aws:iam::${var.custom_coralogix_arn}:root" : var.bypass_valid_region == true ? "arn:aws:iam::${var.coralogix_arn_mapping["default"]}:root" : "arn:aws:iam::${var.coralogix_arn_mapping[var.coralogix_region]}:root"
}

data "aws_region" "current" {}
Expand Down Expand Up @@ -80,12 +80,12 @@ resource "aws_s3_bucket_policy" "metrics_bucket_policy" {
AWS = local.coralogix_arn
}
Action = [
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
"s3:DeleteObject",
"s3:PutObjectTagging",
"s3:GetObjectTagging"
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
"s3:DeleteObject",
"s3:PutObjectTagging",
"s3:GetObjectTagging"
]
Resource = [
aws_s3_bucket.metrics_bucket_name[count.index].arn,
Expand Down
6 changes: 3 additions & 3 deletions modules/provisioning/s3-archive/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ output "bucket_name_same" {
}

output "wrong_region" {
value = local.is_valid_region ? "" : "You tried to configure the bucket in a region that is not supported, or you are not in the region that you specified"
value = local.is_valid_region ? "" : "You tried to configure the bucket in a region that is not supported, or you are not in the region that you specified"
}

output "logs_kms_problem" {
value = var.logs_kms_arn == "" || contains(split(":", var.logs_kms_arn), var.coralogix_region) ? "" : "The KMS that you specified for logs is not in the same region as your coralogix_region"
value = var.logs_kms_arn == "" || contains(split(":", var.logs_kms_arn), var.coralogix_region) ? "" : "The KMS that you specified for logs is not in the same region as your coralogix_region"
}

output "metrics_kms_problem" {
value = var.metrics_kms_arn == "" || contains(split(":", var.metrics_kms_arn), var.coralogix_region) ? "" : "The KMS that you specified for metrics is not in the same region as your coralogix_region"
value = var.metrics_kms_arn == "" || contains(split(":", var.metrics_kms_arn), var.coralogix_region) ? "" : "The KMS that you specified for metrics is not in the same region as your coralogix_region"
}
19 changes: 19 additions & 0 deletions modules/provisioning/s3-archive/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ variable "bypass_valid_region" {
default = false
}

variable "custom_coralogix_arn" {
type = string
description = "In case that you want to use a custom coralogix arn enter the aws account id that you want to use"
default = ""
}

variable "coralogix_arn_mapping" {
type = map(string)
default = {
"eu-west-1" = "625240141681"
"eu-north-1" = "625240141681"
"ap-southeast-1" = "625240141681"
"ap-south-1" = "625240141681"
"us-east-2" = "625240141681"
"us-west-2" = "739076534691"
"default" = "625240141681"
}
}

variable "logs_bucket_name" {
type = string
description = "The name of the S3 bucket to create for the logs archive (Leave empty if not needed)"
Expand Down
Loading