i am going my first steps in Terraform for AWS and i want to create an S3 bucket and set "block all public access" to ON.
Versions:
Terraform v0.12.24 + provider.aws v2.60.0
file provider.tf
provider "aws" {
region = "eu-west-1"
profile = "<myprofile>"
}
file s3.tf
resource "aws_s3_bucket" "<myname>" {
bucket = "<myname>"
region = "eu-west-1"
}
resource "aws_s3_bucket_public_access_block" "<myname>" {
bucket = "aws_s3_bucket.<myname>.id"
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
the values in <> are my own values and if its the same value on my file, i used the same example value here (so in the s3.tf file its just one name for all the variables)
if i make a
terraform apply
it will create everything, but at the "aws_s3_bucket_public_access_block" it will go into a timeout after like 1 minute and tell me:
Error: error creating public access block policy for S3 bucket (aws_s3_bucket.<myname>.id): NoSuchBucket: The specified bucket does not exist
status code: 404
i also tried to add
depends_on = [ aws_s3_bucket.<myname> ]
in the "aws_s3_bucket_public_access_block" but it doesnt work either.
I searched and tried and searched but nothing really works. Someone reported an error about it and told i must set the AWS_REGION globally in an .env file, tried it and didnt work either.