Skip to content

Add support for policy_update_patterns in policy_set#2030

Open
nithishravindra wants to merge 3 commits intomainfrom
nithish/TF-32131-update-policyset-1
Open

Add support for policy_update_patterns in policy_set#2030
nithishravindra wants to merge 3 commits intomainfrom
nithish/TF-32131-update-policyset-1

Conversation

@nithishravindra
Copy link
Copy Markdown
Member

@nithishravindra nithishravindra commented Apr 8, 2026

Description

Add PolicyUpdatePatterns support for policy sets (read/create/update) and tests

Remember to:

Testing plan

  1. Describe how to replicate
  2. the conditions
  3. under which your code performs its purpose,
  4. including example Terraform configs where necessary.

External links

Include any links here that might be helpful for people reviewing your PR. If there are none, feel free to delete this section.

Output from acceptance tests

Please run applicable acceptance tests locally and include the output here. See testing.md to learn how to run acceptance tests.

If you are an external contributor, your contribution(s) will first be reviewed before running them against the project's CI pipeline.

resource "tfe_policy_set" "dummy_patterns" {
  name                = "dummy-policy-set-update-patterns"
  description         = "Dummy policy set for update pattern testing"
  organization        = data.tfe_organization.test.name
  kind                = "sentinel"
  agent_enabled       = true
  policy_tool_version = "0.24.1"
  workspace_ids       = ["ws-x"]
  policy_update_patterns = [
    "policies/dummy-policy-set/*",
    "sentinel/*.sentinel",
  ]

  vcs_repo {
    identifier                 = "xxx/xxx"
    ingress_submodules         = false
    github_app_installation_id = "ghain-xxx"
  }
}

output "dummy_policy_set_id" {
  value = tfe_policy_set.dummy_patterns.id
}

...

Rollback Plan

Changes to Security Controls

@nithishravindra nithishravindra marked this pull request as ready for review April 8, 2026 09:58
@nithishravindra nithishravindra requested a review from a team as a code owner April 8, 2026 09:58
@nithishravindra nithishravindra marked this pull request as draft April 8, 2026 09:58
@nithishravindra nithishravindra marked this pull request as ready for review April 15, 2026 08:58
}

if d.HasChange("policy_update_patterns") {
for _, pattern := range d.Get("policy_update_patterns").([]interface{}) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: iteration can be moved to another function and reused


// Don't bother updating the policy set's attributes if they haven't changed
if d.HasChange("name") || d.HasChange("description") || d.HasChange("global") || d.HasChange("vcs_repo") || d.HasChange("overridable") || d.HasChange("agent_enabled") || d.HasChange("policy_tool_version") {
if d.HasChange("name") || d.HasChange("description") || d.HasChange("global") || d.HasChange("vcs_repo") || d.HasChange("overridable") || d.HasChange("agent_enabled") || d.HasChange("policy_tool_version") || d.HasChange("policy_update_patterns") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can be rewitten like

fields := []string{
    "name", "description", "global", "vcs_repo", 
    "overridable", "agent_enabled", "policy_tool_version", 
    "policy_update_patterns",
}

hasAnyChange := false
for _, field := range fields {
    if d.HasChange(field) {
        hasAnyChange = true
        break
    }
}

if hasAnyChange {
    ....
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants