-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DBTP-1568 - Add s3 support for cross environment service access (…
…#293) Co-authored-by: Anthony Roy <[email protected]>
- Loading branch information
1 parent
795dbae
commit e4252ad
Showing
6 changed files
with
219 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.git | ||
.playwright-browsers | ||
poetry.lock | ||
.terraform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -442,6 +442,153 @@ run "aws_s3_bucket_external_role_access_invalid_cyber_sign_off" { | |
expect_failures = [var.config.external_role_access.cyber_sign_off_by] | ||
} | ||
|
||
run "aws_s3_bucket_cross_environment_service_access_read_write_unit_test" { | ||
command = plan | ||
|
||
variables { | ||
config = { | ||
"bucket_name" = "dbt-terraform-test-s3-cross-env-service-access", | ||
"type" = "s3", | ||
"cross_environment_service_access" = { | ||
"test-access" = { | ||
"application" = "app", | ||
"environment" = "test", | ||
"account" = "123456789012", | ||
"service" = "service", | ||
"read" = true, | ||
"write" = true, | ||
"cyber_sign_off_by" = "[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
|
||
assert { | ||
condition = data.aws_iam_policy_document.bucket-policy.statement[1].effect == "Allow" | ||
error_message = "Should be: Allow" | ||
} | ||
|
||
assert { | ||
condition = length([for item in data.aws_iam_policy_document.bucket-policy.statement[1].condition : item if item.test == "StringLike"]) == 1 | ||
error_message = "condition should have a test: StringLike attribute" | ||
} | ||
|
||
assert { | ||
condition = length([for item in data.aws_iam_policy_document.bucket-policy.statement[1].condition : item if item.variable == "aws:PrincipalArn"]) == 1 | ||
error_message = "condition should have a variable: aws:PrincipalArn attribute" | ||
} | ||
|
||
assert { | ||
condition = length([for item in data.aws_iam_policy_document.bucket-policy.statement[1].condition : | ||
item if item.values == tolist(["arn:aws:iam::123456789012:role/app-test-service-TaskRole-*"])]) == 1 | ||
error_message = "condition should have a values: [bucket arn] attribute" | ||
} | ||
|
||
assert { | ||
condition = alltrue([ | ||
contains(data.aws_iam_policy_document.bucket-policy.statement[1].actions, "s3:Get*"), | ||
contains(data.aws_iam_policy_document.bucket-policy.statement[1].actions, "s3:Put*"), | ||
contains(data.aws_iam_policy_document.bucket-policy.statement[1].actions, "s3:ListBucket"), | ||
]) | ||
error_message = "Should be: s3:Get*, s3:Put*, s3:ListBucket" | ||
} | ||
} | ||
|
||
run "aws_s3_bucket_cross_environment_service_access_read_only_unit_test" { | ||
command = plan | ||
|
||
variables { | ||
config = { | ||
"bucket_name" = "dbt-terraform-test-s3-cross-env-service-access", | ||
"type" = "s3", | ||
"cross_environment_service_access" = { | ||
"test-access" = { | ||
"application" = "app", | ||
"environment" = "test", | ||
"account" = "123456789012", | ||
"service" = "service", | ||
"read" = true, | ||
"write" = false, | ||
"cyber_sign_off_by" = "[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
|
||
assert { | ||
condition = data.aws_iam_policy_document.bucket-policy.statement[1].effect == "Allow" | ||
error_message = "Should be: Allow" | ||
} | ||
|
||
assert { | ||
condition = alltrue([ | ||
contains(data.aws_iam_policy_document.bucket-policy.statement[1].actions, "s3:Get*"), | ||
contains(data.aws_iam_policy_document.bucket-policy.statement[1].actions, "s3:ListBucket"), | ||
!contains(data.aws_iam_policy_document.bucket-policy.statement[1].actions, "s3:Put*"), | ||
]) | ||
error_message = "Should be: s3:Get*, s3:ListBucket" | ||
} | ||
} | ||
|
||
run "aws_s3_bucket_cross_environment_service_access_write_only_unit_test" { | ||
command = plan | ||
|
||
variables { | ||
config = { | ||
"bucket_name" = "dbt-terraform-test-s3-cross-env-service-access", | ||
"type" = "s3", | ||
"cross_environment_service_access" = { | ||
"test-access" = { | ||
"application" = "app", | ||
"environment" = "test", | ||
"account" = "123456789012", | ||
"service" = "service", | ||
"read" = false, | ||
"write" = true, | ||
"cyber_sign_off_by" = "[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
|
||
assert { | ||
condition = data.aws_iam_policy_document.bucket-policy.statement[1].effect == "Allow" | ||
error_message = "Should be: Allow" | ||
} | ||
|
||
assert { | ||
condition = alltrue([ | ||
!contains(data.aws_iam_policy_document.bucket-policy.statement[1].actions, "s3:Get*"), | ||
!contains(data.aws_iam_policy_document.bucket-policy.statement[1].actions, "s3:ListBucket"), | ||
contains(data.aws_iam_policy_document.bucket-policy.statement[1].actions, "s3:Put*"), | ||
]) | ||
error_message = "Should be: s3:Put*" | ||
} | ||
} | ||
|
||
run "aws_s3_bucket_cross_environment_service_access_invalid_cyber_sign_off" { | ||
command = plan | ||
|
||
variables { | ||
config = { | ||
"bucket_name" = "dbt-terraform-test-s3-cross-env-service-access", | ||
"type" = "s3", | ||
"cross_environment_service_access" = { | ||
"test-access" = { | ||
"application" = "app", | ||
"environment" = "test", | ||
"account" = "123456789012", | ||
"service" = "service", | ||
"read" = true, | ||
"write" = true, | ||
"cyber_sign_off_by" = "no-one" | ||
} | ||
} | ||
} | ||
} | ||
expect_failures = [var.config.cross_environment_service_access.cyber_sign_off_by] | ||
} | ||
|
||
run "aws_s3_bucket_object_lock_configuration_governance_unit_test" { | ||
command = plan | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters