Skip to content

Commit

Permalink
update reference to conditional bucket, replace s3 bucket object
Browse files Browse the repository at this point in the history
  • Loading branch information
vchinnakotla committed Apr 12, 2022
1 parent aed862b commit 78f4552
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions bucket.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resource "aws_s3_bucket" "guard_duty_lists" {
}

resource "aws_s3_bucket_server_side_encryption_configuration" "guard_duty_lists_encryption" {
bucket = aws_s3_bucket.guard_duty_lists.bucket
bucket = aws_s3_bucket.guard_duty_lists.0.bucket

rule {
apply_server_side_encryption_by_default {
Expand All @@ -19,23 +19,23 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "guard_duty_lists_
}

resource "aws_s3_bucket_versioning" "guard_duty_lists_versioning" {
bucket = aws_s3_bucket.guard_duty_lists.bucket
bucket = aws_s3_bucket.guard_duty_lists.0.bucket

versioning_configuration {
status = "Enabled"
}
}

resource "aws_s3_bucket_logging" "guard_duty_lists_logging" {
bucket = aws_s3_bucket.guard_duty_lists.bucket
bucket = aws_s3_bucket.guard_duty_lists.0.bucket

target_bucket = data.aws_s3_bucket.log_bucket[0].id
target_prefix = "s3/guard_duty/"
}


data "aws_iam_policy_document" "guard_duty_lists" {
count = local.bucket_creation_count
count = local.bucket_creation_count
statement {
actions = [
"s3:*",
Expand Down
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource "aws_guardduty_detector" "master" {
enable = var.enable
}

resource "aws_s3_bucket_object" "MyThreatIntelSet" {
resource "aws_s3_object" "MyThreatIntelSet" {
count = var.threat_intel_list_path == "" ? 0 : 1
bucket = aws_s3_bucket.guard_duty_lists[0].id
key = "MyThreatIntelSet.txt"
Expand All @@ -15,11 +15,11 @@ resource "aws_guardduty_threatintelset" "MyThreatIntelSet" {
activate = var.threat_intel_set_active
detector_id = aws_guardduty_detector.master.id
format = var.threat_intel_set_format
location = "https://s3.amazonaws.com/${aws_s3_bucket_object.MyThreatIntelSet[0].bucket}/${aws_s3_bucket_object.MyThreatIntelSet[0].key}"
location = "https://s3.amazonaws.com/${aws_s3_object.MyThreatIntelSet[0].bucket}/${aws_s3_object.MyThreatIntelSet[0].key}"
name = "MyThreatIntelSet"
}

resource "aws_s3_bucket_object" "MyIPSet" {
resource "aws_s3_object" "MyIPSet" {
count = var.ip_set_list_path == "" ? 0 : 1
bucket = aws_s3_bucket.guard_duty_lists[0].id
key = "MyIPSet.txt"
Expand All @@ -32,7 +32,7 @@ resource "aws_guardduty_ipset" "MyIPSet" {
activate = var.ip_set_active
detector_id = aws_guardduty_detector.master.id
format = var.ip_set_format
location = "https://s3.amazonaws.com/${aws_s3_bucket_object.MyIPSet[0].bucket}/${aws_s3_bucket_object.MyIPSet[0].key}"
location = "https://s3.amazonaws.com/${aws_s3_object.MyIPSet[0].bucket}/${aws_s3_object.MyIPSet[0].key}"
name = "MyIPSet"
}

Expand Down
5 changes: 3 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

terraform {
required_version = ">= 0.13"
required_version = ">= 1.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
source = "hashicorp/aws"
version = ">= 4.0.0"
}
}
}

0 comments on commit 78f4552

Please sign in to comment.