Skip to content

Commit 3de80fd

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
and
ci.datadog-api-spec
authored
Add convert rule JSON to terraform to Datadog API Spec. (#1665)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com>
1 parent c1c0a34 commit 3de80fd

File tree

17 files changed

+855
-4
lines changed

17 files changed

+855
-4
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2024-07-11 14:29:31.447802",
8-
"spec_repo_commit": "3eedf0af"
7+
"regenerated": "2024-07-11 16:35:13.616074",
8+
"spec_repo_commit": "d83fe206"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2024-07-11 14:29:31.466571",
13-
"spec_repo_commit": "3eedf0af"
12+
"regenerated": "2024-07-11 16:35:13.635786",
13+
"spec_repo_commit": "d83fe206"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17377,6 +17377,18 @@ components:
1737717377
required:
1737817378
- status
1737917379
type: object
17380+
SecurityMonitoringRuleConvertPayload:
17381+
description: Convert a rule from JSON to Terraform.
17382+
oneOf:
17383+
- $ref: '#/components/schemas/SecurityMonitoringStandardRulePayload'
17384+
- $ref: '#/components/schemas/SecurityMonitoringSignalRulePayload'
17385+
SecurityMonitoringRuleConvertResponse:
17386+
description: Result of the convert rule request containing Terraform content.
17387+
properties:
17388+
terraformContent:
17389+
description: Terraform string as a result of converting the rule from JSON.
17390+
type: string
17391+
type: object
1738017392
SecurityMonitoringRuleCreatePayload:
1738117393
description: Create a new rule.
1738217394
oneOf:
@@ -33246,6 +33258,47 @@ paths:
3324633258
tags:
3324733259
- Security Monitoring
3324833260
x-codegen-request-body-name: body
33261+
/api/v2/security_monitoring/rules/convert:
33262+
post:
33263+
description: 'Convert a rule that doesn''t (yet) exist from JSON to Terraform
33264+
for datadog provider
33265+
33266+
resource datadog_security_monitoring_rule.'
33267+
operationId: ConvertSecurityMonitoringRuleFromJSONToTerraform
33268+
requestBody:
33269+
content:
33270+
application/json:
33271+
schema:
33272+
$ref: '#/components/schemas/SecurityMonitoringRuleConvertPayload'
33273+
required: true
33274+
responses:
33275+
'200':
33276+
content:
33277+
application/json:
33278+
schema:
33279+
$ref: '#/components/schemas/SecurityMonitoringRuleConvertResponse'
33280+
description: OK
33281+
'400':
33282+
$ref: '#/components/responses/BadRequestResponse'
33283+
'401':
33284+
$ref: '#/components/responses/ConcurrentModificationResponse'
33285+
'403':
33286+
$ref: '#/components/responses/NotAuthorizedResponse'
33287+
'404':
33288+
$ref: '#/components/responses/NotFoundResponse'
33289+
'429':
33290+
$ref: '#/components/responses/TooManyRequestsResponse'
33291+
security:
33292+
- apiKeyAuth: []
33293+
appKeyAuth: []
33294+
- AuthZ:
33295+
- security_monitoring_rules_write
33296+
summary: Convert a rule from JSON to Terraform
33297+
tags:
33298+
- Security Monitoring
33299+
x-codegen-request-body-name: body
33300+
x-unstable: '**Note**: This feature is in private beta. Reach out to support
33301+
to request access.'
3324933302
/api/v2/security_monitoring/rules/test:
3325033303
post:
3325133304
description: Test a rule.
@@ -33403,6 +33456,39 @@ paths:
3340333456
tags:
3340433457
- Security Monitoring
3340533458
x-codegen-request-body-name: body
33459+
/api/v2/security_monitoring/rules/{rule_id}/convert:
33460+
get:
33461+
description: 'Convert an existing rule from JSON to Terraform for datadog provider
33462+
33463+
resource datadog_security_monitoring_rule.'
33464+
operationId: ConvertExistingSecurityMonitoringRule
33465+
parameters:
33466+
- $ref: '#/components/parameters/SecurityMonitoringRuleID'
33467+
responses:
33468+
'200':
33469+
content:
33470+
application/json:
33471+
schema:
33472+
$ref: '#/components/schemas/SecurityMonitoringRuleConvertResponse'
33473+
description: OK
33474+
'400':
33475+
$ref: '#/components/responses/BadRequestResponse'
33476+
'403':
33477+
$ref: '#/components/responses/NotAuthorizedResponse'
33478+
'404':
33479+
$ref: '#/components/responses/NotFoundResponse'
33480+
'429':
33481+
$ref: '#/components/responses/TooManyRequestsResponse'
33482+
security:
33483+
- apiKeyAuth: []
33484+
appKeyAuth: []
33485+
- AuthZ:
33486+
- security_monitoring_rules_read
33487+
summary: Convert an existing rule from JSON to Terraform
33488+
tags:
33489+
- Security Monitoring
33490+
x-unstable: '**Note**: This feature is in private beta. Reach out to support
33491+
to request access.'
3340633492
/api/v2/security_monitoring/rules/{rule_id}/test:
3340733493
post:
3340833494
description: Test an existing rule.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2024-06-24T19:47:12.909Z"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"log": {
3+
"_recordingName": "Security Monitoring/Convert a rule from JSON to Terraform returns \"OK\" response",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "20e4dd5b7315ecf5a5ead4ea85ff50dc",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 432,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json"
22+
},
23+
{
24+
"_fromType": "array",
25+
"name": "content-type",
26+
"value": "application/json"
27+
}
28+
],
29+
"headersSize": 616,
30+
"httpVersion": "HTTP/1.1",
31+
"method": "POST",
32+
"postData": {
33+
"mimeType": "application/json",
34+
"params": [],
35+
"text": "{\"cases\":[{\"condition\":\"a > 0\",\"name\":\"\",\"notifications\":[],\"status\":\"info\"}],\"filters\":[],\"isEnabled\":true,\"message\":\"Test rule\",\"name\":\"Test-Convert_a_rule_from_JSON_to_Terraform_returns_OK_response-1719258432\",\"options\":{\"evaluationWindow\":900,\"keepAlive\":3600,\"maxSignalDuration\":86400},\"queries\":[{\"aggregation\":\"count\",\"distinctFields\":[],\"groupByFields\":[],\"metric\":\"\",\"query\":\"@test:true\"}],\"tags\":[],\"type\":\"log_detection\"}"
36+
},
37+
"queryString": [],
38+
"url": "https://api.datadoghq.com/api/v2/security_monitoring/rules/convert"
39+
},
40+
"response": {
41+
"bodySize": 747,
42+
"content": {
43+
"mimeType": "application/json",
44+
"size": 747,
45+
"text": "{\"terraformContent\":\"resource \\\"datadog_security_monitoring_rule\\\" \\\"test-convert_a_rule_from_json_to_terraform_returns_ok_response-1719258432\\\" {\\n\\tname = \\\"Test-Convert_a_rule_from_JSON_to_Terraform_returns_OK_response-1719258432\\\"\\n\\tenabled = true\\n\\tquery {\\n\\t\\tquery = \\\"@test:true\\\"\\n\\t\\tgroup_by_fields = []\\n\\t\\tdistinct_fields = []\\n\\t\\taggregation = \\\"count\\\"\\n\\t\\tname = \\\"\\\"\\n\\t}\\n\\toptions {\\n\\t\\tkeep_alive = 3600\\n\\t\\tmax_signal_duration = 86400\\n\\t\\tdetection_method = \\\"threshold\\\"\\n\\t\\tevaluation_window = 900\\n\\t}\\n\\tcase {\\n\\t\\tname = \\\"\\\"\\n\\t\\tstatus = \\\"info\\\"\\n\\t\\tnotifications = []\\n\\t\\tcondition = \\\"a > 0\\\"\\n\\t}\\n\\tmessage = \\\"Test rule\\\"\\n\\ttags = []\\n\\thas_extended_title = false\\n\\ttype = \\\"log_detection\\\"\\n}\\n\"}\n"
46+
},
47+
"cookies": [],
48+
"headers": [
49+
{
50+
"name": "content-type",
51+
"value": "application/json"
52+
}
53+
],
54+
"headersSize": 654,
55+
"httpVersion": "HTTP/1.1",
56+
"redirectURL": "",
57+
"status": 200,
58+
"statusText": "OK"
59+
},
60+
"startedDateTime": "2024-06-24T19:47:12.919Z",
61+
"time": 160
62+
}
63+
],
64+
"pages": [],
65+
"version": "1.2"
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2024-06-24T19:55:06.421Z"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"log": {
3+
"_recordingName": "Security Monitoring/Convert an existing rule from JSON to Terraform returns \"OK\" response",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "c96ac2df410444c5d9519c5799ae5647",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 443,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json"
22+
},
23+
{
24+
"_fromType": "array",
25+
"name": "content-type",
26+
"value": "application/json"
27+
}
28+
],
29+
"headersSize": 588,
30+
"httpVersion": "HTTP/1.1",
31+
"method": "POST",
32+
"postData": {
33+
"mimeType": "application/json",
34+
"params": [],
35+
"text": "{\"cases\":[{\"condition\":\"a > 0\",\"name\":\"\",\"notifications\":[],\"status\":\"info\"}],\"filters\":[],\"isEnabled\":true,\"message\":\"Test rule\",\"name\":\"Test-Convert_an_existing_rule_from_JSON_to_Terraform_returns_OK_response-1719258906\",\"options\":{\"evaluationWindow\":900,\"keepAlive\":3600,\"maxSignalDuration\":86400},\"queries\":[{\"aggregation\":\"count\",\"distinctFields\":[],\"groupByFields\":[],\"metrics\":[],\"query\":\"@test:true\"}],\"tags\":[],\"type\":\"log_detection\"}"
36+
},
37+
"queryString": [],
38+
"url": "https://api.datadoghq.com/api/v2/security_monitoring/rules"
39+
},
40+
"response": {
41+
"bodySize": 688,
42+
"content": {
43+
"mimeType": "application/json",
44+
"size": 688,
45+
"text": "{\"id\":\"eu8-b0k-wzc\",\"version\":1,\"name\":\"Test-Convert_an_existing_rule_from_JSON_to_Terraform_returns_OK_response-1719258906\",\"createdAt\":1719258906588,\"creationAuthorId\":1445416,\"isDefault\":false,\"isPartner\":false,\"isEnabled\":true,\"isDeleted\":false,\"isDeprecated\":false,\"queries\":[{\"query\":\"@test:true\",\"groupByFields\":[],\"hasOptionalGroupByFields\":false,\"distinctFields\":[],\"aggregation\":\"count\",\"name\":\"\"}],\"options\":{\"keepAlive\":3600,\"maxSignalDuration\":86400,\"detectionMethod\":\"threshold\",\"evaluationWindow\":900},\"cases\":[{\"name\":\"\",\"status\":\"info\",\"notifications\":[],\"condition\":\"a > 0\"}],\"message\":\"Test rule\",\"tags\":[],\"hasExtendedTitle\":false,\"type\":\"log_detection\",\"filters\":[]}\n"
46+
},
47+
"cookies": [],
48+
"headers": [
49+
{
50+
"name": "content-type",
51+
"value": "application/json"
52+
}
53+
],
54+
"headersSize": 654,
55+
"httpVersion": "HTTP/1.1",
56+
"redirectURL": "",
57+
"status": 200,
58+
"statusText": "OK"
59+
},
60+
"startedDateTime": "2024-06-24T19:55:06.431Z",
61+
"time": 184
62+
},
63+
{
64+
"_id": "a275424eb01a9e224f0921502c0ab3e2",
65+
"_order": 0,
66+
"cache": {},
67+
"request": {
68+
"bodySize": 0,
69+
"cookies": [],
70+
"headers": [
71+
{
72+
"_fromType": "array",
73+
"name": "accept",
74+
"value": "application/json"
75+
}
76+
],
77+
"headersSize": 563,
78+
"httpVersion": "HTTP/1.1",
79+
"method": "GET",
80+
"queryString": [],
81+
"url": "https://api.datadoghq.com/api/v2/security_monitoring/rules/eu8-b0k-wzc/convert"
82+
},
83+
"response": {
84+
"bodySize": 767,
85+
"content": {
86+
"mimeType": "application/json",
87+
"size": 767,
88+
"text": "{\"terraformContent\":\"resource \\\"datadog_security_monitoring_rule\\\" \\\"test-convert_an_existing_rule_from_json_to_terraform_returns_ok_response-1719258906\\\" {\\n\\tname = \\\"Test-Convert_an_existing_rule_from_JSON_to_Terraform_returns_OK_response-1719258906\\\"\\n\\tenabled = true\\n\\tquery {\\n\\t\\tquery = \\\"@test:true\\\"\\n\\t\\tgroup_by_fields = []\\n\\t\\tdistinct_fields = []\\n\\t\\taggregation = \\\"count\\\"\\n\\t\\tname = \\\"\\\"\\n\\t}\\n\\toptions {\\n\\t\\tkeep_alive = 3600\\n\\t\\tmax_signal_duration = 86400\\n\\t\\tdetection_method = \\\"threshold\\\"\\n\\t\\tevaluation_window = 900\\n\\t}\\n\\tcase {\\n\\t\\tname = \\\"\\\"\\n\\t\\tstatus = \\\"info\\\"\\n\\t\\tnotifications = []\\n\\t\\tcondition = \\\"a > 0\\\"\\n\\t}\\n\\tmessage = \\\"Test rule\\\"\\n\\ttags = []\\n\\thas_extended_title = false\\n\\ttype = \\\"log_detection\\\"\\n}\\n\"}\n"
89+
},
90+
"cookies": [],
91+
"headers": [
92+
{
93+
"name": "content-type",
94+
"value": "application/json"
95+
}
96+
],
97+
"headersSize": 654,
98+
"httpVersion": "HTTP/1.1",
99+
"redirectURL": "",
100+
"status": 200,
101+
"statusText": "OK"
102+
},
103+
"startedDateTime": "2024-06-24T19:55:06.621Z",
104+
"time": 130
105+
},
106+
{
107+
"_id": "8a82e9fa9f0c3c4b402308121880806a",
108+
"_order": 0,
109+
"cache": {},
110+
"request": {
111+
"bodySize": 0,
112+
"cookies": [],
113+
"headers": [
114+
{
115+
"_fromType": "array",
116+
"name": "accept",
117+
"value": "*/*"
118+
}
119+
],
120+
"headersSize": 536,
121+
"httpVersion": "HTTP/1.1",
122+
"method": "DELETE",
123+
"queryString": [],
124+
"url": "https://api.datadoghq.com/api/v2/security_monitoring/rules/eu8-b0k-wzc"
125+
},
126+
"response": {
127+
"bodySize": 0,
128+
"content": {
129+
"mimeType": "text/plain",
130+
"size": 0
131+
},
132+
"cookies": [],
133+
"headers": [],
134+
"headersSize": 601,
135+
"httpVersion": "HTTP/1.1",
136+
"redirectURL": "",
137+
"status": 204,
138+
"statusText": "No Content"
139+
},
140+
"startedDateTime": "2024-06-24T19:55:06.757Z",
141+
"time": 157
142+
}
143+
],
144+
"pages": [],
145+
"version": "1.2"
146+
}
147+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Convert an existing rule from JSON to Terraform returns "OK" response
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
configuration.unstableOperations["v2.convertExistingSecurityMonitoringRule"] =
9+
true;
10+
const apiInstance = new v2.SecurityMonitoringApi(configuration);
11+
12+
// there is a valid "security_rule" in the system
13+
const SECURITY_RULE_ID = process.env.SECURITY_RULE_ID as string;
14+
15+
const params: v2.SecurityMonitoringApiConvertExistingSecurityMonitoringRuleRequest =
16+
{
17+
ruleId: SECURITY_RULE_ID,
18+
};
19+
20+
apiInstance
21+
.convertExistingSecurityMonitoringRule(params)
22+
.then((data: v2.SecurityMonitoringRuleConvertResponse) => {
23+
console.log(
24+
"API called successfully. Returned data: " + JSON.stringify(data)
25+
);
26+
})
27+
.catch((error: any) => console.error(error));

0 commit comments

Comments
 (0)