---
title: Cloud storage bucket versioning disabled
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Infrastructure as Code (IaC)
  Security > IaC Security Rules > Cloud storage bucket versioning disabled
---

# Cloud storage bucket versioning disabled

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**Id:** `ansible-gcp-cloud-storage-bucket-versioning-disabled` 

**Provider:** GCP

**Platform:** Ansible

**Severity:** Medium

**Category:** Observability

#### Learn More{% #learn-more %}

- [Provider Reference](https://docs.ansible.com/ansible/latest/collections/google/cloud/gcp_storage_bucket_module.html#parameter-versioning)

### Description{% #description %}

Cloud Storage buckets should have object versioning enabled to protect against accidental or malicious deletion and allow recovery of prior object states. In Ansible, tasks using the `google.cloud.gcp_storage_bucket` or `gcp_storage_bucket` modules must define the `versioning` parameter and set `versioning.enabled` to `true`. Resources missing the `versioning` parameter or with `versioning.enabled` set to `false` are flagged.

Secure configuration example:

```yaml
- name: Create GCS bucket with versioning
  google.cloud.gcp_storage_bucket:
    name: my-bucket
    versioning:
      enabled: true
```

## Compliant Code Examples{% #compliant-code-examples %}

```yaml
- name: create a bucket
  google.cloud.gcp_storage_bucket:
    name: ansible-storage-module
    project: test_project
    auth_kind: serviceaccount
    service_account_file: /tmp/auth.pem
    state: present
    versioning:
      enabled: yes
```

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```yaml
---
- name: create a bucket
  google.cloud.gcp_storage_bucket:
    name: ansible-storage-module
    project: test_project
    auth_kind: serviceaccount
    service_account_file: "/tmp/auth.pem"
    state: present
- name: create a second bucket
  google.cloud.gcp_storage_bucket:
    name: ansible-storage-module
    project: test_project
    auth_kind: serviceaccount
    service_account_file: "/tmp/auth.pem"
    state: present
    versioning:
      enabled: no
```
