-
Notifications
You must be signed in to change notification settings - Fork 53
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
How to create nexus cleanup policy #226
Comments
hi @SomniVertix. This is not a bug. It's a feature request. |
please votes there: https://ideas.sonatype.com/ideas/IDEAS-I-1466 |
This issue has been automatically marked as |
This is the public issue that is tracking the status. |
Upstream issue moved to sonatype/nexus-public#149 |
As of Nexus 3.70 there is an API for clean up policies |
Found a super hacky terraform-onlyISH way to circumvent this limitation by leveraging the ################ SCRIPTS ########################
# Unfortunately Nexus OSS doesn't provide a REST Endpoint in the free version to manage cleanup policies.
# But since they are a crucial part for a full-auto GitOps management,
# we include the groovy script from our former Ansible solution here.
data "http" "cleanup_policy_script" {
url = "https://raw.githubusercontent.com/ansible-ThoTeam/nexus3-oss/refs/tags/v2.5.2/files/groovy/create_cleanup_policies_from_list.groovy"
}
# upload the groovy script to Nexus
resource "nexus_script" "cleanup_policy_script" {
name = local.script_name
content = data.http.cleanup_policy_script.response_body
type = "groovy"
}
# define cleanup policies
locals {
script_name = "create_cleanup_policies_from_list"
cleanup_policies = [{
name = "delete_old"
format = "maven2"
notes = "Automatically delete old assets 30 days after downloading."
criteria = {
lastDownloaded = 30
}
}]
}
# Due to the nature of the `data` block when using the `http` provider
# the POST request would already happen during the plan phase.
# The null_resource prevents this, since it will always change
# and the http data block depends on it.
resource "null_resource" "ok_to_be_replaced" {
triggers = {
always_change = "${timestamp()}"
}
}
data "http" "upload_cleanup_policy" {
depends_on = [ nexus_script.cleanup_policy_script, local.cleanup_policies, null_resource.ok_to_be_replaced ]
url = "${local.nexus_url}/service/rest/v1/script/${local.script_name}/run"
method = "POST"
request_headers = {
Content-Type: "text/plain"
authorization = "Basic ${base64encode("${local.nexus_username}:${local.nexus_password}")}"
}
request_body = jsonencode(local.cleanup_policies)
lifecycle {
postcondition {
condition = contains([200], self.status_code)
error_message = "Something went wrong uploading cleanup policies. Response (Code ${self.status_code}): ${self.response_body}"
}
}
} Important You'll need to provide some variables like |
Describe the bug
Not sure if its a bug or if I'm just missing something, but I can't seem to find where to define/create cleanup policies?
Expected behavior
Use of terraform provider to cleanup policies
The text was updated successfully, but these errors were encountered: