From 2e11cb2d0f5e0db2f987682bd229f3af251bfc1a Mon Sep 17 00:00:00 2001 From: "linda.nasredin" Date: Mon, 5 Feb 2024 14:09:45 +0200 Subject: [PATCH] EDSF-535 Add prefix to tarball/agent s3 bucket --- modules/aws/db-with-agent/iam_role.tf | 2 +- modules/aws/db-with-agent/main.tf | 6 +++--- modules/aws/db-with-agent/userdata.tf | 4 ++-- modules/aws/sonar-base-instance/iam_role.tf | 2 +- modules/aws/sonar-base-instance/main.tf | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/aws/db-with-agent/iam_role.tf b/modules/aws/db-with-agent/iam_role.tf index 5f257d416..be89ee016 100644 --- a/modules/aws/db-with-agent/iam_role.tf +++ b/modules/aws/db-with-agent/iam_role.tf @@ -28,7 +28,7 @@ locals { "s3:GetObject" ] "Resource" : [ - "arn:aws:s3:::${local.s3_bucket_and_prefix}/*", + "arn:aws:s3:::${local.installation_s3_bucket_and_prefix}/*", ] } ] diff --git a/modules/aws/db-with-agent/main.tf b/modules/aws/db-with-agent/main.tf index 28ed4858d..31b3be71d 100644 --- a/modules/aws/db-with-agent/main.tf +++ b/modules/aws/db-with-agent/main.tf @@ -5,9 +5,9 @@ locals { db_type = var.db_type != null ? var.db_type : random_shuffle.db.result[0] os_type = var.os_type != null ? var.os_type : random_shuffle.os.result[0] - s3_object = var.binaries_location.s3_object != null ? var.binaries_location.s3_object : local.os_params[local.os_type].installation_filename - s3_key = var.binaries_location.s3_prefix != null ? join("/", [var.binaries_location.s3_prefix, local.s3_object]) : local.s3_object - s3_bucket_and_prefix = var.binaries_location.s3_prefix != null ? join("/", [var.binaries_location.s3_bucket, var.binaries_location.s3_prefix]) : var.binaries_location.s3_bucket + installation_s3_object = var.binaries_location.s3_object != null ? var.binaries_location.s3_object : local.os_params[local.os_type].installation_filename + installation_s3_key = var.binaries_location.s3_prefix != null ? join("/", [var.binaries_location.s3_prefix, local.installation_s3_object]) : local.installation_s3_object + installation_s3_bucket_and_prefix = var.binaries_location.s3_prefix != null ? join("/", [var.binaries_location.s3_bucket, var.binaries_location.s3_prefix]) : var.binaries_location.s3_bucket } resource "random_shuffle" "db" { diff --git a/modules/aws/db-with-agent/userdata.tf b/modules/aws/db-with-agent/userdata.tf index 2166b12f9..d84c03463 100644 --- a/modules/aws/db-with-agent/userdata.tf +++ b/modules/aws/db-with-agent/userdata.tf @@ -16,8 +16,8 @@ locals { sudo ./aws/install export PATH=$PATH:/usr/local/bin:/usr/local/bin echo "Downloading agent:" - INSTALLATION_FILE=${local.s3_object} - aws s3 cp s3://${var.binaries_location.s3_bucket}/${local.s3_key} . --region ${var.binaries_location.s3_region} + INSTALLATION_FILE=${local.installation_s3_object} + aws s3 cp s3://${var.binaries_location.s3_bucket}/${local.installation_s3_key} . --region ${var.binaries_location.s3_region} chmod +x ./"$INSTALLATION_FILE" echo "Installing agent:" ./"$INSTALLATION_FILE" -n -d ${local.agent_installation_dir} diff --git a/modules/aws/sonar-base-instance/iam_role.tf b/modules/aws/sonar-base-instance/iam_role.tf index be21a4f18..bd44df1ee 100644 --- a/modules/aws/sonar-base-instance/iam_role.tf +++ b/modules/aws/sonar-base-instance/iam_role.tf @@ -49,7 +49,7 @@ locals { "s3:GetObject" ] "Resource" : [ - "arn:aws:s3:::${local.s3_bucket_and_prefix}/*", + "arn:aws:s3:::${local.installation_s3_bucket_and_prefix}/*", ] } ] diff --git a/modules/aws/sonar-base-instance/main.tf b/modules/aws/sonar-base-instance/main.tf index fa917114d..cebec04a6 100644 --- a/modules/aws/sonar-base-instance/main.tf +++ b/modules/aws/sonar-base-instance/main.tf @@ -18,10 +18,10 @@ locals { [for sg in aws_security_group.dsf_base_sg : sg.id], var.security_group_ids) - # For example, if the binaries_location.s3_key is "path/to/file.zip", then the s3_bucket_prefix will be "path/to" - # If the binaries_location.s3_key is "file.zip", then the s3_bucket_prefix will be null - s3_bucket_prefix = try(regex("^(.*)/[^/]+", var.binaries_location.s3_key)[0], null) - s3_bucket_and_prefix = local.s3_bucket_prefix != null ? join("/", [var.binaries_location.s3_bucket, local.s3_bucket_prefix]) : var.binaries_location.s3_bucket + # For example, if the binaries_location.s3_key is "path/to/file.zip", then the installation_s3_prefix will be "path/to" + # If the binaries_location.s3_key is "file.zip", then the installation_s3_prefix will be null + installation_s3_prefix = try(regex("^(.*)/[^/]+", var.binaries_location.s3_key)[0], null) + installation_s3_bucket_and_prefix = local.installation_s3_prefix != null ? join("/", [var.binaries_location.s3_bucket, local.installation_s3_prefix]) : var.binaries_location.s3_bucket } resource "aws_eip" "dsf_instance_eip" {