Skip to content

Commit

Permalink
Merge pull request #170 from BESTSELLER/tech-review-2021
Browse files Browse the repository at this point in the history
Fixed the import of harbor_replication
  • Loading branch information
wrighbr authored Dec 13, 2021
2 parents 1a72ade + da18ba6 commit 8c03b0e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 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
33 changes: 32 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,35 @@ 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)
}

if jsonDataReplication.Trigger.Type == "scheduled" {
d.Set("schedule", jsonDataReplication.Trigger.TriggerSettings.Cron)
} else {
d.Set("schedule", "manual")
}

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)

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion provider/resource_replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func testAccCheckReplicationUpdate() string {
}

func TestDestinationNamespace(t *testing.T) {
var scheduleType = "event_based"
var scheduleType = "* 0/15 * * * *"
var destNamepace = "gcp-project"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down

0 comments on commit 8c03b0e

Please sign in to comment.