From 241031ba6e7019ff19dcf22aa195de77a67d71c7 Mon Sep 17 00:00:00 2001 From: David Berndtsson Date: Fri, 25 Aug 2023 11:05:24 +0200 Subject: [PATCH 1/3] Create and update on default project quotas. Need to implement read. Signed-off-by: David Berndtsson --- client/config.go | 5 +++++ models/config.go | 2 +- provider/resource_config_system.go | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/client/config.go b/client/config.go index 015baa2..cd70512 100644 --- a/client/config.go +++ b/client/config.go @@ -10,6 +10,10 @@ import ( func GetConfigSystem(d *schema.ResourceData) models.ConfigBodySystemPost { var body models.ConfigBodySystemPost + storage := d.Get("storage_per_project").(int) + if storage > 0 { + storage *= 1073741824 // GB + } body = models.ConfigBodySystemPost{ ProjectCreationRestriction: d.Get("project_creation_restriction").(string), ReadOnly: d.Get("read_only").(bool), @@ -17,6 +21,7 @@ func GetConfigSystem(d *schema.ResourceData) models.ConfigBodySystemPost { RobotTokenDuration: d.Get("robot_token_expiration").(int), QuotaPerProjectEnable: true, RobotNamePrefix: d.Get("robot_name_prefix").(string), + StoragePerProject: storage, } log.Printf("[DEBUG] %+v\n ", body) return body diff --git a/models/config.go b/models/config.go index bf5b7f8..c2f9cab 100644 --- a/models/config.go +++ b/models/config.go @@ -48,7 +48,7 @@ type ConfigBodySystemPost struct { RobotTokenDuration int `json:"robot_token_duration,omitempty"` QuotaPerProjectEnable bool `json:"quota_per_project_enable"` RobotNamePrefix string `json:"robot_name_prefix,omitempty"` - StoragePerProject string `json:"storage_per_project,omitempty"` + StoragePerProject int `json:"storage_per_project,omitempty"` ScannerSkipUpdatePulltime bool `json:"scanner_skip_update_pulltime"` } diff --git a/provider/resource_config_system.go b/provider/resource_config_system.go index f7e2840..48f4bcf 100644 --- a/provider/resource_config_system.go +++ b/provider/resource_config_system.go @@ -37,6 +37,11 @@ func resourceConfigSystem() *schema.Resource { Optional: true, Default: false, }, + "storage_per_project": { + Type: schema.TypeInt, + Optional: true, + Default: -1, + }, }, Create: resourceConfigSystemCreate, Read: resourceConfigSystemRead, From a2e81a90de6ae46fe135447a8bb08cbcd5f053c8 Mon Sep 17 00:00:00 2001 From: David Berndtsson Date: Fri, 25 Aug 2023 11:13:07 +0200 Subject: [PATCH 2/3] Implement read and detect config drift Signed-off-by: David Berndtsson --- client/config.go | 2 +- docs/resources/config_system.md | 7 +++++-- provider/resource_config_system.go | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/client/config.go b/client/config.go index cd70512..dce93ea 100644 --- a/client/config.go +++ b/client/config.go @@ -12,7 +12,7 @@ func GetConfigSystem(d *schema.ResourceData) models.ConfigBodySystemPost { var body models.ConfigBodySystemPost storage := d.Get("storage_per_project").(int) if storage > 0 { - storage *= 1073741824 // GB + storage *= 1073741824 // GB to Byte } body = models.ConfigBodySystemPost{ ProjectCreationRestriction: d.Get("project_creation_restriction").(string), diff --git a/docs/resources/config_system.md b/docs/resources/config_system.md index fb39c71..d1f68cc 100644 --- a/docs/resources/config_system.md +++ b/docs/resources/config_system.md @@ -7,6 +7,7 @@ resource "harbor_config_system" "main" { project_creation_restriction = "adminonly" robot_token_expiration = 30 robot_name_prefix = "harbor@" + storage_per_project = 100 } ``` @@ -15,10 +16,12 @@ The following arguments are supported: * **project_creation_restriction** - (Optional) Who can create projects within Harbor. Can be **"adminonly"** or **"everyone"** -* **robot_token_expiration** - (Optional) The amount of time in days a robot account will expiry. +* **robot_token_expiration** - (Optional) The amount of time in days a robot account will expiry. * **robot_name_prefix** - (Optional) Robot account prefix. `NOTE: If the time is set to high you will get a 500 internal server error message when creating robot accounts` * **scanner_skip_update_pulltime** - (Optional) Whether or not to skip update pull time for scanner. -`NOTE: "scanner_skip_update_pulltime" can only be used with harbor version v2.8.0 and above` \ No newline at end of file +`NOTE: "scanner_skip_update_pulltime" can only be used with harbor version v2.8.0 and above` + +* **storage_per_project** - (Optional) Default quota space per project in GIB. Default is -1 (unlimited). diff --git a/provider/resource_config_system.go b/provider/resource_config_system.go index 48f4bcf..e62f146 100644 --- a/provider/resource_config_system.go +++ b/provider/resource_config_system.go @@ -83,12 +83,17 @@ func resourceConfigSystemRead(d *schema.ResourceData, m interface{}) error { if err != nil { return fmt.Errorf("Error getting system configuration %s", err) } + storage := jsonData.StoragePerProject.Value + if storage > 0 { + storage /= 1073741824 // Byte to GB + } d.Set("project_creation_restriction", jsonData.ProjectCreationRestriction.Value) d.Set("read_only", jsonData.ReadOnly.Value) d.Set("robot_token_expiration", jsonData.RobotTokenDuration.Value) d.Set("robot_name_prefix", jsonData.RobotNamePrefix.Value) d.Set("scanner_skip_update_pulltime", jsonData.ScannerSkipUpdatePulltime.Value) + d.Set("storage_per_project", storage) d.SetId("configuration/system") return nil From 14fd4cc43c23cbbd783af9a1be4620937254e888 Mon Sep 17 00:00:00 2001 From: David Berndtsson Date: Mon, 28 Aug 2023 08:35:42 +0200 Subject: [PATCH 3/3] Revert trailing space change Signed-off-by: David Berndtsson --- docs/resources/config_system.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/resources/config_system.md b/docs/resources/config_system.md index d1f68cc..2eed4e3 100644 --- a/docs/resources/config_system.md +++ b/docs/resources/config_system.md @@ -16,7 +16,7 @@ The following arguments are supported: * **project_creation_restriction** - (Optional) Who can create projects within Harbor. Can be **"adminonly"** or **"everyone"** -* **robot_token_expiration** - (Optional) The amount of time in days a robot account will expiry. +* **robot_token_expiration** - (Optional) The amount of time in days a robot account will expiry. * **robot_name_prefix** - (Optional) Robot account prefix. `NOTE: If the time is set to high you will get a 500 internal server error message when creating robot accounts`