Skip to content

Commit

Permalink
[fix]:[CDS-75647] fix policyset showing diff (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
RajBaviskar committed Aug 21, 2023
1 parent 8c76145 commit f26c888
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
1 change: 0 additions & 1 deletion internal/service/platform/policy/resource_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func readPolicy(d *schema.ResourceData, policy policymgmt.Policy) {
d.SetId(policy.Identifier)
_ = d.Set("identifier", policy.Identifier)
_ = d.Set("org_id", policy.OrgId)
_ = d.Set("account_id", policy.AccountId)
_ = d.Set("project_id", policy.ProjectId)
_ = d.Set("name", policy.Name)
_ = d.Set("rego", policy.Rego)
Expand Down
8 changes: 2 additions & 6 deletions internal/service/platform/policyset/resource_policyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ResourcePolicyset() *schema.Resource {
UpdateContext: resourcePolicysetCreateOrUpdate,
DeleteContext: resourcePolicysetDelete,
CreateContext: resourcePolicysetCreateOrUpdate,
Importer: helpers.OrgResourceImporter,
Importer: helpers.MultiLevelResourceImporter,

Schema: map[string]*schema.Schema{
"type": {
Expand All @@ -38,16 +38,13 @@ func ResourcePolicyset() *schema.Resource {
"enabled": {
Description: "Enabled for the policyset.",
Type: schema.TypeBool,
Required: false,
Computed: false,
Optional: true,
},
"policies": {
Description: "List of policy identifiers / severity for the policyset.",
Type: schema.TypeList,
Computed: false,
Computed: true,
Optional: true,
Required: false,
MinItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -220,7 +217,6 @@ func readPolicyset(d *schema.ResourceData, policy policymgmt.PolicySet2) {
d.SetId(policy.Identifier)
_ = d.Set("identifier", policy.Identifier)
_ = d.Set("org_id", policy.OrgId)
_ = d.Set("account_id", policy.AccountId)
_ = d.Set("project_id", policy.ProjectId)
_ = d.Set("name", policy.Name)
_ = d.Set("action", policy.Action)
Expand Down
21 changes: 16 additions & 5 deletions internal/service/platform/policyset/resource_policyset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,23 @@ func TestAccResourcePolicyset(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: acctest.OrgResourceImportStateIdFunc(resourceName),
ImportStateIdFunc: acctest.AccountLevelResourceImportStateIdFunc(resourceName),
},
},
})
}

func testAccResourcePolicyset(id, name, action, policyType string, enabled bool) string {
return fmt.Sprintf(`
resource "harness_platform_policy" "test" {
identifier = "%[1]s"
name = "%[1]s"
resource "harness_platform_policy" "first" {
identifier = "policyFirst"
name = "policyFirst"
rego = "some text"
}
resource "harness_platform_policy" "second" {
identifier = "policySecond"
name = "policySecond"
rego = "some text"
}
resource "harness_platform_policyset" "test" {
Expand All @@ -73,7 +79,12 @@ func testAccResourcePolicyset(id, name, action, policyType string, enabled bool)
type = "%[4]s"
enabled = %[5]t
policies {
identifier = "%[1]s"
identifier = harness_platform_policy.first.identifier
severity = "warning"
}
policies {
identifier = harness_platform_policy.second.identifier
severity = "warning"
}
}
Expand Down

0 comments on commit f26c888

Please sign in to comment.