I am trying to create a policy to enforce all S3 buckets to be private in my org. The policy seems to work well when TFC fully knows about the S3 bucket. I have a situation where the bucket was deleted outside of TFC. However, the Sentinel mocks show “no-op” as the action on the resource. Is this a bug? How can I handle this scenario, as we most likely will encounter it in the future?
The TFC workspace is using 0.15.5.
For reference, here is the policy:
# This policy uses the Sentinel tfplan/v2 import to require that all S3 buckets do not have a public ACL
# Import common-functions/tfplan-functions/tfplan-functions.sentinel
# with alias "plan"
import "tfplan-functions" as plan
# Get all S3 buckets
allS3Buckets = plan.find_resources("aws_s3_bucket")
# Filter S3 buckets that have an ACL not set to private
# Warnings will be printed for all violations since the last parameter is true
checkForPrivateAcl = plan.filter_attribute_is_not_value(allS3Buckets, "acl", "private", true)
# Main rule
main = rule {
length(checkForPrivateAcl["resources"]) is 0
}
Here is a snippet from the TFC plan, which shows up under the section "Terraform detected the following changes made outside of Terraform since the last “terraform apply”:
# module.redacted has been deleted
- resource "aws_s3_bucket" "redacted" {
- acl = "private" -> null
- arn = "redacted" -> null
- bucket = "redacted" -> null
- bucket_domain_name = "redacted" -> null
- bucket_regional_domain_name = "redacted" -> null
- force_destroy = false -> null
- hosted_zone_id = "redacted" -> null
- id = "redacted" -> null
- region = "redacted" -> null
- request_payer = "BucketOwner" -> null
- tags = {redacted} -> null
- tags_all = {redacted} -> null
- server_side_encryption_configuration {
- rule {
- bucket_key_enabled = false -> null
- apply_server_side_encryption_by_default {
- kms_master_key_id = "redacted" -> null
- sse_algorithm = "aws:kms" -> null
}
}
}
- versioning {
- enabled = false -> null
- mfa_delete = false -> null
}
}
Here’s a snippet from the Sentinel mocks:
"module.redacted": {
"address": "module.redacted",
"change": {
"actions": [
"no-op",
],
"after": null,
"after_unknown": {},
"before": null,
},
"deposed": "",
"index": null,
"mode": "managed",
"module_address": "module.redacted",
"name": "redacted",
"provider_name": "registry.terraform.io/hashicorp/aws",
"type": "aws_s3_bucket",
},
And finally, here’s the error I’m getting while running sentinel apply --trace
:
module.redacted has acl that is null or undefined. It is supposed to be private