Skip to content

Commit 0fcb6a2

Browse files
feat: add abac rules for products, environments, and promotion flows (#151)
1 parent 3fe2bc4 commit 0fcb6a2

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

Diff for: codefresh/resource_abac_rules.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1212
)
1313

14-
var validSetValues = []string{"REFRESH", "SYNC", "TERMINATE_SYNC", "VIEW_POD_LOGS", "APP_ROLLBACK"}
14+
var validSetValues = []string{"REFRESH", "SYNC", "TERMINATE_SYNC", "VIEW_POD_LOGS", "APP_ROLLBACK", "TRIGGER_PROMOTION", "RETRY_RELEASE", "PROMOTE_TO"}
1515

1616
func resourceGitopsAbacRule() *schema.Resource {
1717
return &schema.Resource{
@@ -34,11 +34,14 @@ func resourceGitopsAbacRule() *schema.Resource {
3434
Description: `
3535
The type of resources the ABAC rules applies to. Possible values:
3636
* gitopsApplications
37+
* promotionFlows
38+
* products
39+
* environments
3740
`,
3841
Type: schema.TypeString,
3942
Required: true,
4043
ValidateFunc: validation.StringInSlice([]string{
41-
"gitopsApplications",
44+
"gitopsApplications", "promotionFlows", "products", "environments",
4245
}, false),
4346
},
4447
"teams": {
@@ -67,6 +70,9 @@ Action to be allowed. Possible values:
6770
* TERMINATE_SYNC
6871
* VIEW_POD_LOGS
6972
* APP_ROLLBACK
73+
* TRIGGER_PROMOTION
74+
* RETRY_RELEASE
75+
* PROMOTE_TO
7076
`,
7177
Type: schema.TypeSet,
7278
Required: true,

Diff for: codefresh/resource_abac_rules_test.go

+53-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import (
66
"testing"
77

88
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient"
9-
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
10-
119
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1211
funk "github.com/thoas/go-funk"
1312
)
1413

@@ -41,6 +40,58 @@ func TestAccCodefreshAbacRulesConfig(t *testing.T) {
4140
resource.TestCheckResourceAttr(resourceName, "tags.1", "production"),
4241
),
4342
},
43+
{
44+
Config: testAccCodefreshAbacRulesConfig(
45+
"promotionFlows",
46+
"",
47+
"",
48+
"",
49+
[]string{"TRIGGER_PROMOTION"},
50+
[]string{"staging"},
51+
),
52+
Check: resource.ComposeTestCheckFunc(
53+
testAccCheckCodefreshAbacRulesExists(resourceName),
54+
resource.TestCheckResourceAttr(resourceName, "entity_type", "promotionFlows"),
55+
resource.TestCheckResourceAttr(resourceName, "actions.0", "TRIGGER_PROMOTION"),
56+
resource.TestCheckResourceAttr(resourceName, "tags.0", "staging"),
57+
),
58+
},
59+
{
60+
Config: testAccCodefreshAbacRulesConfig(
61+
"products",
62+
"",
63+
"",
64+
"",
65+
[]string{"TRIGGER_PROMOTION", "RETRY_RELEASE"},
66+
[]string{"dev", "qa"},
67+
),
68+
Check: resource.ComposeTestCheckFunc(
69+
testAccCheckCodefreshAbacRulesExists(resourceName),
70+
resource.TestCheckResourceAttr(resourceName, "entity_type", "products"),
71+
resource.TestCheckResourceAttr(resourceName, "actions.#", "2"),
72+
resource.TestCheckTypeSetElemAttr(resourceName, "actions.*", "TRIGGER_PROMOTION"),
73+
resource.TestCheckTypeSetElemAttr(resourceName, "actions.*", "RETRY_RELEASE"),
74+
resource.TestCheckResourceAttr(resourceName, "tags.#", "2"),
75+
resource.TestCheckTypeSetElemAttr(resourceName, "tags.*", "dev"),
76+
resource.TestCheckTypeSetElemAttr(resourceName, "tags.*", "qa"),
77+
),
78+
},
79+
{
80+
Config: testAccCodefreshAbacRulesConfig(
81+
"environments",
82+
"",
83+
"",
84+
"",
85+
[]string{"PROMOTE_TO"},
86+
[]string{"production"},
87+
),
88+
Check: resource.ComposeTestCheckFunc(
89+
testAccCheckCodefreshAbacRulesExists(resourceName),
90+
resource.TestCheckResourceAttr(resourceName, "entity_type", "environments"),
91+
resource.TestCheckResourceAttr(resourceName, "actions.0", "PROMOTE_TO"),
92+
resource.TestCheckResourceAttr(resourceName, "tags.0", "production"),
93+
),
94+
},
4495
{
4596
ResourceName: resourceName,
4697
ImportState: true,

Diff for: docs/resources/abac_rules.md

+6
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ resource "codefresh_abac_rules" "app_rule" {
4848
* TERMINATE_SYNC
4949
* VIEW_POD_LOGS
5050
* APP_ROLLBACK
51+
* TRIGGER_PROMOTION
52+
* RETRY_RELEASE
53+
* PROMOTE_TO
5154
- `entity_type` (String) The type of resources the ABAC rules applies to. Possible values:
5255
* gitopsApplications
56+
* promotionFlows
57+
* products
58+
* environments
5359
- `teams` (Set of String) The IDs of the teams the ABAC rules apply to.
5460

5561
### Optional

0 commit comments

Comments
 (0)