diff --git a/client/system.go b/client/system.go index c6b08cd..a9cecc0 100644 --- a/client/system.go +++ b/client/system.go @@ -27,6 +27,7 @@ func GetSystemBoby(d *schema.ResourceData, scheduleType string) models.SystemBod body.Schedule.Cron = CronStr if scheduleType == "gc" { body.Parameters.DeleteUntagged = d.Get("delete_untagged").(bool) + body.Parameters.Workers = d.Get("workers").(int) } else if scheduleType == "purgeaudit" { body.Parameters.AuditRetentionHour = d.Get("audit_retention_hour").(int) body.Parameters.IncludeOperations = d.Get("include_operations").(string) diff --git a/docs/resources/garbage_collection.md b/docs/resources/garbage_collection.md index 5605871..e79c9ff 100644 --- a/docs/resources/garbage_collection.md +++ b/docs/resources/garbage_collection.md @@ -14,8 +14,9 @@ description: |- ```terraform resource "harbor_garbage_collection" "main" { - schedule = "Daily" - delete_untagged = true + schedule = "Daily" + delete_untagged = true + workers = 1 } ``` @@ -28,6 +29,7 @@ resource "harbor_garbage_collection" "main" { ### Optional - `delete_untagged` (Boolean) Allow garbage collection on untagged artifacts. +- `workers` (Number) Number of workers to run the garbage collection, value must be between 1 and 5. ### Read-Only diff --git a/examples/resources/harbor_garbage_collection/resource.tf b/examples/resources/harbor_garbage_collection/resource.tf index 7e80df8..51d48c4 100644 --- a/examples/resources/harbor_garbage_collection/resource.tf +++ b/examples/resources/harbor_garbage_collection/resource.tf @@ -1,4 +1,5 @@ resource "harbor_garbage_collection" "main" { - schedule = "Daily" - delete_untagged = true + schedule = "Daily" + delete_untagged = true + workers = 1 } diff --git a/models/system.go b/models/system.go index 257061c..30e8852 100644 --- a/models/system.go +++ b/models/system.go @@ -12,6 +12,7 @@ type JobParameters struct { DeleteUntagged bool `json:"delete_untagged,omitempty"` AuditRetentionHour int `json:"audit_retention_hour,omitempty"` IncludeOperations string `json:"include_operations,omitempty"` + Workers int `json:"workers,omitempty"` } type SystemBody struct { @@ -31,6 +32,7 @@ type SystemBody struct { DeleteUntagged bool `json:"delete_untagged,omitempty"` AuditRetentionHour int `json:"audit_retention_hour,omitempty"` IncludeOperations string `json:"include_operations,omitempty"` + Workers int `json:"workers,omitempty"` AdditionalProp1 bool `json:"additionalProp1,omitempty"` AdditionalProp2 bool `json:"additionalProp2,omitempty"` AdditionalProp3 bool `json:"additionalProp3,omitempty"` diff --git a/provider/resource_garbage_collection.go b/provider/resource_garbage_collection.go index d6cbd76..cf2cfe3 100644 --- a/provider/resource_garbage_collection.go +++ b/provider/resource_garbage_collection.go @@ -20,6 +20,18 @@ func resourceGC() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + "workers": { + Type: schema.TypeInt, + Optional: true, + Default: 1, + ValidateFunc: func(i interface{}, k string) (ws []string, errors []error) { + value := i.(int) + if value < 1 || value > 5 { + errors = append(errors, fmt.Errorf("GC workers must be between 1 and 5")) + } + return + }, + }, }, Create: resourceGCCreate, Read: resourceGCRead, @@ -69,6 +81,7 @@ func resourceGCRead(d *schema.ResourceData, m interface{}) error { d.Set("schedule", jsonData.Schedule.Type) } d.Set("delete_untagged", jsonJobParameters.DeleteUntagged) + d.Set("workers", jsonJobParameters.Workers) return nil } diff --git a/provider/resource_garbage_collection_test.go b/provider/resource_garbage_collection_test.go index be90065..c12d619 100644 --- a/provider/resource_garbage_collection_test.go +++ b/provider/resource_garbage_collection_test.go @@ -76,6 +76,7 @@ func testAccCheckGCUpdate() string { resource "harbor_garbage_collection" "main" { schedule = "Hourly" delete_untagged = true + workers = 2 } `) } diff --git a/templates/resources/garbage_collection.md.tmpl b/templates/resources/garbage_collection.md.tmpl index 581c47a..5ee35fe 100644 --- a/templates/resources/garbage_collection.md.tmpl +++ b/templates/resources/garbage_collection.md.tmpl @@ -27,6 +27,7 @@ For example, the {{ .SchemaMarkdown }} template can be used to replace manual sc ### Optional - `delete_untagged` (Boolean) Allow garbage collection on untagged artifacts. +- `workers` (Number) Number of workers to run the garbage collection, value must be between 1 and 5. ### Read-Only