Skip to content

Commit f401e30

Browse files
authored
Merge pull request #204 from KoppulaRajender/clean_up_fix
feat: add auto_cleanup to registry resource
2 parents e0cc194 + 1db5235 commit f401e30

5 files changed

Lines changed: 20 additions & 1 deletion

File tree

aquasec/data_registry.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func dataSourceRegistry() *schema.Resource {
6161
Description: "The interval in days to start pulling new images from the registry, Defaults to 1",
6262
Computed: true,
6363
},
64+
"auto_cleanup": {
65+
Type: schema.TypeBool,
66+
Description: "Automatically clean up images and repositories which are no longer present in the registry from Aqua console",
67+
Computed: true,
68+
},
6469
"image_creation_date_condition": {
6570
Type: schema.TypeString,
6671
Description: "Additional condition for pulling and rescanning images, Defaults to 'none'",
@@ -124,6 +129,7 @@ func dataRegistryRead(d *schema.ResourceData, m interface{}) error {
124129
d.Set("auto_pull_max", reg.AutoPullMax)
125130
d.Set("auto_pull_time", reg.AutoPullTime)
126131
d.Set("auto_pull_interval", reg.AutoPullInterval)
132+
d.Set("auto_cleanup", reg.AutoCleanUp)
127133
d.Set("scanner_type", reg.ScannerType)
128134
d.Set("prefixes", convertStringArr(prefixes))
129135
scannerType := d.Get("scanner_type").(string)

aquasec/resource_registry.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ func resourceRegistry() *schema.Resource {
8282
Description: "The interval in days to start pulling new images from the registry, Defaults to 1",
8383
Optional: true,
8484
},
85+
"auto_cleanup": {
86+
Type: schema.TypeBool,
87+
Description: "Automatically clean up images and repositories which are no longer present in the registry from Aqua console",
88+
Optional: true,
89+
},
8590
"image_creation_date_condition": {
8691
Type: schema.TypeString,
8792
Description: "Additional condition for pulling and rescanning images, Defaults to 'none'",
@@ -177,6 +182,7 @@ func resourceRegistryCreate(d *schema.ResourceData, m interface{}) error {
177182
AutoPullRescan: d.Get("auto_pull_rescan").(bool),
178183
AutoPullMax: d.Get("auto_pull_max").(int),
179184
AutoPullTime: d.Get("auto_pull_time").(string),
185+
AutoCleanUp: d.Get("auto_cleanup").(bool),
180186
ImageCreationDateCondition: d.Get("image_creation_date_condition").(string),
181187
PullImageAge: d.Get("pull_image_age").(string),
182188
PullImageCount: d.Get("pull_image_count").(int),
@@ -230,6 +236,9 @@ func resourceRegistryRead(d *schema.ResourceData, m interface{}) error {
230236
if err = d.Set("auto_pull_interval", r.AutoPullInterval); err != nil {
231237
return err
232238
}
239+
if err = d.Set("auto_cleanup", r.AutoCleanUp); err != nil {
240+
return err
241+
}
233242
if err = d.Set("image_creation_date_condition", r.ImageCreationDateCondition); err != nil {
234243
return err
235244
}
@@ -288,7 +297,7 @@ func resourceRegistryUpdate(d *schema.ResourceData, m interface{}) error {
288297
autoPullInterval = 1
289298
}
290299

291-
if d.HasChanges("name", "username", "password", "url", "type", "auto_pull", "auto_pull_rescan", "auto_pull_max", "auto_pull_time", "auto_pull_interval", "image_creation_date_condition", "scanner_name", "prefixes", "pull_image_count", "pull_image_age", "options") {
300+
if d.HasChanges("name", "username", "password", "url", "type", "auto_pull", "auto_pull_rescan", "auto_pull_max", "auto_pull_time", "auto_pull_interval", "auto_cleanup", "image_creation_date_condition", "scanner_name", "prefixes", "pull_image_count", "pull_image_age", "options") {
292301

293302
prefixes := d.Get("prefixes").([]interface{})
294303
scanner_name := d.Get("scanner_name").([]interface{})
@@ -309,6 +318,7 @@ func resourceRegistryUpdate(d *schema.ResourceData, m interface{}) error {
309318
AutoPullRescan: d.Get("auto_pull_rescan").(bool),
310319
AutoPullMax: d.Get("auto_pull_max").(int),
311320
AutoPullTime: d.Get("auto_pull_time").(string),
321+
AutoCleanUp: d.Get("auto_cleanup").(bool),
312322
AutoPullInterval: autoPullInterval,
313323
ImageCreationDateCondition: d.Get("image_creation_date_condition").(string),
314324
PullImageAge: d.Get("pull_image_age").(string),

client/registries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Registry struct {
2525
AutoPullTime string `json:"auto_pull_time"`
2626
AutoPullMax int `json:"auto_pull_max"`
2727
AutoPullInterval int `json:"auto_pull_interval"`
28+
AutoCleanUp bool `json:"auto_cleanup"`
2829
PullRepoPatterns interface{} `json:"pull_repo_patterns"`
2930
PullRepoPatternsExcluded interface{} `json:"pull_repo_patterns_excluded"`
3031
PullTagPatterns interface{} `json:"pull_tag_patterns"`

docs/data-sources/integration_registries.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ description: |-
2929

3030
### Read-Only
3131

32+
- `auto_cleanup` (Boolean) Automatically clean up images and repositories which are no longer present in the registry from Aqua console
3233
- `auto_pull` (Boolean) Whether to automatically pull images from the registry on creation and daily
3334
- `auto_pull_interval` (Number) The interval in days to start pulling new images from the registry, Defaults to 1
3435
- `auto_pull_max` (Number) Maximum number of repositories to pull every day, defaults to 100

docs/resources/integration_registry.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ description: |-
2323
### Optional
2424

2525
- `author` (String) The username of the user who created or last modified the registry
26+
- `auto_cleanup` (Boolean) Automatically clean up images and repositories which are no longer present in the registry from Aqua console
2627
- `auto_pull` (Boolean) Whether to automatically pull images from the registry on creation and daily
2728
- `auto_pull_interval` (Number) The interval in days to start pulling new images from the registry, Defaults to 1
2829
- `auto_pull_max` (Number) Maximum number of repositories to pull every day, defaults to 100

0 commit comments

Comments
 (0)