Skip to content

Commit

Permalink
Fixed the import of replharbor_replication
Browse files Browse the repository at this point in the history
  • Loading branch information
wrighbr committed Dec 13, 2021
1 parent 33e88eb commit c5b5426
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/resources/replication.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ In addition to all argument, the following attributes are exported:
Harbor project can be imported using the `replication id` eg,

`
terraform import harbor_project.main /registries/7
terraform import harbor_project.main /replication/policies/1
`
3 changes: 2 additions & 1 deletion models/replications.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var PathReplication = "/replication/policies"
type ReplicationBody struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
ID int `json:"id"`
SrcRegistry struct {
ID int `json:"id,omitempty"`
} `json:"src_registry,omitempty"`
Expand All @@ -18,7 +19,7 @@ type ReplicationBody struct {
Cron string `json:"cron,omitempty"`
} `json:"trigger_settings,omitempty"`
} `json:"trigger,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Enabled bool `json:"enabled"`
Deletion bool `json:"deletion,omitempty"`
Override bool `json:"override,omitempty"`
Filters []ReplicationFilters `json:"filters,omitempty"`
Expand Down
28 changes: 27 additions & 1 deletion provider/resource_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func resourceReplication() *schema.Resource {
Read: resourceReplicationRead,
Update: resourceReplicationUpdate,
Delete: resourceReplicationDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
}
}

Expand Down Expand Up @@ -126,7 +129,30 @@ func resourceReplicationRead(d *schema.ResourceData, m interface{}) error {
return fmt.Errorf("Resource not found %s", d.Id())
}

d.Set("replication_policy_id", jsonData.ID)
var jsonDataReplication models.ReplicationBody
err = json.Unmarshal([]byte(resp), &jsonDataReplication)
if err != nil {
return fmt.Errorf("Resource not found %s", d.Id())
}

destRegistryID := jsonDataReplication.DestRegistry.ID

if destRegistryID == 0 {
d.Set("action", "pull")
d.Set("registry_id", jsonDataReplication.SrcRegistry.ID)

} else {
d.Set("action", "push")
d.Set("registry_id", destRegistryID)
}

d.Set("replication_policy_id", jsonDataReplication.ID)
d.Set("enabled", jsonDataReplication.Enabled)
d.Set("name", jsonDataReplication.Name)
d.Set("deletion", jsonDataReplication.Deletion)
d.Set("override", jsonDataReplication.Override)
d.Set("schedule", jsonDataReplication.Trigger.Type)

return nil
}

Expand Down

0 comments on commit c5b5426

Please sign in to comment.