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

change coralogix_region to aws_region and add validation[CDS-558] #79

Merged
merged 4 commits into from
Aug 20, 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
2 changes: 1 addition & 1 deletion examples/s3-archive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ provider "aws" {
module "s3-archive" {
source = "coralogix/aws/coralogix//modules/provisioning/s3-archive"

coralogix_region = "<your coralogix region>"
aws_region = "<your aws region>"
logs_bucket_name = "<your bucket name>"
metrics_bucket_name = "<your bucket name>"
}
Expand Down
6 changes: 3 additions & 3 deletions examples/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. Allow regions: eu-west-1, eu-north-1, ap-southeast-1, ap-south-1, us-east-2, us-west-2"
}

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.aws_region) ? "" : "The KMS that you specified for logs is not in the same region as your aws_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.aws_region) ? "" : "The KMS that you specified for metrics is not in the same region as your aws_region"
}
2 changes: 1 addition & 1 deletion examples/s3-archive/s3-archive.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ provider "aws" {
module "s3-archive" {
source = "coralogix/aws/coralogix//modules/provisioning/s3-archive"

coralogix_region = "<your coralogix region>"
aws_region = "<your aws region>"
logs_bucket_name = "<your bucket name>"
metrics_bucket_name = "<your bucket name>"
}
17 changes: 11 additions & 6 deletions examples/s3-archive/varibales.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
variable "coralogix_region" {
variable "aws_region" {
type = string
description = "The region that you want to create the buckets in"
description = "The AWS region that you want to create the S3 bucket, Must be the same as the AWS region where your coralogix account is set"
default = ""
validation {
condition = contains(["eu-west-1", "eu-north-1", "ap-southeast-1", "ap-south-1", "us-east-2", "us-west-2", ""], var.aws_region)
error_message = "The aws region must be one of these values: [eu-west-1, eu-north-1, ap-southeast-1, ap-south-1, us-east-2, us-west-2]."
}
}

variable "bypass_valid_region" {
type = bool
description = "Use to bypass the coralogix_region validation"
default = false
type = string
description = "Use to bypass the aws_region validation, enter the AWS region that you want to create the S3 bucket in. When using this variable leave aws_region empty"
default = ""
}

variable "custom_coralogix_arn" {
Expand All @@ -24,7 +29,7 @@ variable "coralogix_arn_mapping" {
"ap-south-1" = "625240141681"
"us-east-2" = "625240141681"
"us-west-2" = "739076534691"
"default" = "625240141681"
"" = "625240141681"
}
}

Expand Down
3 changes: 3 additions & 0 deletions modules/provisioning/s3-archive/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

## S3-archive

### 0.0.2 / 20.8.2023
* [Update] Change coralogix_region to aws_region and add validation to the variable.

### 0.0.1 / 17.8.2023
* [Update] Add support to US2, and add an option to use custom coalogix arn.
2 changes: 1 addition & 1 deletion modules/provisioning/s3-archive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The module can run only on the following regions eu-west-1,eu-north-1,ap-southea

| Variable name | Description | Type | Default | Required |
|------|-------------|------|------|:--------:|
| coralogix_region | The AWS Region where your [coralogix account](https://coralogix.com/docs/coralogix-domain/) is set, Note: Must be the same as the region you create the S3 bucket | `string` | n/a | :heavy_check_mark: |
| aws_region | The AWS region that you want to create the S3 bucket, Must be the same as the AWS region where your [coralogix account](https://coralogix.com/docs/coralogix-domain/) is set. Allowd values: eu-west-1, eu-north-1, ap-southeast-1, ap-south-1, us-east-2, us-west-2 | `string` | n/a | :heavy_check_mark: |
| logs_bucket_name | The name of the S3 bucket to create for the logs archive (Leave empty if not needed), Note: bucket name must follow [AWS naming rules](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html) | `string` | n/a | |
| metrics_bucket_name | The name of the S3 bucket to create for the metrics archive (Leave empty if not needed), Note: bucket name must follow [AWS naming rules](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html) | `string` | n/a | |
| logs_kms_arn | The arn of your kms for the logs bucket , Note: make sure that the kms is in the same region as your bucket | `string` | n/a | |
Expand Down
12 changes: 6 additions & 6 deletions modules/provisioning/s3-archive/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ locals {
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", "us-west-2"], var.coralogix_region) && data.aws_region.current.name == var.coralogix_region
is_valid_region = data.aws_region.current.name == var.aws_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 = 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"
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.aws_region)
kms_metrics_validation = local.metrics_validations && var.metrics_kms_arn != "" && contains(split(":", var.metrics_kms_arn), var.aws_region)
coralogix_arn = var.custom_coralogix_arn != "" ? "arn:aws:iam::${var.custom_coralogix_arn}:root" : var.bypass_valid_region != "" ? "arn:aws:iam::${var.coralogix_arn_mapping[""]}:root" : "arn:aws:iam::${var.coralogix_arn_mapping[var.aws_region]}:root"
}

data "aws_region" "current" {}
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. Allow regions: eu-west-1, eu-north-1, ap-southeast-1, ap-south-1, us-east-2, us-west-2"
}

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.aws_region) ? "" : "The KMS that you specified for logs is not in the same region as your aws_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.aws_region) ? "" : "The KMS that you specified for metrics is not in the same region as your aws_region"
}
17 changes: 11 additions & 6 deletions modules/provisioning/s3-archive/variables.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
variable "coralogix_region" {
variable "aws_region" {
type = string
description = "The region that you want to create the buckets in"
description = "The AWS region that you want to create the S3 bucket, Must be the same as the AWS region where your coralogix account is set"
default = ""
validation {
condition = contains(["eu-west-1", "eu-north-1", "ap-southeast-1", "ap-south-1", "us-east-2", "us-west-2", ""], var.aws_region)
error_message = "The aws region must be one of these values: [eu-west-1, eu-north-1, ap-southeast-1, ap-south-1, us-east-2, us-west-2]."
}
}

variable "bypass_valid_region" {
type = bool
description = "Use to bypass the coralogix_region validation"
default = false
type = string
description = "Use to bypass the aws_region validation, enter the AWS region that you want to create the S3 bucket in. When using this variable leave aws_region empty"
default = ""
}

variable "custom_coralogix_arn" {
Expand All @@ -24,7 +29,7 @@ variable "coralogix_arn_mapping" {
"ap-south-1" = "625240141681"
"us-east-2" = "625240141681"
"us-west-2" = "739076534691"
"default" = "625240141681"
"" = "625240141681"
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/provisioning/s3-archive.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ provider "aws" {
module "s3-archive" {
source = "../../modules/provisioning/s3-archive"

coralogix_region = "eu-west-1"
aws_region = "eu-west-1"
}
Loading