Skip to content
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

[resource_datadog_domain_allowlist] Domain allowlist provider support #2637

Merged
merged 19 commits into from
Nov 11, 2024

Conversation

diab42
Copy link
Contributor

@diab42 diab42 commented Oct 30, 2024

For the general release of the domain allowlist feature we need to support enabling the domain allowlist via terraform.

When enabled, the domain allowlist blocks emails of certain types from being sent to email domains outside the set list.

@diab42 diab42 marked this pull request as ready for review November 8, 2024 18:20
@diab42 diab42 requested review from a team as code owners November 8, 2024 18:20
@diab42 diab42 changed the title Domain allowlist [DOGMAIL-257] Domain allowlist provider support Nov 8, 2024
estherk15
estherk15 previously approved these changes Nov 8, 2024
@jack-edmonds-dd jack-edmonds-dd changed the title [DOGMAIL-257] Domain allowlist provider support [resource_datadog_domain_allowlist] Domain allowlist provider support Nov 8, 2024
Copy link
Contributor

@alexaliaskovski alexaliaskovski left a comment

Choose a reason for hiding this comment

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

I'm curious whether there's been any product interest in eventually having separate domain allowlists for different email types, or if we plan to have one overarching one? If we might have many different Domain Allowlists, could this provider be easily backwards-compatible? We don't need a full solution now -- just want to get a sense for how much effort it might be to introduce a Allowlist Split in the future.

Perhaps if we still had a "Default" allowlist, and then optional "Override" allowlists for different email types, this would be easy to support.

@@ -356,6 +357,14 @@ func (i *ApiInstances) GetCSMThreatsApiV2() *datadogV2.CSMThreatsApi {
return i.csmThreatsApiV2
}

// GetDoomainAllowlittApiV2 get instance of DowntimesApi
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// GetDoomainAllowlittApiV2 get instance of DowntimesApi
// GetDomainAllowlistApiV2 get instance of DowntimesApi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected and found a few other typos.

@@ -0,0 +1,4 @@
resource "datadog_ip_allowlist" "example" {
enabled = true
Copy link
Contributor

Choose a reason for hiding this comment

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

How would this work if a user tried to set

Suggested change
enabled = true
enabled = False

In the API this would be an invalid input -- does Terraform give similar feedback?

Copy link
Contributor Author

@diab42 diab42 Nov 11, 2024

Choose a reason for hiding this comment

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

So that should be able to be replicated within the tests. I updated to set that in line 72 in the test file

The error message from the command is

=== RUN   TestAccDatadogDomainAllowlist_CreateUpdate
    resource_datadog_domain_allowlist_test.go:21: Step 1/2 error: Error running pre-apply refresh: exit status 1
        
        Error: Invalid reference
        
          on terraform_plugin_test.tf line 3, in resource "datadog_domain_allowlist" "foo":
           3: 	enabled = False
        
        A reference to a resource type must be followed by at least one attribute
        access, specifying the resource name.

I'm not sure if that's the general command error we return when the input is invalid in the provider.

If you want to confirm the command to run it against backend instead of the saved cassette file is TESTARGS="-run TestAccDatadogDomainAllowlist_CreateUpdate" make cassettes

@diab42
Copy link
Contributor Author

diab42 commented Nov 11, 2024

I'm curious whether there's been any product interest in eventually having separate domain allowlists for different email types, or if we plan to have one overarching one? If we might have many different Domain Allowlists, could this provider be easily backwards-compatible? We don't need a full solution now -- just want to get a sense for how much effort it might be to introduce a Allowlist Split in the future.

Perhaps if we still had a "Default" allowlist, and then optional "Override" allowlists for different email types, this would be easy to support.

I have seen some product interest from the beta customers to manage different email types in the domain allowlist from each other. I'm not sure there is any specific customers who have expressed interest in multiple different domain allowlists but it is possible. I'm checking with the PM whether that has ever been asked for by the beta customers.

What you're suggesting should be easier to make it backwards compatible and matches the overall requests we have so far. If we had multiple lists to manage, it would be much harder to make this backwards compatible. We could think about making this internally a list to start but that might be overkill if we don't know whether that will ever be wanted.

@diab42 diab42 changed the title [resource_datadog_domain_allowlist] Domain allowlist provider support [resource_datadog_domain_allowlist][DOGMAIL-257] Domain allowlist provider support Nov 11, 2024
@diab42 diab42 changed the title [resource_datadog_domain_allowlist][DOGMAIL-257] Domain allowlist provider support [resource_datadog_domain_allowlist] Domain allowlist provider support Nov 11, 2024
Copy link
Contributor

@alexaliaskovski alexaliaskovski left a comment

Choose a reason for hiding this comment

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

LGTM, with some qs and nits.

Description: "The domains within the domain allowlist.",
ElementType: types.StringType,
Required: true,
Computed: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Out-of-curiosity, what does this param computed mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the hashicorp terraform-provider-framework comment

	// Computed indicates whether the provider may return its own value for
	// this Attribute or not. Required and Computed cannot both be true. If
	// Required and Optional are both false, Computed must be true, and the
	// attribute will be considered "read only" for the practitioner, with
	// only the provider able to set its value.

remote_addr: ""
request_uri: ""
body: |
{"data":{"attributes":{"domains":["@test.com","@datadoghq.com"],"enabled":true},"type":"domain_allowlist"}}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: domains and enabled aren't consistently in the same order in this file, not sure if it's autogenerated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is autogenerated from the response from the server. Should be fine that they're out of order.

}
resp, httpResp, err := r.Api.PatchDomainAllowlist(r.Auth, *domainAllowlistReq)
if err != nil {
response.Diagnostics.Append(utils.FrameworkErrorDiag(utils.TranslateClientError(err, httpResp, " error updating domain allowlist"), ""))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
response.Diagnostics.Append(utils.FrameworkErrorDiag(utils.TranslateClientError(err, httpResp, " error updating domain allowlist"), ""))
response.Diagnostics.Append(utils.FrameworkErrorDiag(utils.TranslateClientError(err, httpResp, "error updating domain allowlist"), ""))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated this and the other comment in a new commit

domainAllowlistReq, _ := buildDomainAllowlistUpdateRequest(state)
resp, httpResp, err := r.Api.PatchDomainAllowlist(r.Auth, *domainAllowlistReq)
if err != nil {
response.Diagnostics.Append(utils.FrameworkErrorDiag(utils.TranslateClientError(err, httpResp, ""), "error updating email domain allowlist"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
response.Diagnostics.Append(utils.FrameworkErrorDiag(utils.TranslateClientError(err, httpResp, ""), "error updating email domain allowlist"))
response.Diagnostics.Append(utils.FrameworkErrorDiag(utils.TranslateClientError(err, httpResp, ""), "error creating email domain allowlist"))

In this context this might make more sense? But I don't feel strongly about this change, whatever makes more sense for user experience when config.

@jack-edmonds-dd jack-edmonds-dd merged commit 1a9bcec into master Nov 11, 2024
11 checks passed
@jack-edmonds-dd jack-edmonds-dd deleted the domainAllowlist branch November 11, 2024 20:51
skarimo added a commit that referenced this pull request Nov 11, 2024
skarimo added a commit that referenced this pull request Nov 11, 2024
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.

4 participants