Skip to content

[datadog_compliance_custom_framework] Terraform Provider for Custom Frameworks #2975

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

Open
wants to merge 55 commits into
base: master
Choose a base branch
from

Conversation

nkonjeti
Copy link

@nkonjeti nkonjeti commented Apr 16, 2025

Motivation:

We wanted a terraform provider to interact with our Custom Framework APIs. The terraform resources will remain as the source of truth so whenever a resource is updated/created/deleted this will be reflected in the database and UI.

Testing

I built the Terrraform provider locally.

Tested the following:

Creating
Screenshot 2025-04-25 at 4 36 07 PM

Updating
Screenshot 2025-04-25 at 4 37 17 PM

Deleting/Destroying
Screenshot 2025-04-25 at 4 38 52 PM

Changing order of rules
Screenshot 2025-04-27 at 4 07 16 PM
no changes in state so no action taken

Terraform Provider Immutable Fields (Handle And Version)
Screenshot 2025-05-19 at 10 23 46 AM

  • if handle or version is changed in a framework this will delete the old framework and create a new one with the new handle and version
Screenshot 2025-05-19 at 10 16 40 AM
  • in this example, updating the version to 2 deleted the old framework (version 1) and created a new framework with version 2
Screenshot 2025-05-19 at 10 20 48 AM
  • in this example updating the handle and version deleted the old framework with the old handle and version, and created a new framework with the new handle and version

Testing Large Input
Created this Framework: https://dd.datad0g.com/security/compliance/home/custom/my-custom-framework-terraform-3/3.0.0?previousUrl=%2Fsecurity%2Fcompliance%2Fhome&timestamp=1747948011353&live=true
one control with over 200 rule ids (seconds to complete)

Commands:

cd examples/resources/datadog_custom_framework 
terraform init
terraform plan -var="datadog_api_key=<>" -var="datadog_app_key=<>"
terraform apply

also added unit tests!

@nkonjeti nkonjeti requested review from a team as code owners April 16, 2025 22:27
@nkonjeti nkonjeti changed the title provider for custom frameworks Terraform Provider for Custom Frameworks Apr 24, 2025
@nkonjeti nkonjeti force-pushed the neha.konjeti/framework-provider branch from ccaf302 to f8a90fe Compare April 25, 2025 18:59
@nkonjeti nkonjeti marked this pull request as draft April 25, 2025 20:34
@nkonjeti nkonjeti changed the title Terraform Provider for Custom Frameworks [K9VULN-4477]: Terraform Provider for Custom Frameworks Apr 30, 2025
@nkonjeti nkonjeti marked this pull request as ready for review May 1, 2025 21:14
@nkonjeti nkonjeti requested a review from a team as a code owner May 1, 2025 21:14
@nkonjeti nkonjeti changed the title [K9VULN-4477]: Terraform Provider for Custom Frameworks Terraform Provider for Custom Frameworks May 2, 2025
@nkonjeti nkonjeti force-pushed the neha.konjeti/framework-provider branch from ac03605 to e2e496e Compare May 14, 2025 17:25
@nkonjeti nkonjeti requested a review from vbarth2 May 14, 2025 17:37
@nkonjeti nkonjeti requested a review from vbarth2 May 16, 2025 17:50
@fpighi fpighi changed the title Terraform Provider for Custom Frameworks [datadog_compliance_custom_framework] Terraform Provider for Custom Frameworks May 19, 2025

_, httpResp, err := r.Api.CreateCustomFramework(r.Auth, *buildCreateFrameworkRequest(state))
if err != nil {
if httpResp != nil && httpResp.StatusCode == 409 { // if framework already exists, try to update it with the new state
Copy link
Author

Choose a reason for hiding this comment

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

changed this code under the if statement

"requirements": schema.ListNestedBlock{
Description: "The requirements of the framework.",
Validators: []validator.List{
validators.DuplicateRequirementControlValidator(),
Copy link
Author

Choose a reason for hiding this comment

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

change: merged the two validators into one

apiControlMap[req.GetName()][control.GetName()] = control
}
}

Copy link
Author

Choose a reason for hiding this comment

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

change: below this comment

sorting the API response to match the order of the state because the requirements and controls are lists - to prevent a diff being created each time "terraform plan" is done

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

Successfully merging this pull request may close these issues.

5 participants