Skip to content

Commit c749902

Browse files
committed
fix abac rule update and tags inconsistency
1 parent 3172be8 commit c749902

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

codefresh/cfclient/gitops_abac_rules.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type GitopsAbacRuleResponse struct {
3131
Data struct {
3232
AbacRule GitopsAbacRule `json:"abacRule,omitempty"`
3333
CreateAbacRule GitopsAbacRule `json:"createAbacRule,omitempty"`
34+
UpdateAbacRule GitopsAbacRule `json:"updateAbacRule,omitempty"`
3435
RemoveAbacRule GitopsAbacRule `json:"removeAbacRule,omitempty"`
3536
} `json:"data"`
3637
}
@@ -165,6 +166,54 @@ func (client *Client) CreateAbacRule(gitopsAbacRule *GitopsAbacRule) (*GitopsAba
165166
return &gitopsAbacRuleResponse.Data.CreateAbacRule, nil
166167
}
167168

169+
func (client *Client) UpdateAbacRule(gitopsAbacRule *GitopsAbacRule) (*GitopsAbacRule, error) {
170+
acc, err := client.GetCurrentAccount()
171+
gitopsAbacRule.AccountId = acc.ID
172+
if err != nil {
173+
return nil, err
174+
}
175+
176+
request := GraphQLRequest{
177+
Query: `mutation ($accountId: String!, $updateAbacRuleInput: UpdateAbacRuleInput!) {
178+
updateAbacRule(
179+
accountId: $accountId
180+
updateAbacRuleInput: $updateAbacRuleInput
181+
) {
182+
id
183+
accountId
184+
entityType
185+
teams
186+
tags
187+
actions
188+
attributes {
189+
name
190+
key
191+
value
192+
}
193+
}
194+
}
195+
`,
196+
Variables: map[string]interface{}{
197+
"accountId": acc.ID,
198+
"updateAbacRuleInput": gitopsAbacRule,
199+
},
200+
}
201+
202+
response, err := client.SendGqlRequest(request)
203+
if err != nil {
204+
fmt.Println("Error:", err)
205+
return nil, err
206+
}
207+
208+
var gitopsAbacRuleResponse GitopsAbacRuleResponse
209+
err = DecodeGraphQLResponseInto(response, &gitopsAbacRuleResponse)
210+
if err != nil {
211+
return nil, err
212+
}
213+
214+
return &gitopsAbacRuleResponse.Data.UpdateAbacRule, nil
215+
}
216+
168217
func (client *Client) DeleteAbacRule(id string) (*GitopsAbacRule, error) {
169218
request := GraphQLRequest{
170219
Query: `

codefresh/resource_abac_rules.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package codefresh
33
import (
44
"context"
55
"fmt"
6-
"log"
76

87
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient"
98
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/internal/datautil"
@@ -58,6 +57,10 @@ The effective tags of the resource to apply the permission to. There are two spe
5857
`,
5958
Type: schema.TypeSet,
6059
Optional: true,
60+
Computed: true,
61+
DefaultFunc: func() (interface{}, error) {
62+
return []string{"*", "untagged"}, nil
63+
},
6164
Elem: &schema.Schema{
6265
Type: schema.TypeString,
6366
},
@@ -102,7 +105,6 @@ Action to be allowed. Possible values:
102105
},
103106
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, v interface{}) error {
104107
actions := diff.Get("actions").(*schema.Set).List()
105-
106108
for _, action := range actions {
107109
actionStr := action.(string)
108110
if !contains(validSetValues, actionStr) {
@@ -169,17 +171,11 @@ func resourceGitopsAbacRuleUpdate(d *schema.ResourceData, meta interface{}) erro
169171
client := meta.(*cfclient.Client)
170172

171173
abacRule := *mapResourceToGitopsAbacRule(d)
172-
resp, err := client.CreateAbacRule(&abacRule)
174+
_, err := client.UpdateAbacRule(&abacRule)
173175
if err != nil {
174176
return err
175177
}
176178

177-
deleteErr := resourceGitopsAbacRuleDelete(d, meta)
178-
if deleteErr != nil {
179-
log.Printf("[WARN] failed to delete permission %v: %v", abacRule, deleteErr)
180-
}
181-
d.SetId(resp.ID)
182-
183179
return resourceGitopsAbacRuleRead(d, meta)
184180
}
185181

0 commit comments

Comments
 (0)