Skip to content

Commit

Permalink
initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Feb 2, 2023
1 parent 544b4d9 commit 6977f16
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 119 deletions.
2 changes: 1 addition & 1 deletion common/version.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
locals {
_module_version = "2.2.7"
_module_version = "2.3.0"
}
7 changes: 2 additions & 5 deletions org-logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ module "org_logging" {
| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.66.0 |
| <a name="provider_local"></a> [local](#provider\_local) | n/a |
| <a name="provider_null"></a> [null](#provider\_null) | n/a |
| <a name="provider_template"></a> [template](#provider\_template) | n/a |

## Modules

Expand All @@ -149,6 +147,7 @@ No modules.
| [aws_s3_bucket_policy.policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
| [aws_s3_bucket_public_access_block.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
| [aws_s3_bucket_server_side_encryption_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
| [aws_s3_bucket_versioning.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_versioning) | resource |
| [aws_sns_topic.logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
| [aws_sns_topic_policy.logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_policy) | resource |
| [aws_sns_topic_subscription.additional_logging_sqs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription) | resource |
Expand All @@ -161,9 +160,7 @@ No modules.
| [aws_sqs_queue_policy.additional_logging_sqs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue_policy) | resource |
| [aws_sqs_queue_policy.logging_deadletter](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue_policy) | resource |
| [aws_sqs_queue_policy.logging_sqs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue_policy) | resource |
| [local_file.splunk_logging](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [null_resource.policy_delay](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [null_resource.splunk_logging](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [aws_arn.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_iam_policy_document.additional_logging_deadletter](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
Expand All @@ -176,9 +173,9 @@ No modules.
| [aws_iam_policy_document.logging_sqs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.logging_topic](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_kms_key.incoming_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/kms_key) | data source |
| [aws_organizations_organization.org](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organization) | data source |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
| [aws_regions.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/regions) | data source |
| [template_file.splunk_logging](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |

## Inputs

Expand Down
45 changes: 0 additions & 45 deletions org-logging/generate_splunk.cloudtrail.tf

This file was deleted.

6 changes: 2 additions & 4 deletions org-logging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ locals {
account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew"
partition = data.aws_arn.current.partition
account_alias = var.account_alias == "" ? "MISSING" : var.account_alias
organization_id = data.aws_organizations_organization.org.id

_name = var.name == null ? format("%v-%v", lookup(local._defaults["logging"], "name"), local.region) : var.name
name = var.enable_organization ? lookup(local._defaults["org_logging"], "name") : local._name
Expand All @@ -154,7 +155,4 @@ data "aws_kms_key" "incoming_key" {
key_id = var.kms_key_arn
}

# data "aws_organizations_organization" "org" {}



data "aws_organizations_organization" "org" {}
File renamed without changes.
38 changes: 31 additions & 7 deletions org-logging/s3.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
resource "aws_s3_bucket" "this" {
bucket = local.bucket_name
# acl = "private"
force_destroy = false
bucket = local.bucket_name
force_destroy = var.force_destroy

lifecycle {
prevent_destroy = false
}

tags = merge(
local.base_tags,
Expand All @@ -17,9 +20,11 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
kms_master_key_id = var.kms_key_arn
sse_algorithm = "aws:kms"
}
bucket_key_enabled = true
}
}


resource "aws_s3_bucket_logging" "this" {
bucket = aws_s3_bucket.this.id
target_bucket = var.access_log_bucket
Expand All @@ -29,7 +34,8 @@ resource "aws_s3_bucket_logging" "this" {
resource "aws_s3_bucket_acl" "this" {
count = 0
bucket = aws_s3_bucket.this.id
acl = "private"
# acl = "private"
acl = "log-delivery-write"
}

resource "aws_s3_bucket_ownership_controls" "this" {
Expand All @@ -40,6 +46,14 @@ resource "aws_s3_bucket_ownership_controls" "this" {
}
}

# no versioning on logs
resource "aws_s3_bucket_versioning" "this" {
bucket = aws_s3_bucket.this.id
versioning_configuration {
status = "Suspended"
}
}

#---
# bucket policy (apply also encryption key usage here?)
# deny unencrypted uploads policy statement removed for default encryption
Expand All @@ -48,12 +62,17 @@ data "aws_iam_policy_document" "bucket_policy" {
statement {
sid = "AWSLoggingAclCheck"
effect = "Allow"
actions = ["s3:GetBucketAcl"]
actions = ["s3:GetBucketAcl", "s3:ListBucket"]
principals {
type = "Service"
identifiers = ["logging.amazonaws.com"]
}
resources = [aws_s3_bucket.this.arn]
condition {
test = "StringEquals"
variable = "aws:PrincipalOrgId"
values = [local.organization_id]
}
}
statement {
sid = "AWSLoggingWrite"
Expand All @@ -63,13 +82,19 @@ data "aws_iam_policy_document" "bucket_policy" {
type = "Service"
identifiers = ["logging.amazonaws.com"]
}
resources = [format("%v/%v/*", aws_s3_bucket.this.arn, var.logging_bucket_prefix)]
resources = [format("%v/*", aws_s3_bucket.this.arn)]
condition {
test = "StringEquals"
variable = "s3:x-amz-acl"
values = ["bucket-owner-full-control"]
}
condition {
test = "StringEquals"
variable = "aws:PrincipalOrgId"
values = [data.organization_id]
}
}
# key access
}

#---
Expand Down Expand Up @@ -102,4 +127,3 @@ resource "null_resource" "policy_delay" {
command = "sleep 180"
}
}

57 changes: 0 additions & 57 deletions org-logging/s3.tf2

This file was deleted.

0 comments on commit 6977f16

Please sign in to comment.