Skip to content

Commit d7cc440

Browse files
authored
Add option for Single Active Replication (fixes #542) (#550)
Signed-off-by: flbla <flbla@users.noreply.github.com>
1 parent a1b1d55 commit d7cc440

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

client/replication.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ func GetReplicationBody(d *schema.ResourceData) models.ReplicationBody {
1515
schedule := d.Get("schedule").(string)
1616

1717
body := models.ReplicationBody{
18-
Name: d.Get("name").(string),
19-
Description: d.Get("description").(string),
20-
Override: d.Get("override").(bool),
21-
Enabled: d.Get("enabled").(bool),
22-
Deletion: d.Get("deletion").(bool),
23-
DestNamespace: d.Get("dest_namespace").(string),
24-
DestNamespaceReplace: d.Get("dest_namespace_replace").(int),
25-
CopyByChunk: d.Get("copy_by_chunk").(bool),
26-
Speed: d.Get("speed").(int),
18+
Name: d.Get("name").(string),
19+
Description: d.Get("description").(string),
20+
Override: d.Get("override").(bool),
21+
Enabled: d.Get("enabled").(bool),
22+
Deletion: d.Get("deletion").(bool),
23+
DestNamespace: d.Get("dest_namespace").(string),
24+
DestNamespaceReplace: d.Get("dest_namespace_replace").(int),
25+
CopyByChunk: d.Get("copy_by_chunk").(bool),
26+
SingleActiveReplication: d.Get("single_active_replication").(bool),
27+
Speed: d.Get("speed").(int),
2728
}
2829

2930
if action == "push" {

docs/resources/replication.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ resource "harbor_replication" "alpine" {
7474
- `dest_namespace` (String) Specify the destination namespace. if empty, the resource will be put under the same namespace as the source.
7575
- `dest_namespace_replace` (Number) Specify the destination namespace flattening policy. Integers from `-1` to `3` are valid values in the harbor API. A value of `-1` will 'Flatten All Levels', `0` means 'No Flattening', `1` 'Flatten 1 Level', `2` 'Flatten 2 Levels', `3` 'Flatten 3 Levels' (Default: `-1`, see [Replication Rules](https://goharbor.io/docs/latest/administration/configuring-replication/create-replication-rules/) for more details)
7676
- `copy_by_chunk` (Boolean) Specify whether to enable the artifact blobs copied by chunks. (Default: `false`)
77+
- `single_active_replication` (Boolean), prevent parallel runs under the same replication. (Default: `false`)
7778
- `enabled` (Boolean) Specify whether the replication is enabled. (Default: `true`)
7879
- `execute_on_changed` (Boolean) Specify whether to execute the replication rule if new or modified. (Default: `false`)
7980
- `filters` (Block Set) (see [below for nested schema](#nestedblock--filters))

models/replications.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ type ReplicationBody struct {
2121
Cron string `json:"cron,omitempty"`
2222
} `json:"trigger_settings,omitempty"`
2323
} `json:"trigger,omitempty"`
24-
Enabled bool `json:"enabled"`
25-
Deletion bool `json:"deletion,omitempty"`
26-
Override bool `json:"override,omitempty"`
27-
CopyByChunk bool `json:"copy_by_chunk,omitempty"`
28-
Filters []ReplicationFilters `json:"filters,omitempty"`
29-
Speed int `json:"speed,omitempty"`
24+
Enabled bool `json:"enabled"`
25+
Deletion bool `json:"deletion,omitempty"`
26+
Override bool `json:"override,omitempty"`
27+
CopyByChunk bool `json:"copy_by_chunk,omitempty"`
28+
SingleActiveReplication bool `json:"single_active_replication,omitempty"`
29+
Filters []ReplicationFilters `json:"filters,omitempty"`
30+
Speed int `json:"speed,omitempty"`
3031
}
3132

3233
type ReplicationFilters struct {

provider/resource_replication.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ func resourceReplication() *schema.Resource {
7070
Optional: true,
7171
Default: false,
7272
},
73+
"single_active_replication": {
74+
Type: schema.TypeBool,
75+
Optional: true,
76+
Default: false,
77+
},
7378
"filters": {
7479
Type: schema.TypeSet,
7580
Optional: true,
@@ -207,6 +212,7 @@ func resourceReplicationRead(d *schema.ResourceData, m interface{}) error {
207212
d.Set("dest_namespace", jsonDataReplication.DestNamespace)
208213
d.Set("dest_namespace_replace", jsonDataReplication.DestNamespaceReplace)
209214
d.Set("copy_by_chunk", jsonDataReplication.CopyByChunk)
215+
d.Set("single_active_replication", jsonDataReplication.SingleActiveReplication)
210216

211217
return nil
212218
}

0 commit comments

Comments
 (0)