Skip to content

Commit

Permalink
Artifact Registry: Implement cleanup policies (#8671) (#15561)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Aug 18, 2023
1 parent b058ffb commit 42aa70d
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
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

0 comments on commit 42aa70d

Please sign in to comment.