Skip to content

Commit

Permalink
PLT-921 - Move the bucket to a separate module
Browse files Browse the repository at this point in the history
* move the bucket to a module to ensure latest security features enabled, as mentioned by security hub
* move aws_s3_bucket_object to aws_s3_object as it is deprecated
  • Loading branch information
Engerim committed Aug 20, 2024
1 parent 8260593 commit ea7442f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
22 changes: 13 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
moved {
from = aws_s3_bucket.lambda_newrelic_resource
to = module.lambda_newrelic_resource_bucket.aws_s3_bucket.this[0]
}

locals {
name = "newrelic-${random_string.this.result}"
}
Expand All @@ -7,17 +12,16 @@ resource "random_string" "this" {
special = false
}

resource "aws_s3_bucket" "lambda_newrelic_resource" {
module "lambda_newrelic_resource_bucket" {
source = "github.com/terraform-aws-modules/terraform-aws-s3-bucket?ref=v4.1.2"
tags = var.tags

bucket_prefix = "lambda-newrelic-resource"
acl = "private"

tags = {
Name = "Created by Terraform"
}
}

resource "aws_s3_bucket_object" "newrelic_log_ingestion_zip" {
bucket = aws_s3_bucket.lambda_newrelic_resource.id
resource "aws_s3_object" "newrelic_log_ingestion_zip" {
bucket = module.lambda_newrelic_resource_bucket.s3_bucket_id
key = "newrelic-log-ingestion-2.3.5.zip"
source = "${path.module}/newrelic-log-ingestion.zip"
etag = filemd5("${path.module}/newrelic-log-ingestion.zip")
Expand All @@ -28,8 +32,8 @@ resource "aws_cloudformation_stack" "newrelic_log_ingestion" {
template_body = file("${path.module}/newrelic-log-ingestion.yaml")
capabilities = ["CAPABILITY_AUTO_EXPAND", "CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
parameters = {
Bucket = aws_s3_bucket.lambda_newrelic_resource.id
Key = aws_s3_bucket_object.newrelic_log_ingestion_zip.id
Bucket = module.lambda_newrelic_resource_bucket.s3_bucket_id
Key = aws_s3_object.newrelic_log_ingestion_zip.id
NewRelicLicenseKey = data.aws_ssm_parameter.newrelic_license_key.value
}
}
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ variable "region" {
type = string
default = "eu-central-1"
}

variable "tags" {
description = "Map of custom tags for the provisioned resources"
type = map(string)
default = {}
}

0 comments on commit ea7442f

Please sign in to comment.