Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artifact Registry: Implement cleanup policies #15561

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/8671.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
artifactregistry: added `cleanup_policies` and `cleanup_policy_dry_run` fields to resource `google_artifact_registry_repository`
```
116 changes: 116 additions & 0 deletions website/docs/r/artifact_registry_repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,50 @@ resource "google_artifact_registry_repository" "my-repo" {
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgit.luolix.top%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=artifact_registry_repository_cleanup&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Artifact Registry Repository Cleanup


```hcl
resource "google_artifact_registry_repository" "my-repo" {
provider = google-beta
location = "us-central1"
repository_id = "my-repository"
description = "example docker repository with cleanup policies"
format = "DOCKER"
cleanup_policy_dry_run = false
cleanup_policies {
id = "delete-prerelease"
action = "DELETE"
condition {
tag_state = "TAGGED"
tag_prefixes = ["alpha", "v0"]
older_than = "2592000s"
}
}
cleanup_policies {
id = "keep-tagged-release"
action = "KEEP"
condition {
tag_state = "TAGGED"
tag_prefixes = ["release"]
package_name_prefixes = ["webapp", "mobile"]
}
}
cleanup_policies {
id = "keep-minimum-versions"
action = "KEEP"
most_recent_versions {
package_name_prefixes = ["webapp", "mobile", "sandbox"]
keep_count = 5
}
}
}
```

## Argument Reference

Expand Down Expand Up @@ -215,11 +259,24 @@ The following arguments are supported:
Configuration specific for a Virtual Repository.
Structure is [documented below](#nested_virtual_repository_config).

* `cleanup_policies` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Cleanup policies for this repository. Cleanup policies indicate when
certain package versions can be automatically deleted.
Map keys are policy IDs supplied by users during policy creation. They must
unique within a repository and be under 128 characters in length.
Structure is [documented below](#nested_cleanup_policies).

* `remote_repository_config` -
(Optional)
Configuration specific for a Remote Repository.
Structure is [documented below](#nested_remote_repository_config).

* `cleanup_policy_dry_run` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
If true, the cleanup pipeline is prevented from deleting versions in this
repository.

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down Expand Up @@ -267,6 +324,65 @@ The following arguments are supported:
(Optional)
Entries with a greater priority value take precedence in the pull order.

<a name="nested_cleanup_policies"></a>The `cleanup_policies` block supports:

* `id` - (Required) The identifier for this object. Format specified above.

* `action` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Policy action.
Possible values are: `DELETE`, `KEEP`.

* `condition` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Policy condition for matching versions.
Structure is [documented below](#nested_condition).

* `most_recent_versions` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Policy condition for retaining a minimum number of versions. May only be
specified with a Keep action.
Structure is [documented below](#nested_most_recent_versions).


<a name="nested_condition"></a>The `condition` block supports:

* `tag_state` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Match versions by tag status.
Default value is `ANY`.
Possible values are: `TAGGED`, `UNTAGGED`, `ANY`.

* `tag_prefixes` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Match versions by tag prefix. Applied on any prefix match.

* `version_name_prefixes` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Match versions by version name prefix. Applied on any prefix match.

* `package_name_prefixes` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Match versions by package prefix. Applied on any prefix match.

* `older_than` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Match versions older than a duration.

* `newer_than` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Match versions newer than a duration.

<a name="nested_most_recent_versions"></a>The `most_recent_versions` block supports:

* `package_name_prefixes` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Match versions by package prefix. Applied on any prefix match.

* `keep_count` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Minimum number of versions to keep.

<a name="nested_remote_repository_config"></a>The `remote_repository_config` block supports:

* `description` -
Expand Down