Skip to content

Instantly share code, notes, and snippets.

@Pelirrojo
Last active September 20, 2022 22:41
Show Gist options
  • Save Pelirrojo/9503a60044d6c7e0671fd89930672a91 to your computer and use it in GitHub Desktop.
Save Pelirrojo/9503a60044d6c7e0671fd89930672a91 to your computer and use it in GitHub Desktop.
Iac Terraform Template for creating an AWS S3 Bucket
# terraform.tf
terraform {
required_version = ">= 1.2.5"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.22.0"
}
}
}
# locals.tf
locals {
region = "eu-west-1"
}
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
# main.tf
provider "aws" {
region = "eu-west-1"
}
resource "aws_s3_bucket" "sample_bucket" {
bucket = "custom-tf-bucket-name-${data.aws_caller_identity.current.account_id}"
}
resource "aws_s3_bucket_public_access_block" "state_bucket_public_block" {
bucket = aws_s3_bucket.sample_bucket.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment