Skip to content

Commit 9bf39ec

Browse files
add support for ruletype in permission
1 parent 59f99a0 commit 9bf39ec

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

codefresh/cfclient/permission.go

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Permission struct {
1212
RelatedResource string `json:"relatedResource,omitempty"`
1313
Action string `json:"action,omitempty"`
1414
Account string `json:"account,omitempty"`
15+
RuleType string `json:"ruleType,omitempty"`
1516
Tags []string `json:"attributes,omitempty"`
1617
}
1718

@@ -23,6 +24,7 @@ type NewPermission struct {
2324
RelatedResource string `json:"relatedResource,omitempty"`
2425
Action string `json:"action,omitempty"`
2526
Account string `json:"account,omitempty"`
27+
RuleType string `json:"ruleType,omitempty"`
2628
Tags []string `json:"tags,omitempty"`
2729
}
2830

@@ -93,6 +95,7 @@ func (client *Client) CreatePermission(permission *Permission) (*Permission, err
9395
RelatedResource: permission.RelatedResource,
9496
Action: permission.Action,
9597
Account: permission.Account,
98+
RuleType: permission.RuleType,
9699
Tags: permission.Tags,
97100
}
98101

codefresh/resource_permission.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ Action to be allowed. Possible values:
8484
"debug",
8585
}, false),
8686
},
87+
"rule_type": {
88+
Description: "Rule type - can be either `all` or `any`. If all is specified the rule will apply on resources that have all the tags. If any is specified the rule will apply on resources that have any of the tags. If not specified, deafult behavior is `any`.",
89+
Type: schema.TypeString,
90+
Optional: true,
91+
//Default: "any",
92+
ValidateFunc: validation.StringInSlice([]string{"all", "any"}, false),
93+
},
8794
"tags": {
8895
Description: `
8996
The tags for which to apply the permission. Supports two custom tags:
@@ -163,7 +170,7 @@ func resourcePermissionUpdate(d *schema.ResourceData, meta interface{}) error {
163170
permission := *mapResourceToPermission(d)
164171

165172
// In case team, action or relatedResource or resource have changed - a new permission needs to be created (but without recreating the terraform resource as destruction of resources is alarming for end users)
166-
if d.HasChanges("team", "action", "related_resource", "resource") {
173+
if d.HasChanges("team", "action", "related_resource", "resource", "rule_type") {
167174
deleteErr := resourcePermissionDelete(d, meta)
168175

169176
if deleteErr != nil {
@@ -231,6 +238,11 @@ func mapPermissionToResource(permission *cfclient.Permission, d *schema.Resource
231238
return err
232239
}
233240

241+
err = d.Set("rule_type", permission.RuleType)
242+
if err != nil {
243+
return err
244+
}
245+
234246
return nil
235247
}
236248

@@ -249,6 +261,7 @@ func mapResourceToPermission(d *schema.ResourceData) *cfclient.Permission {
249261
Action: d.Get("action").(string),
250262
Resource: d.Get("resource").(string),
251263
RelatedResource: d.Get("related_resource").(string),
264+
RuleType: d.Get("rule_type").(string),
252265
Tags: tags,
253266
}
254267

docs/resources/permission.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ resource "codefresh_permission" "developers" {
5959
- `_id` (String) The permission ID.
6060
- `related_resource` (String) Specifies the resource to use when evaluating the tags. Possible values:
6161
* project
62+
- `rule_type` (String) Rule type - can be either `all` or `any`. If all is specified the rule will apply on resources that have all the tags. If any is specified the rule will apply on resources that have any of the tags. If not specified, deafult behavior is `any`.
6263
- `tags` (Set of String) The tags for which to apply the permission. Supports two custom tags:
6364
* untagged: Apply to all resources without tags
6465
* (asterisk): Apply to all resources with any tag

0 commit comments

Comments
 (0)