Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

harbor_immutable_tag_rule : disabled at creation time (fixes #477) #486

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions provider/resource_immutable_tag_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,26 @@ func resourceImmutableTagRuleCreate(d *schema.ResourceData, m interface{}) error
body := client.GetImmutableTagRuleBody(d)
id := ""

_, headers, _, err := apiClient.SendRequest("POST", path, body, 201)
if err != nil {
_, headers, respCode, err := apiClient.SendRequest("POST", path, body, 201)
if respCode == 409 {
log.Printf("[DEBUG] resource already exists %s", path)
return err
} else if err != nil {
return err
}

id, _ = client.GetID(headers)
d.SetId(id)

if d.Get("disabled").(bool) {
// if the rule is disabled, we need to do a second request to disable it as Harbor API doesn't allow to create a disabled rule
body := client.GetImmutableTagRuleBody(d)
_, _, _, err := apiClient.SendRequest("PUT", id, body, 200)
if err != nil {
return err
}
}

return resourceImmutableTagRuleRead(d, m)
}

Expand Down
Loading