Skip to content

Add support for change request policies #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2025
Merged

Conversation

emily-curry
Copy link
Contributor

This change adds support for managing CR policies via terraform.

CR policies are not generally available yet, and the API endpoints used here are not available publicly. We'll hold on merging/releasing these changes until CR policies are released.

Copy link
Member

@nmanoogian nmanoogian left a comment

Choose a reason for hiding this comment

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

Awesome job, @emily-curry! Really solid implementation and things work exactly as I expected.

Manage a Doppler change request policy.
---

# doppler_change_request_policy (Resource)
Copy link
Member

Choose a reason for hiding this comment

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

Nice example 👍 Unfortunately these docs aren't rendered into markdown automatically and we need to generate them manually with make tfdocs and commit them. I've added a check in #121 to verify that the generated docs are up-to-date with the source files.

For convenience, you can add the missing rendered file with this patch:

diff --git a/docs/resources/change_request_policy.md b/docs/resources/change_request_policy.md
new file mode 100644
index 0000000..f35c3b7
--- /dev/null
+++ b/docs/resources/change_request_policy.md
@@ -0,0 +1,153 @@
+---
+page_title: "doppler_change_request_policy Resource - terraform-provider-doppler"
+subcategory: ""
+description: |-
+	Manage a Doppler change request policy.
+---
+
+# doppler_change_request_policy (Resource)
+
+Manage a Doppler change request policy.
+
+## Example Usage
+
+```terraform
+data "doppler_user" "nic" {
+  email = "[email protected]"
+}
+
+data "doppler_user" "emily" {
+  email = "[email protected]"
+}
+
+resource "doppler_project" "test_proj" {
+  name = "my-test-project"
+  description = "This is a test project"
+}
+
+resource "doppler_environment" "prd" {
+  project = doppler_project.test_proj.name
+  slug = "prd"
+  name = "prd"
+}
+
+resource "doppler_environment" "ci" {
+  project = doppler_project.test_proj.name
+  slug = "ci"
+  name = "CI-CD"
+}
+
+resource "doppler_config" "ci_github" {
+  project = doppler_project.test_proj.name
+  environment = doppler_environment.ci.slug
+  name = "ci_github"
+}
+
+resource "doppler_group" "prod_reviewers" {
+  name = "Prod Reviewers"
+}
+
+resource "doppler_group_member" "prod_reviewers" {
+  for_each   = toset([data.doppler_user.nic.slug])
+  group_slug = doppler_group.prod_reviewers.slug
+  user_slug  = each.value
+}
+
+resource "doppler_change_request_policy" "prd_review" {
+  name = "Prod Review"
+  description = <<EOT
+A change request policy which requires 2 total approvals, and 1 approval from emily or any member of the prod_reviewers group.
+Reviews from the author of the change request are not counted.
+This policy is enforced in all configs of the prd environment of test_proj, as well as the ci_github branch config.
+EOT
+  rules {
+    disallow_self_review = true 
+    
+    required_reviewers {
+      count = 2
+    } 
+    
+    required_reviewers {
+      count = 1
+      group_slugs = [doppler_group.prod_reviewers.slug]
+      user_slugs = [data.doppler_user.emily.slug]
+    }
+  }
+  targets {
+    project {
+      project_name = doppler_project.test_proj.name
+      environment_slugs = [doppler_environment.prd.slug]
+      config_names = [doppler_config.ci_github.name]
+    }
+  }
+}
+```
+
+<!-- schema generated by tfplugindocs -->
+## Schema
+
+### Required
+
+- `name` (String) The name of the change request policy
+- `rules` (Block List, Min: 1, Max: 1) Rules that the policy will apply to its targets (see [below for nested schema](#nestedblock--rules))
+- `targets` (Block List, Min: 1, Max: 1) Where the policy will apply (see [below for nested schema](#nestedblock--targets))
+
+### Optional
+
+- `description` (String) A description of the change request policy
+
+### Read-Only
+
+- `id` (String) The ID of this resource.
+- `slug` (String) The unique identifier of the change request policy
+
+<a id="nestedblock--rules"></a>
+### Nested Schema for `rules`
+
+Optional:
+
+- `disallow_self_review` (Boolean) If true, approvals from the author of a change request will be excluded when evaluating this policy
+- `required_reviewers` (Block Set) Enforces that a specific number of users approve a change request before it can be applied (see [below for nested schema](#nestedblock--rules--required_reviewers))
+
+<a id="nestedblock--rules--required_reviewers"></a>
+### Nested Schema for `rules.required_reviewers`
+
+Required:
+
+- `count` (Number) The number of approvals a a change request must recieve before it can be applied
+
+Optional:
+
+- `group_slugs` (Set of String) If set, only approvals from members of these groups will satisfy this rule
+- `user_slugs` (Set of String) If set, only approvals from these users will satisfy this rule
+
+
+
+<a id="nestedblock--targets"></a>
+### Nested Schema for `targets`
+
+Optional:
+
+- `all_projects` (Boolean) Whether or not the policy applies to all projects in the workplace
+- `project` (Block List) A project that the policy will apply to (see [below for nested schema](#nestedblock--targets--project))
+
+<a id="nestedblock--targets--project"></a>
+### Nested Schema for `targets.project`
+
+Required:
+
+- `project_name` (String) The name of the project to apply the policy to
+
+Optional:
+
+- `all` (Boolean) Whether or not the policy applies to all configs in the project
+- `config_names` (Set of String) Specific configs the policy applies to
+- `environment_slugs` (Set of String) Entire environments the policy applies to
+
+## Import
+
+Import is supported using the following syntax:
+
+```shell
+terraform import doppler_change_request_policy.<name> <change-request-policy-id>
+```

@emily-curry emily-curry merged commit 1b80404 into master Mar 4, 2025
4 of 5 checks passed
@emily-curry emily-curry deleted the emily/cr-policies branch March 4, 2025 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants