Project: KICS (Provisioning / Security & Compliance)
File: 568a4d22-3517-44a6-a7ad-6a7eed88722c.md

title: S3 Bucket Without Versioning hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 568a4d22-3517-44a6-a7ad-6a7eed88722c Query name: S3 Bucket Without Versioning Platform: Terraform Severity: <span style="color:#ff7213">Medium</span> Category: Backup URL: S3 bucket should have versioning enabled<br> ```tf title="Positive test num. 1 - tf file" hl_lines="24" provider "aws" { region = "us-east-1" } terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.0" } } } resource "awss3bucket" "positive1" { bucket = "my-tf-test-bucket" acl = "private" tags = { Name = "My bucket" Environment = "Dev" } versioning { enabled = false } } ``` ```tf title="Positive test num. 2 - tf file" hl_lines="14" provider "aws" { region = "us-east-1" } terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.0" } } } resource "awss3bucket" "positive2" { bucket = "my-tf-test-bucket" acl = "private" tags = { Name = "My bucket" Environment = "Dev" } } ``` ```tf title="Positive test num. 3 - tf file" hl_lines="23" provider "aws" { region = "us-east-1" } terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.0" } } } resource "awss3bucket" "positive3" { bucket = "my-tf-test-bucket" acl = "private" tags = { Name = "My bucket" Environment = "Dev" } versioning { mfa_delete = true } } ``` <details><summary>Positive test num. 4 - tf file</summary> ```tf hl_lines="10" module "s3_bucket" { source = "terraform-aws-modules/s3-bucket/aws" version = "3.7.0" bucket = "my-s3-bucket" acl = "private" versioning = { enabled = false } } ``` </details> <details><summary>Positive test num. 5 - tf file</summary> ```tf hl_lines="9" module "s3_bucket" { source = "terraform-aws-modules/s3-bucket/aws" version = "3.7.0" bucket = "my-s3-bucket" acl = "private" versioning = { mfa_delete = true } } ``` </details> <details><summary>Positive test num. 6 - tf file</summary> ```tf hl_lines="1" module "s3_bucket" { source = "terraform-aws-modules/s3-bucket/aws" version = "3.7.0" bucket = "my-s3-bucket" acl = "private" } ``` </details> <details><summary>Positive test num. 7 - tf file</summary> ```tf hl_lines="27" terraform { required_providers { aws = { source = "hashicorp/aws" version = "4.2.0" } } } provider "aws" { } resource "awss3bucket" "b0" { bucket = "my-tf-test-bucket" tags = { Name = "My bucket" Environment = "Dev" } } resource "awss3bucket_versioning" "example" { bucket = awss3bucket.b0.id versioning_configuration { status = "Suspended" } } ``` </details> <details><summary>Positive test num. 8 - tf file</summary> ```tf hl_lines="14" terraform { required_providers { aws = { source = "hashicorp/aws" version = "4.2.0" } } } provider "aws" { } resource "awss3bucket" "b2" { bucket = "my-tf-test-bucket" tags = { Name = "My bucket" Environment = "Dev" } } ``` </details> ```tf title="Negative test num. 1 - tf file" provider "aws" { region = "us-east-1" } terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.0" } } } resource "awss3bucket" "negative1" { bucket = "my-tf-test-bucket" acl = "private" tags = { Name = "My bucket" Environment = "Dev" } versioning { enabled = true } } ``` ```tf title="Negative test num. 2 - tf file" module "s3_bucket" { source = "terraform-aws-modules/s3-bucket/aws" version = "3.7.0" bucket = "my-s3-bucket" acl = "private" versioning = { enabled = true } } ``` ```tf title="Negative test num. 3 - tf file" terraform { required_providers { aws = { source = "hashicorp/aws" version = "4.2.0" } } } provider "aws" { } resource "awss3bucket" "b" { bucket = "my-tf-test-bucket" tags = { Name = "My bucket" Environment = "Dev" } } resource "awss3bucket_versioning" "example" { bucket = awss3bucket.b.id versioning_configuration { status = "Enabled" } } ```