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 ef07100
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ This module will create lambda for new relic log ingestion.

## Modules

No modules.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_lambda_newrelic_resource_bucket"></a> [lambda\_newrelic\_resource\_bucket](#module\_lambda\_newrelic\_resource\_bucket) | github.com/terraform-aws-modules/terraform-aws-s3-bucket | v4.1.2 |

## Resources

Expand All @@ -29,8 +31,7 @@ No modules.
| [aws_cloudformation_stack.newrelic_lambda_integration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack) | resource |
| [aws_cloudformation_stack.newrelic_license_key_secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack) | resource |
| [aws_cloudformation_stack.newrelic_log_ingestion](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack) | resource |
| [aws_s3_bucket.lambda_newrelic_resource](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [aws_s3_bucket_object.newrelic_log_ingestion_zip](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object) | resource |
| [aws_s3_object.newrelic_log_ingestion_zip](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource |
| [random_string.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
| [aws_ssm_parameter.newrelic_account_number](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssm_parameter) | data source |
| [aws_ssm_parameter.newrelic_license_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssm_parameter) | data source |
Expand All @@ -42,6 +43,7 @@ No modules.
| <a name="input_newrelic_account_number"></a> [newrelic\_account\_number](#input\_newrelic\_account\_number) | n/a | `string` | `""` | no |
| <a name="input_newrelic_license_key_path"></a> [newrelic\_license\_key\_path](#input\_newrelic\_license\_key\_path) | n/a | `string` | `""` | no |
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | `"eu-central-1"` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Map of custom tags for the provisioned resources | `map(string)` | `{}` | no |

## Outputs

Expand Down
23 changes: 13 additions & 10 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,15 @@ resource "random_string" "this" {
special = false
}

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

tags = {
Name = "Created by Terraform"
}
bucket_prefix = "lambda-newrelic-resource"
}

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 +31,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 ef07100

Please sign in to comment.