Skip to content

Commit

Permalink
Merge branch 'master' into jirikuncar/synthetics-retry-multi-step
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikuncar committed Jan 4, 2022
2 parents 4ba8641 + e3a8da8 commit c1067b3
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 146 deletions.
3 changes: 0 additions & 3 deletions datadog/data_source_datadog_security_monitoring_rules.go
Expand Up @@ -206,9 +206,6 @@ func buildSecurityMonitoringTfRule(rule datadogV2.SecurityMonitoringRuleResponse
tfQueries := make([]map[string]interface{}, len(rule.GetQueries()))
for i, query := range rule.GetQueries() {
tfQuery := make(map[string]interface{})
if agentRule, ok := query.GetAgentRuleOk(); ok {
tfQuery["agent_rule"] = extractTfAgentRule(*agentRule)
}
if aggregation, ok := query.GetAggregationOk(); ok {
tfQuery["aggregation"] = string(*aggregation)
}
Expand Down
3 changes: 2 additions & 1 deletion datadog/resource_datadog_application_key.go
Expand Up @@ -46,7 +46,8 @@ func buildDatadogApplicationKeyCreateV2Struct(d *schema.ResourceData) *datadogV2
}

func buildDatadogApplicationKeyUpdateV2Struct(d *schema.ResourceData) *datadogV2.ApplicationKeyUpdateRequest {
applicationKeyAttributes := datadogV2.NewApplicationKeyUpdateAttributes(d.Get("name").(string))
applicationKeyAttributes := datadogV2.NewApplicationKeyUpdateAttributes()
applicationKeyAttributes.SetName(d.Get("name").(string))
applicationKeyData := datadogV2.NewApplicationKeyUpdateData(*applicationKeyAttributes, d.Id(), datadogV2.APPLICATIONKEYSTYPE_APPLICATION_KEYS)
applicationKeyRequest := datadogV2.NewApplicationKeyUpdateRequest(*applicationKeyData)

Expand Down
48 changes: 4 additions & 44 deletions datadog/resource_datadog_security_monitoring_rule.go
Expand Up @@ -159,19 +159,20 @@ func datadogSecurityMonitoringRuleSchema() map[string]*schema.Schema {
Schema: map[string]*schema.Schema{
"agent_rule": {
Type: schema.TypeList,
Deprecated: "`agent_rule` has been deprecated in favor of new Agent Rule resource.",
Optional: true,
Description: "The agent rule.",
Description: "**Deprecated**. It won't be applied anymore.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"agent_rule_id": {
Type: schema.TypeString,
Required: true,
Description: "The Agent rule ID. Must be unique within the rule.",
Description: "**Deprecated**. It won't be applied anymore.",
},
"expression": {
Type: schema.TypeString,
Required: true,
Description: "A Runtime Security expression determines what activity should be collected by the Datadog Agent. These logical expressions can use predefined operators and attributes. Tags cannot be used in Runtime Security expressions. Instead, allow or deny based on tags under the advanced option.",
Description: "**Deprecated**. It won't be applied anymore.",
},
},
},
Expand Down Expand Up @@ -409,13 +410,6 @@ func buildCreatePayloadQueries(d *schema.ResourceData) []datadogV2.SecurityMonit
query := tfQuery.(map[string]interface{})
payloadQuery := datadogV2.SecurityMonitoringRuleQueryCreate{}

if v, ok := query["agent_rule"]; ok {
tfAgentRuleList := v.([]interface{})
if payloadAgentRule, ok := buildPayloadAgentRule(tfAgentRuleList); ok {
payloadQuery.AgentRule = payloadAgentRule
}
}

if v, ok := query["aggregation"]; ok {
aggregation := datadogV2.SecurityMonitoringRuleQueryAggregation(v.(string))
payloadQuery.Aggregation = &aggregation
Expand Down Expand Up @@ -456,23 +450,6 @@ func buildCreatePayloadQueries(d *schema.ResourceData) []datadogV2.SecurityMonit
return payloadQueries
}

func buildPayloadAgentRule(tfAgentRuleList []interface{}) (*datadogV2.SecurityMonitoringRuntimeAgentRule, bool) {
payloadAgentRule := datadogV2.NewSecurityMonitoringRuntimeAgentRule()
tfAgentRule := extractMapFromInterface(tfAgentRuleList)
hasPayload := false
if v, ok := tfAgentRule["agent_rule_id"]; ok {
hasPayload = true
agentRuleId := v.(string)
payloadAgentRule.AgentRuleId = &agentRuleId
}
if v, ok := tfAgentRule["expression"]; ok {
hasPayload = true
expression := v.(string)
payloadAgentRule.Expression = &expression
}
return payloadAgentRule, hasPayload
}

func buildPayloadFilters(tfFilters []interface{}) []datadogV2.SecurityMonitoringFilter {
payloadFilters := make([]datadogV2.SecurityMonitoringFilter, len(tfFilters))
for idx, tfFilter := range tfFilters {
Expand Down Expand Up @@ -547,9 +524,6 @@ func updateResourceDataFromResponse(d *schema.ResourceData, ruleResponse datadog
ruleQuery := make(map[string]interface{})
responseRuleQuery := ruleResponse.GetQueries()[idx]

if agentRule, ok := responseRuleQuery.GetAgentRuleOk(); ok {
ruleQuery["agent_rule"] = extractTfAgentRule(*agentRule)
}
if aggregation, ok := responseRuleQuery.GetAggregationOk(); ok {
ruleQuery["aggregation"] = *aggregation
}
Expand Down Expand Up @@ -622,13 +596,6 @@ func extractTfOptions(options datadogV2.SecurityMonitoringRuleOptions) map[strin
return tfOptions
}

func extractTfAgentRule(agentRule datadogV2.SecurityMonitoringRuntimeAgentRule) []map[string]interface{} {
tfAgentRule := make(map[string]interface{})
tfAgentRule["agent_rule_id"] = agentRule.GetAgentRuleId()
tfAgentRule["expression"] = agentRule.GetExpression()
return []map[string]interface{}{tfAgentRule}
}

func resourceDatadogSecurityMonitoringRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
providerConf := meta.(*ProviderConfiguration)
datadogClientV2 := providerConf.DatadogClientV2
Expand Down Expand Up @@ -703,13 +670,6 @@ func buildUpdatePayload(d *schema.ResourceData) datadogV2.SecurityMonitoringRule
query := tfQuery.(map[string]interface{})
payloadQuery := datadogV2.SecurityMonitoringRuleQuery{}

if v, ok := query["agent_rule"]; ok {
tfAgentRuleList := v.([]interface{})
if payloadAgentRule, ok := buildPayloadAgentRule(tfAgentRuleList); ok {
payloadQuery.AgentRule = payloadAgentRule
}
}

if v, ok := query["aggregation"]; ok {
aggregation := datadogV2.SecurityMonitoringRuleQueryAggregation(v.(string))
payloadQuery.Aggregation = &aggregation
Expand Down
@@ -1 +1 @@
2021-10-01T09:50:23.956424+01:00
2022-01-04T12:50:58.56411+01:00

0 comments on commit c1067b3

Please sign in to comment.