---
title: "Create a Terraform state protection rule for a project"
method: POST
path: "/api/v4/projects/{id}/terraform/state_protection_rules"
tags: ["projects"]
---

# Create a Terraform state protection rule for a project

`POST /api/v4/projects/{id}/terraform/state_protection_rules`

## Request

- Base URL: `https://gitlab.com`
- URL: `https://gitlab.com/api/v4/projects/{id}/terraform/state_protection_rules`
- Auth: none declared

This feature was introduced in GitLab 19.1.

## Path parameters

- `id` string, required

## Request body

- PostApiV4ProjectsIdTerraformStateProtectionRules: Create a Terraform state protection rule for a project
  - `state_name` string, required: Terraform state name to protect. Maximum 255 characters. Must be unique per project.
  - `minimum_access_level_for_write` 'developer' | 'maintainer' | 'owner' | 'admin', required: Minimum GitLab access level required to write to the Terraform state. Valid values: developer, maintainer, owner, admin.
  - `allowed_from` 'anywhere' | 'ci_only' | 'ci_on_protected_branch_only': Source restriction for write requests. Default: anywhere. Valid values: anywhere, ci_only, ci_on_protected_branch_only.

## Response `201`

Create a Terraform state protection rule for a project

- APIEntitiesTerraformStateProtectionRule: API_Entities_Terraform_StateProtectionRule model
  - `id` integer, required
  - `project_id` integer, required
  - `state_name` string, required
  - `minimum_access_level_for_write` string, required
  - `allowed_from` string, required

## Other responses

- `400`: Bad Request
- `401`: Unauthorized
- `403`: Forbidden
- `404`: Not Found
- `422`: Unprocessable Entity

---

[API](https://skmtc.dev/gitlab/apis/gitlab-api.md) - [All operations](https://skmtc.dev/gitlab/apis/gitlab-api/llms.txt) - [OpenAPI document](https://skmtc.dev/gitlab/apis/gitlab-api/revisions/b234947ef3f2?raw)
