Skip to content

Commit

Permalink
harbor_immutable_tag_rule : disabled at creation time (fixes #477) (#486
Browse files Browse the repository at this point in the history
)

fixes #477

Signed-off-by: flbla <flbla@users.noreply.github.com>
  • Loading branch information
flbla authored Dec 16, 2024
1 parent e5b3e2c commit b117199
Showing 1 changed file with 15 additions and 2 deletions.
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

0 comments on commit b117199

Please sign in to comment.