|
| 1 | +# Resource: harbor_retention_policy |
| 2 | + |
| 3 | +Harbor official documentation feature reference: https://goharbor.io/docs/2.0.0/working-with-projects/working-with-images/create-tag-retention-rules/ |
| 4 | + |
| 5 | +## Example Usage |
| 6 | + |
| 7 | +```hcl |
| 8 | +resource "harbor_project" "main" { |
| 9 | + name = "main" |
| 10 | +} |
| 11 | +
|
| 12 | +resource "harbor_retention_policy" "cleanup" { |
| 13 | + scope { |
| 14 | + ref = harbor_project.main.id |
| 15 | + } |
| 16 | +
|
| 17 | + rule { |
| 18 | + template = "always" |
| 19 | + tag_selectors { |
| 20 | + decoration = "matches" |
| 21 | + pattern = "master" |
| 22 | + extras = jsonencode({ |
| 23 | + untagged: false |
| 24 | + }) |
| 25 | + } |
| 26 | + } |
| 27 | +
|
| 28 | + rule { |
| 29 | + disabled = true |
| 30 | + template = "latestPulledN" |
| 31 | + params = { |
| 32 | + "latestPulledN" = 15 |
| 33 | + "nDaysSinceLastPush" = 7 |
| 34 | + } |
| 35 | + tag_selectors { |
| 36 | + kind = "doublestar" |
| 37 | + decoration = "excludes" |
| 38 | + pattern = "master" |
| 39 | + extras = jsonencode({ |
| 40 | + untagged: false |
| 41 | + }) |
| 42 | + } |
| 43 | + scope_selectors { |
| 44 | + repository { |
| 45 | + kind = "doublestar" |
| 46 | + decoration = "repoExcludes" |
| 47 | + pattern = "nginx-*" |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | +
|
| 52 | + trigger { |
| 53 | + settings { |
| 54 | + cron = "0 0 0 * * *" |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +## Argument Reference |
| 61 | + |
| 62 | +The following arguments are supported: |
| 63 | + |
| 64 | +* `algorithm` - (Optional) Algorithm used to aggregate rules. Defaults to `"or"`. |
| 65 | + |
| 66 | +* `scope` - (Required) Describes the (project) scope of this retention policy. |
| 67 | + |
| 68 | +* `rule` - (Required) List of retention rules that compose the policy. |
| 69 | + |
| 70 | +* `trigger` - (Required) Defines a schedule with a cron rule. |
| 71 | + |
| 72 | +## Nested Blocks |
| 73 | + |
| 74 | +### scope |
| 75 | + |
| 76 | +#### Arguments |
| 77 | + |
| 78 | +* `level` - (Optional) Defines the level the scope applies to. Defaults to `"project"`. |
| 79 | + |
| 80 | +* `ref` - (Required) Reference id (usually project id) the retention policy refers to. |
| 81 | + |
| 82 | +### rule |
| 83 | + |
| 84 | +#### Arguments |
| 85 | + |
| 86 | +* `disabled` - (Optional) Specifies if the rule should be taken in account or not (ie disabled). Defaults to `false`. |
| 87 | + |
| 88 | +* `action` - (Optional) Specifies the action to do if set of rules is matched. Defaults to `"retain"`. |
| 89 | + |
| 90 | +* `template` - (Required) kind of rules among the following: |
| 91 | + |
| 92 | + * `latestPushedK`: (retain) the most recently pushed # artifacts |
| 93 | + |
| 94 | + * `latestPulledK`: (retain) the most recently pulled # artifacts |
| 95 | + |
| 96 | + * `nDaysSinceLastPush`: (retain) the artifacts pushed with the last # days |
| 97 | + |
| 98 | + * `nDaysSinceLastPull`: (retain) the artifacts pulled with the last # days |
| 99 | + |
| 100 | + * `always`: (retain) always |
| 101 | + |
| 102 | +* `params` - (Optional) Map of params for the kind of rule (number of days or artifacts associated to the rule template). Defaults to empty map. |
| 103 | + |
| 104 | +Note that multiple key-values can be specified instead of only the one matching the template. The other ones would be disabled but recorded as default choice to the associated template within the UI combo-box. |
| 105 | + |
| 106 | +* `tag_selectors` - (Required) Describes the image tags on which to apply the rule. |
| 107 | + |
| 108 | +* `scope_selectors` - (Required) Describes the image name(s) on which to apply the rule. |
| 109 | + |
| 110 | +#### Attributes |
| 111 | + |
| 112 | +* `id` - The id of the rule (currently not used and set to `0` whatever the number of rules). |
| 113 | + |
| 114 | +* `priority` - A priority tag to know in which order the set of rules should b performed (currently not used and set to `0`). |
| 115 | + |
| 116 | +### `tag_selectors` |
| 117 | + |
| 118 | +#### Arguments |
| 119 | + |
| 120 | +* `kind` - (Optional) The kind of tag selector. Defaults to `doublestar`. |
| 121 | + |
| 122 | +* `extras` - (Optional) Describes extra info for tag selector as a json encoded string, supports mainly the following key value: `untagged: (false|true)` to match or not the untagged artifacts in the rule. Defaults to `""`. |
| 123 | + |
| 124 | +* `decoration` - (Required) Specifies if the pattern should be matched (`"matches"`) or excluded (`"excludes"`). |
| 125 | + |
| 126 | +* `pattern` - (Required) Describes the pattern that should match (or exclude) image tags |
| 127 | + |
| 128 | +### `scope_selectors` |
| 129 | + |
| 130 | +#### Arguments |
| 131 | + |
| 132 | +* `kind` - (Optional) The kind of scope selector. Defaults to `doublestar`. |
| 133 | + |
| 134 | +* `extras` - (Optional) Describes extra info for scope selector as a json encoded string, does not support any known key value as now. Defaults to `""`. |
| 135 | + |
| 136 | +* `decoration` - (Required) Specifies if the pattern should be matched (`"repoMatches"`) or excluded (`"repoExcludes"`). |
| 137 | + |
| 138 | +* `pattern` - (Required) Describes the pattern that should match (or exclude) image names |
| 139 | + |
| 140 | +### `trigger` |
| 141 | + |
| 142 | +#### Arguments |
| 143 | + |
| 144 | +* `kind` - (Optional) The kind of trigger. Defaults to `Schedule`. |
| 145 | + |
| 146 | +* `settings` - (Required) The trigger settings. |
| 147 | + |
| 148 | +#### Attributes |
| 149 | + |
| 150 | +* `references` - Reference to an internal job responsible for applying the trigger. |
| 151 | + |
| 152 | +### `settings` |
| 153 | + |
| 154 | +#### Arguments |
| 155 | + |
| 156 | +* `cron` - (Optional) 6-fields cron pattern for triggering the retention policy execution by cron schedule. Defaults to `""` (which refers to a "None" Schedule). |
| 157 | + |
| 158 | +### `references` |
| 159 | + |
| 160 | +#### Attributes |
| 161 | + |
| 162 | +* `job_id` - Reference to the internal job id associated to the trigger. |
| 163 | + |
| 164 | +## Attributes Reference |
| 165 | + |
| 166 | +In addition to all arguments, the following attribute is exported: |
| 167 | + |
| 168 | +* `id` - The id of the retention policy. |
| 169 | + |
| 170 | +## Import |
| 171 | + |
| 172 | +Harbor Retention policies can be imported using the `harbor_retention_policy`, e.g. |
| 173 | + |
| 174 | +```sh |
| 175 | +terraform import harbor_retention_policy.cleanup 2 |
| 176 | +``` |
0 commit comments