Skip to content

Commit

Permalink
Merge branch 'main' into fix/362
Browse files Browse the repository at this point in the history
  • Loading branch information
flbla authored Aug 21, 2023
2 parents 871601e + 14f33d1 commit 952ad9d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
docker_daemon_json: '{"insecure-registries":["0.0.0.0/0"]}'

- name: Create kind cluster
uses: helm/kind-action@v1.7.0
uses: helm/kind-action@v1.8.0
with:
version: v0.11.1
node_image: kindest/node:v1.22.0
Expand Down
10 changes: 9 additions & 1 deletion docs/resources/robot_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,12 @@ The following arguments are supported:
In addition to all argument, the following attributes are exported:


* **full_name** - Full name of the robot account which harbor generates including the robot prefix. Eg. `robot$project+name` or `harbor@project+name` (depending on your robot prefix).
* **full_name** - Full name of the robot account which harbor generates including the robot prefix. Eg. `robot$project+name` or `harbor@project+name` (depending on your robot prefix).

## Import
Harbor robot account can be imported using the `robot account id` eg,

`
terraform import harbor_robot_account.system /robots/123
`

12 changes: 11 additions & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package provider

import (
"fmt"
"os"
"strings"

"github.com/goharbor/terraform-provider-harbor/client"
Expand Down Expand Up @@ -74,7 +76,15 @@ func Provider() *schema.Provider {
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
var apiPath string

url := d.Get("url").(string)
//url := d.Get("url").(string)
url := os.Getenv("HARBOR_URL")
if d.Get("url").(string) != "" {
url = d.Get("url").(string)
}
if url == "" {
return nil, fmt.Errorf("url is required and must be provided in the provider config or the HARBOR_URL environment variable")
}

username := d.Get("username").(string)
password := d.Get("password").(string)
insecure := d.Get("insecure").(bool)
Expand Down
7 changes: 7 additions & 0 deletions provider/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ func resourceProjectDelete(d *schema.ResourceData, m interface{}) error {
return err
}
}
if !forceDestroy {
projectName := d.Get("name").(string)
repos, _ := apiClient.GetProjectRepositories(projectName)
if len(repos) != 0 {
return fmt.Errorf("Project %s is not empty, please set force_delete to TRUE to clean all repositories", projectName)
}
}

_, _, _, err := apiClient.SendRequest("DELETE", d.Id(), nil, 200)
if err != nil {
Expand Down

0 comments on commit 952ad9d

Please sign in to comment.