|
| 1 | +--- |
| 2 | +layout: "tfe" |
| 3 | +page_title: "Terraform Enterprise: tfe_data_retention_policy" |
| 4 | +description: |- |
| 5 | + Manages data retention policies for organizations and workspaces |
| 6 | +--- |
| 7 | + |
| 8 | +# tfe_data_retention_policy |
| 9 | + |
| 10 | +Creates a data retention policy attached to either an organization or workspace. This resource is for Terraform Enterprise only. |
| 11 | + |
| 12 | +## Example Usage |
| 13 | + |
| 14 | +Creating a data retention policy for a workspace: |
| 15 | + |
| 16 | +```hcl |
| 17 | +resource "tfe_organization" "test-organization" { |
| 18 | + name = "my-org-name" |
| 19 | + |
| 20 | +} |
| 21 | +
|
| 22 | +resource "tfe_workspace" "test-workspace" { |
| 23 | + name = "my-workspace-name" |
| 24 | + organization = tfe_organization.test-organization.name |
| 25 | +} |
| 26 | +
|
| 27 | +resource "tfe_data_retention_policy" "foobar" { |
| 28 | + workspace_id = tfe_workspace.test-workspace.id |
| 29 | +
|
| 30 | + delete_older_than { |
| 31 | + days = 42 |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +Creating a data retention policy for an organization: |
| 37 | + |
| 38 | +```hcl |
| 39 | +resource "tfe_organization" "test-organization" { |
| 40 | + name = "my-org-name" |
| 41 | + |
| 42 | +} |
| 43 | +
|
| 44 | +resource "tfe_data_retention_policy" "foobar" { |
| 45 | + organization = tfe_organization.test-organization.name |
| 46 | +
|
| 47 | + delete_older_than { |
| 48 | + days = 1138 |
| 49 | + } |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +Creating a data retention policy for an organization and exclude a single workspace from it: |
| 54 | + |
| 55 | +```hcl |
| 56 | +resource "tfe_organization" "test-organization" { |
| 57 | + name = "my-org-name" |
| 58 | + |
| 59 | +} |
| 60 | +
|
| 61 | +// create data retention policy the organization |
| 62 | +resource "tfe_data_retention_policy" "foobar" { |
| 63 | + organization = tfe_organization.test-organization.name |
| 64 | +
|
| 65 | + delete_older_than { |
| 66 | + days = 1138 |
| 67 | + } |
| 68 | +} |
| 69 | +
|
| 70 | +resource "tfe_workspace" "test-workspace" { |
| 71 | + name = "my-workspace-name" |
| 72 | + organization = tfe_organization.test-organization.name |
| 73 | +} |
| 74 | +
|
| 75 | +// create a policy that prevents automatic deletion of data in the test-workspace |
| 76 | +resource "tfe_data_retention_policy" "foobar" { |
| 77 | + workspace_id = tfe_workspace.test-workspace.id |
| 78 | +
|
| 79 | + dont_delete {} |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +## Argument Reference |
| 84 | + |
| 85 | +The following arguments are supported: |
| 86 | + |
| 87 | +* `organization` - (Optional) The name of the organization you want the policy to apply to. Must not be set if `workspace_id` is set. |
| 88 | +* `workspace_id` - (Optional) The ID of the workspace you want the policy to apply to. Must not be set if `organization` is set. |
| 89 | +* `delete_older_than` - (Optional) If this block is set, the created policy will apply to any data older than the configured number of days. Must not be set if `dont_delete` is set. |
| 90 | +* `dont_delete` - (Optional) If this block is set, the created policy will prevent other policies from deleting data from this workspace or organization. Must not be set if `delete_older_than` is set. |
| 91 | + |
| 92 | + |
| 93 | +## Import |
| 94 | + |
| 95 | +A resource can be imported; use `<ORGANIZATION>/<WORKSPACE NAME>` or `<ORGANIZATION>` as the import ID. For example: |
| 96 | + |
| 97 | +```shell |
| 98 | +terraform import tfe_data_retention_policy.foobar my-org-name/my-workspace-name |
| 99 | +``` |
0 commit comments