Skip to content

Commit

Permalink
fixed bug with updating quotas
Browse files Browse the repository at this point in the history
  • Loading branch information
wrighbr committed Feb 11, 2021
1 parent 697a130 commit 9fbab5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The following arguments are supported:

* `registry_id` - (Optional) To enabled project as Proxy Cache

* `storage_quote` - (Optional) The storage quota of the project in GB's
* `storage_quota` - (Optional) The storage quota of the project in GB's

## Attributes Reference
In addition to all argument, the following attributes are exported:
Expand Down
8 changes: 8 additions & 0 deletions models/quota.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package models

type StorageQuota struct {
Hard Hard `json:"hard"`
}
type Hard struct {
Storage int64 `json:"storage"`
}
15 changes: 15 additions & 0 deletions provider/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/BESTSELLER/terraform-provider-harbor/client"
"github.com/BESTSELLER/terraform-provider-harbor/models"
Expand Down Expand Up @@ -114,6 +115,20 @@ func resourceProjectUpdate(d *schema.ResourceData, m interface{}) error {
return err
}

if d.HasChange("storage_quota") {
quotaID := "/quotas/" + strings.Replace(d.Id(), "/projects", "", -1)

quota := models.Hard{
Storage: int64(d.Get("storage_quota").(int) * 1073741824),
}
body := models.StorageQuota{quota}

_, _, err := apiClient.SendRequest("PUT", quotaID, body, 200)
if err != nil {
return err
}
}

return resourceProjectRead(d, m)
}

Expand Down

0 comments on commit 9fbab5e

Please sign in to comment.