# Example bad resources for unit testing data "aws_ami" "ubuntu" { most_recent = true filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } filter { name = "virtualization-type" values = ["hvm"] } owners = ["099720109477"] # Canonical } resource "aws_instance" "web" { ami = data.aws_ami.ubuntu.id instance_type = "t3.micro" tags = { Name = "HelloWorld" } } resource "aws_s3_bucket" "b" { bucket = "my-tf-test-bucket" tags = { Name = "My bucket" Environment = "Dev" } } resource "aws_s3_bucket_policy" "allow_access_from_another_account" { bucket = aws_s3_bucket.b.id # data.aws_iam_policy_document.allow_access_from_another_account.json policy = jsonencode({ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111111111111:user/srv_my-bucket" }, "Action": [ "s3:*" ], "Resource": [ "arn:aws:s3:::my-bucket", "arn:aws:s3:::my-bucket/*" ] }#, # { # "Effect": "Deny", # "Principal": { # "AWS": "*" # }, # "Action": [ "s3:*" ], # "Resource": [ # "arn:aws:s3:::my-bucket", # "arn:aws:s3:::my-bucket/*" # ], # "Condition": { # "Bool": { # "aws:SecureTransport": "false" # } # } # } ] }) } data "aws_iam_policy_document" "allow_access_from_another_account" { statement { principals { type = "AWS" identifiers = ["*"] } actions = [ "s3:GetObject", "s3:ListBucket", ] resources = [ aws_s3_bucket.example.arn, "${aws_s3_bucket.example.arn}/*", ] } }