-
Notifications
You must be signed in to change notification settings - Fork 392
[datadog_csm_threats] supporting cws multi-policy in terraform #2681
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
base: master
Are you sure you want to change the base?
Conversation
6322019
to
5da3fb7
Compare
datadog/fwprovider/resource_datadog_csm_threats_multi_policies.go
Outdated
Show resolved
Hide resolved
bf4b1af
to
4c19fd8
Compare
a390790
to
6fc7905
Compare
datadog/fwprovider/resource_datadog_csm_threats_multi_policies.go
Outdated
Show resolved
Hide resolved
f715a3a
to
595f718
Compare
8c3f3f3
to
1d306ae
Compare
datadog/fwprovider/resource_datadog_csm_threats_multi_policy_agent_rule.go
Outdated
Show resolved
Hide resolved
datadog/fwprovider/resource_datadog_csm_threats_multi_policy_agent_rule.go
Show resolved
Hide resolved
datadog/data_source_datadog_cloud_workload_security_agent_rules.go
Outdated
Show resolved
Hide resolved
2c6ae21
to
37ea69b
Compare
a8a6b1c
to
fdbc105
Compare
fdbc105
to
3f0069d
Compare
84f08b8
to
b528f99
Compare
datadog/fwprovider/data_source_datadog_csm_threats_agent_rule.go
Outdated
Show resolved
Hide resolved
datadog/data_source_datadog_cloud_workload_security_agent_rules.go
Outdated
Show resolved
Hide resolved
@@ -51,44 +61,113 @@ func (r *csmThreatsAgentRulesDataSource) Read(ctx context.Context, request datas | |||
return | |||
} | |||
|
|||
res, _, err := r.api.ListCSMThreatsAgentRules(r.auth) | |||
// Fetch CWS rules (without policy_id), using /security_monitoring/cloud_workload_security/agent_rules path | |||
cwsRules, _, err := r.api.ListCloudWorkloadSecurityAgentRules(r.auth) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there was a misunderstanding. I was suggesting that we use this data source to handle only rules from RC (by calling ListCSMThreatsAgentRules
) and we let data_source_datadog_cloud_workload_security_agent_rules
handle rules from Mongo.
I don't see why we need to merge rules from Mongo and RC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad, I moved multi_policy_agent_rules
to agent_rules
and readded cloud_workload_security_agent_rules
6fbce23
to
2481912
Compare
2481912
to
cf16019
Compare
r.api = providerData.DatadogApiInstances.GetCSMThreatsApiV2() | ||
r.auth = providerData.Auth | ||
} | ||
|
||
func (*csmThreatsAgentRulesDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, response *datasource.MetadataResponse) { | ||
func (r *csmThreatsAgentRulesDataSource) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe you don't need this change?
@@ -93,9 +111,6 @@ func (r *csmThreatsAgentRuleResource) Create(ctx context.Context, request resour | |||
return | |||
} | |||
|
|||
csmThreatsMutex.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this deleted? I thought we need this to prevent terraform from creating multiple rules simultaneously.
@@ -29,10 +29,12 @@ resource "datadog_csm_threats_agent_rule" "my_agent_rule" { | |||
- `enabled` (Boolean) Indicates Whether the Agent rule is enabled. | |||
- `expression` (String) The SECL expression of the Agent rule | |||
- `name` (String) The name of the Agent rule. | |||
- `policy_id` (String) The ID of the agent policy in which the rule is saved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update the Import
section below? I think we should support both of these.
terraform import datadog_csm_threats_agent_rule.my_agent_rule <policy ID>:<rule ID>
terraform import datadog_csm_threats_agent_rule.my_agent_rule <rule ID>
resource.ImportStatePassthroughID(ctx, path.Root("id"), request, response) | ||
result := strings.SplitN(request.ID, ":", 2) | ||
if len(result) != 2 { | ||
response.Diagnostics.AddError("error retrieving policy_id or rule_id from given ID", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it's possible to make it backward compatible. When this happens, instead of throwing an error, we just assume that it's a rule ID and the policy ID is not provided.
@@ -123,7 +138,8 @@ func (r *csmThreatsAgentRuleResource) Read(ctx context.Context, request resource | |||
} | |||
|
|||
agentRuleId := state.Id.ValueString() | |||
res, httpResponse, err := r.api.GetCSMThreatsAgentRule(r.auth, agentRuleId) | |||
policyId := state.PolicyId.ValueString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that the policyId is not in the state? Can we not set it in the request if that's the case?
// Mandatory fields | ||
id := state.Id.ValueString() | ||
policyId := state.PolicyId.ValueString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not return an empty string if it's not there.
Adding new resources and data sources to support the CWS multi-policy feature.
datadog_csm_threats_agent_rule
for users to manage their rulesdatadog_csm_threats_policy
for users to manage their policies.