Skip to content
Open
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
23 changes: 23 additions & 0 deletions docs/data-sources/cleanup_policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
page_title: "Data Source nexus_cleanup_policy"
subcategory: "Cleanup"
description: |-

---
# Data Source nexus_cleanup_policy


<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `criteria_asset_regex` (String)
- `criteria_last_blob_updated` (Number)
- `criteria_last_downloaded` (Number)
- `criteria_release_type` (String)
- `format` (String)
- `id` (String) The ID of this resource.
- `name` (String)
- `notes` (String)
- `retain` (Number)
20 changes: 20 additions & 0 deletions docs/data-sources/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
page_title: "Data Source nexus_task"
subcategory: "Other"
description: |-

---
# Data Source nexus_task


<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `current_state` (String)
- `id` (String) The ID of this resource.
- `last_run` (String)
- `name` (String)
- `next_run` (String)
- `type` (String)
48 changes: 48 additions & 0 deletions docs/resources/cleanup_policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
page_title: "Resource nexus_cleanup_policy"
subcategory: "Cleanup"
description: |-

---
# Resource nexus_cleanup_policy

## Example Usage
```terraform
package nexus_cleanup_policy
resource "nexus_cleanup_policy" "example" {
name = "maven-artifacts-clean-up"
notes = "This is an example cleanup policy"
criteria_last_downloaded = 0
criteria_release_type = "RELEASES"
criteria_asset_regex = ".*"
retain = null
format = "maven2"
}
```
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `format` (String)
- `name` (String)

### Optional

- `criteria_asset_regex` (String)
- `criteria_last_blob_updated` (Number)
- `criteria_last_downloaded` (Number)
- `criteria_release_type` (String)
- `notes` (String)
- `retain` (Number)

### Read-Only

- `id` (String) The ID of this resource.
## Import
Import is supported using the following syntax:
```shell
# import using the name of the cleanup policy
# for example: terraform import nexus_task.default <name_cleanup_policy>
terraform import nexus_cleanup_policy.default <name_cleanup_policy>
```
66 changes: 66 additions & 0 deletions docs/resources/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
page_title: "Resource nexus_task"
subcategory: "Other"
description: |-

---
# Resource nexus_task

## Example Usage
```terraform
resource "nexus_task" "default" {
name = "Cleanup service task"
type = "tags.cleanup"
enabled = true
alert_email = "test@test.com"
notification_condition = "FAILURE"
frequency {
schedule = "daily"
cron_expression = null
recurring_days = null
start_date = 1740122615
}
properties = {
}
}
```
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `frequency` (Block Set, Min: 1) (see [below for nested schema](#nestedblock--frequency))
- `name` (String)
- `notification_condition` (String)
- `type` (String)

### Optional

- `alert_email` (String)
- `enabled` (Boolean)
- `properties` (Map of String)

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--frequency"></a>
### Nested Schema for `frequency`

Required:

- `schedule` (String)
- `start_date` (Number)

Optional:

- `cron_expression` (String)
- `recurring_days` (List of Number)
- `time_zone_offset` (String)
## Import
Import is supported using the following syntax:
```shell
# import using the id of the task
# for example: terraform import nexus_task.default 8a8081b4-6b1b-4b3b-8b3b-8b3b8b3b8b3b
terraform import nexus_task.default <task_id>
```
3 changes: 3 additions & 0 deletions examples/resources/nexus_cleanup_policy/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# import using the name of the cleanup policy
# for example: terraform import nexus_task.default <name_cleanup_policy>
terraform import nexus_cleanup_policy.default <name_cleanup_policy>
10 changes: 10 additions & 0 deletions examples/resources/nexus_cleanup_policy/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package nexus_cleanup_policy
resource "nexus_cleanup_policy" "example" {
name = "maven-artifacts-clean-up"
notes = "This is an example cleanup policy"
criteria_last_downloaded = 0
criteria_release_type = "RELEASES"
criteria_asset_regex = ".*"
retain = null
format = "maven2"
}
3 changes: 3 additions & 0 deletions examples/resources/nexus_task/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# import using the id of the task
# for example: terraform import nexus_task.default 8a8081b4-6b1b-4b3b-8b3b-8b3b8b3b8b3b
terraform import nexus_task.default <task_id>
15 changes: 15 additions & 0 deletions examples/resources/nexus_task/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "nexus_task" "default" {
name = "Cleanup service task"
type = "tags.cleanup"
enabled = true
alert_email = "test@test.com"
notification_condition = "FAILURE"
frequency {
schedule = "daily"
cron_expression = null
recurring_days = null
start_date = 1740122615
}
properties = {
}
}
6 changes: 6 additions & 0 deletions internal/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
nexus "github.com/datadrivers/go-nexus-client/nexus3"
"github.com/datadrivers/go-nexus-client/nexus3/pkg/client"
"github.com/datadrivers/terraform-provider-nexus/internal/services/blobstore"
cleanup_policy "github.com/datadrivers/terraform-provider-nexus/internal/services/cleanup-policy"
"github.com/datadrivers/terraform-provider-nexus/internal/services/other"
"github.com/datadrivers/terraform-provider-nexus/internal/services/repository"
"github.com/datadrivers/terraform-provider-nexus/internal/services/security"
"github.com/datadrivers/terraform-provider-nexus/internal/services/task"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand All @@ -19,6 +21,7 @@ func Provider() *schema.Provider {
"nexus_blobstore_group": blobstore.DataSourceBlobstoreGroup(),
"nexus_blobstore_s3": blobstore.DataSourceBlobstoreS3(),
"nexus_blobstore_list": blobstore.DataSourceBlobstoreList(),
"nexus_cleanup_policy": cleanup_policy.DataSourceCleanupPolicy(),
"nexus_repository_apt_hosted": repository.DataSourceRepositoryAptHosted(),
"nexus_repository_apt_proxy": repository.DataSourceRepositoryAptProxy(),
"nexus_repository_bower_group": repository.DataSourceRepositoryBowerGroup(),
Expand Down Expand Up @@ -82,12 +85,14 @@ func Provider() *schema.Provider {
"nexus_privilege_repository_view": security.DataSourceSecurityPrivilegeRepositoryView(),
"nexus_privilege_repository_admin": security.DataSourceSecurityPrivilegeRepositoryAdmin(),
"nexus_privilege_repository_content_selector": security.DataSourceSecurityPrivilegeRepositoryContentSelector(),
"nexus_task": task.DataSourceTask(),
},
ResourcesMap: map[string]*schema.Resource{
"nexus_blobstore_azure": blobstore.ResourceBlobstoreAzure(),
"nexus_blobstore_file": blobstore.ResourceBlobstoreFile(),
"nexus_blobstore_group": blobstore.ResourceBlobstoreGroup(),
"nexus_blobstore_s3": blobstore.ResourceBlobstoreS3(),
"nexus_cleanup_policy": cleanup_policy.ResourceCleanupPolicy(),
"nexus_capability": other.ResourceCapability(),
"nexus_iqserver": other.ResourceIQServer(),
"nexus_repository_apt_hosted": repository.ResourceRepositoryAptHosted(),
Expand Down Expand Up @@ -153,6 +158,7 @@ func Provider() *schema.Provider {
"nexus_privilege_repository_admin": security.ResourceSecurityPrivilegeRepositoryAdmin(),
"nexus_privilege_repository_content_selector": security.ResourceSecurityPrivilegeRepositoryContentSelector(),
"nexus_privilege_wildcard": security.ResourceSecurityPrivilegeWildcard(),
"nexus_task": task.ResourceTask(),
},
Schema: map[string]*schema.Schema{
"insecure": {
Expand Down
72 changes: 72 additions & 0 deletions internal/services/cleanup-policy/data_source_cleanup_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cleanup_policy

import (
nexus "github.com/datadrivers/go-nexus-client/nexus3"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceCleanupPolicy() *schema.Resource {
return &schema.Resource{
Read: dataSourceCleanupPolicyRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"notes": {
Type: schema.TypeString,
Computed: true,
},
"criteria_last_blob_updated": {
Type: schema.TypeInt,
Computed: true,
},
"criteria_last_downloaded": {
Type: schema.TypeInt,
Computed: true,
},
"criteria_release_type": {
Type: schema.TypeString,
Computed: true,
},
"criteria_asset_regex": {
Type: schema.TypeString,
Computed: true,
},
"retain": {
Type: schema.TypeInt,
Computed: true,
},
"format": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceCleanupPolicyRead(d *schema.ResourceData, m interface{}) error {
client := m.(*nexus.NexusClient)
id := d.Get("id").(string)

policy, err := client.CleanupPolicy.Get(id)
if err != nil {
return err
}

//d.SetId(policy.ID)
d.Set("name", policy.Name)
d.Set("notes", policy.Notes)
d.Set("criteria_last_blob_updated", policy.CriteriaLastBlobUpdated)
d.Set("criteria_last_downloaded", policy.CriteriaLastDownloaded)
d.Set("criteria_release_type", policy.CriteriaReleaseType)
d.Set("criteria_asset_regex", policy.CriteriaAssetRegex)
d.Set("retain", policy.Retain)
d.Set("format", policy.Format)

return nil
}
Loading