Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLT-355 switch resource block to data block #96

Merged
merged 9 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tfstate-apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
paths:
- .github/workflows/tfstate-apply.yml
- terraform/services/tfstate/**
- terraform/modules/bucket/**
- terraform/modules/table/**
workflow_dispatch: # Allow manual trigger

jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tfstate-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
paths:
- .github/workflows/tfstate-plan.yml
- terraform/services/tfstate/**
- terraform/modules/bucket/**
- terraform/modules/table/**
workflow_dispatch: # Allow manual trigger

jobs:
Expand Down
60 changes: 4 additions & 56 deletions terraform/modules/bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,64 +86,12 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
}
}
}

resource "aws_s3_bucket" "access_logs" {
bucket = "${var.name}-access"
force_destroy = true
}

data "aws_iam_policy_document" "access_logs" {
statement {
sid = "AllowSSLRequestsOnly"

effect = "Deny"

principals {
type = "AWS"
identifiers = ["*"]
}

actions = ["s3:*"]

resources = [
aws_s3_bucket.access_logs.arn,
"${aws_s3_bucket.access_logs.arn}/*",
]

condition {
test = "Bool"
variable = "aws:SecureTransport"
values = ["false"]
}
}
}

resource "aws_s3_bucket_policy" "access_logs" {
bucket = aws_s3_bucket.access_logs.id
policy = data.aws_iam_policy_document.access_logs.json
}

resource "aws_s3_bucket_versioning" "access_logs" {
bucket = aws_s3_bucket.access_logs.id
versioning_configuration {
status = "Enabled"
}
data "aws_s3_bucket" "bucket_access_logs" {
bucket = "${var.app}-${var.env}-bucket-access-log"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the change suggested in https://github.com/CMSgov/ab2d-bcda-dpc-platform/pull/95/files#r1674341305 we'll be able to drop app and env variables and reference the account ID as we did there.

}

resource "aws_s3_bucket_server_side_encryption_configuration" "access_logs" {
bucket = aws_s3_bucket.access_logs.id

rule {
apply_server_side_encryption_by_default {
kms_master_key_id = module.bucket_key.id
sse_algorithm = "aws:kms"
}
}
}

resource "aws_s3_bucket_logging" "this" {
bucket = aws_s3_bucket.this.id

target_bucket = aws_s3_bucket.access_logs.id
target_prefix = "log/"
target_bucket = data.aws_s3_bucket.bucket_access_logs.id
target_prefix = "${var.name}/"
}
20 changes: 19 additions & 1 deletion terraform/modules/bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ variable "name" {

variable "cross_account_read_roles" {
description = "Roles in other accounts that need read access to this S3 bucket"
type = list
type = list(any)
default = []
}

variable "app" {
description = "The application name (ab2d, bcda, dpc)"
type = string
validation {
condition = contains(["ab2d", "bcda", "dpc"], var.app)
error_message = "Valid value for app is ab2d, bcda, or dpc."
}
}

variable "env" {
description = "The application environment (dev, test, sbx, prod, mgmt)"
type = string
validation {
condition = contains(["dev", "test", "sbx", "prod", "mgmt"], var.env)
error_message = "Valid value for env is dev, test, sbx, prod, or mgmt."
}
}
gsf marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion terraform/modules/bucket/versions.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
source = "hashicorp/aws"
}
}
required_version = "~> 1.5.5"
Expand Down
3 changes: 3 additions & 0 deletions terraform/modules/function/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ module "zip_bucket" {
"arn:aws:iam::${data.aws_ssm_parameter.prod_account[0].value}:role/delegatedadmin/developer/${var.app}-prod-github-actions",
"arn:aws:iam::${data.aws_ssm_parameter.sbx_account[0].value}:role/delegatedadmin/developer/${var.app}-sbx-github-actions",
] : []

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to nit pick but could this blank line addition be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line addition has been removed

app = var.app
env = var.env
gsf marked this conversation as resolved.
Show resolved Hide resolved
}

resource "aws_s3_object" "empty_function_zip" {
Expand Down
2 changes: 2 additions & 0 deletions terraform/services/tfstate/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ locals {
module "tfstate_bucket" {
source = "../../modules/bucket"
name = local.name
app = var.app
env = var.env
}

module "tfstate_table" {
Expand Down
Loading