Skip to content

Commit e2e496e

Browse files
committed
make icon url optional and remove description
1 parent f881471 commit e2e496e

17 files changed

+300
-658
lines changed

datadog/fwprovider/resource_datadog_compliance_custom_framework.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type complianceCustomFrameworkResource struct {
2626

2727
type complianceCustomFrameworkModel struct {
2828
ID types.String `tfsdk:"id"`
29-
Description types.String `tfsdk:"description"`
3029
Version types.String `tfsdk:"version"`
3130
Handle types.String `tfsdk:"handle"`
3231
Name types.String `tfsdk:"name"`
@@ -72,11 +71,7 @@ func (r *complianceCustomFrameworkResource) Schema(_ context.Context, _ resource
7271
Required: true,
7372
},
7473
"icon_url": schema.StringAttribute{
75-
Description: "The URL of the icon representing the framework.",
76-
Optional: true,
77-
},
78-
"description": schema.StringAttribute{
79-
Description: "The description of the framework.",
74+
Description: "The URL of the icon representing the framework. This can be set to empty if NA",
8075
Optional: true,
8176
},
8277
},
@@ -179,11 +174,9 @@ func (r *complianceCustomFrameworkResource) Read(ctx context.Context, request re
179174
// If the framework does not exist, remove it from terraform state
180175
// This is to avoid the provider to return an error when the framework is deleted in the UI prior
181176
if err != nil && err.Error() == "400 Bad Request" {
182-
// Clear the state completely
183177
response.State.RemoveResource(ctx)
184178
return
185179
}
186-
// this is for any other error
187180
if err != nil {
188181
response.Diagnostics.Append(utils.FrameworkErrorDiag(err, "error reading compliance custom framework"))
189182
return
@@ -255,19 +248,17 @@ func setRequirements(requirements []attr.Value) types.Set {
255248
)
256249
}
257250
func readStateFromDatabase(data datadogV2.GetCustomFrameworkResponse, handle string, version string) complianceCustomFrameworkModel {
258-
// Set the state
259251
var state complianceCustomFrameworkModel
260252
state.ID = types.StringValue(handle + "-" + version)
261253
state.Handle = types.StringValue(handle)
262254
state.Version = types.StringValue(version)
263255
state.Name = types.StringValue(data.GetData().Attributes.Name)
264-
state.Description = types.StringValue(data.GetData().Attributes.Description)
265-
state.IconURL = types.StringValue(data.GetData().Attributes.IconUrl)
256+
if data.GetData().Attributes.IconUrl != nil {
257+
state.IconURL = types.StringValue(*data.GetData().Attributes.IconUrl)
258+
}
266259

267-
// Convert requirements to set
268260
requirements := make([]attr.Value, len(data.GetData().Attributes.Requirements))
269261
for i, requirement := range data.GetData().Attributes.Requirements {
270-
// Convert controls to set
271262
controls := make([]attr.Value, len(requirement.Controls))
272263
for j, control := range requirement.Controls {
273264
rulesID := make([]attr.Value, len(control.RulesId))
@@ -323,16 +314,18 @@ func convertStateRequirementsToFrameworkRequirements(requirements types.Set) []d
323314
}
324315

325316
func buildCreateFrameworkRequest(state complianceCustomFrameworkModel) *datadogV2.CreateCustomFrameworkRequest {
317+
var iconURL *string
318+
if !state.IconURL.IsNull() && !state.IconURL.IsUnknown() {
319+
iconURLStr := state.IconURL.ValueString()
320+
iconURL = &iconURLStr
321+
}
326322
createFrameworkRequest := datadogV2.NewCreateCustomFrameworkRequestWithDefaults()
327-
description := state.Description.ValueString()
328-
iconURL := state.IconURL.ValueString()
329323
createFrameworkRequest.SetData(datadogV2.CustomFrameworkData{
330324
Type: "custom_framework",
331325
Attributes: datadogV2.CustomFrameworkDataAttributes{
332326
Handle: state.Handle.ValueString(),
333327
Name: state.Name.ValueString(),
334-
Description: &description,
335-
IconUrl: &iconURL,
328+
IconUrl: iconURL,
336329
Version: state.Version.ValueString(),
337330
Requirements: convertStateRequirementsToFrameworkRequirements(state.Requirements),
338331
},
@@ -341,17 +334,19 @@ func buildCreateFrameworkRequest(state complianceCustomFrameworkModel) *datadogV
341334
}
342335

343336
func buildUpdateFrameworkRequest(state complianceCustomFrameworkModel) *datadogV2.UpdateCustomFrameworkRequest {
337+
var iconURL *string
338+
if !state.IconURL.IsNull() && !state.IconURL.IsUnknown() {
339+
iconURLStr := state.IconURL.ValueString()
340+
iconURL = &iconURLStr
341+
}
344342
updateFrameworkRequest := datadogV2.NewUpdateCustomFrameworkRequestWithDefaults()
345-
description := state.Description.ValueString()
346-
iconURL := state.IconURL.ValueString()
347343
updateFrameworkRequest.SetData(datadogV2.CustomFrameworkData{
348344
Type: "custom_framework",
349345
Attributes: datadogV2.CustomFrameworkDataAttributes{
350346
Handle: state.Handle.ValueString(),
351347
Name: state.Name.ValueString(),
352-
Description: &description,
353-
IconUrl: &iconURL,
354348
Version: state.Version.ValueString(),
349+
IconUrl: iconURL,
355350
Requirements: convertStateRequirementsToFrameworkRequirements(state.Requirements),
356351
},
357352
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2025-05-01T17:16:53.65853-04:00
1+
2025-05-14T13:18:54.151434-04:00

datadog/tests/cassettes/TestCustomFramework_CreateConflict.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ interactions:
3333
- application/vnd.api+json
3434
status: 400 Bad Request
3535
code: 400
36-
duration: 103.46125ms
36+
duration: 54.499584ms
3737
- id: 1
3838
request:
3939
proto: HTTP/1.1
4040
proto_major: 1
4141
proto_minor: 1
42-
content_length: 285
42+
content_length: 252
4343
transfer_encoding: []
4444
trailer: {}
4545
host: api.datadoghq.com
4646
remote_addr: ""
4747
request_uri: ""
4848
body: |
49-
{"data":{"attributes":{"description":"test description","handle":"terraform-handle","icon_url":"test url","name":"new-framework-terraform","requirements":[{"controls":[{"name":"control1","rules_id":["def-000-be9"]}],"name":"requirement1"}],"version":"1.0"},"type":"custom_framework"}}
49+
{"data":{"attributes":{"handle":"terraform-handle","icon_url":"test url","name":"new-framework-terraform","requirements":[{"controls":[{"name":"control1","rules_id":["def-000-be9"]}],"name":"requirement1"}],"version":"1.0"},"type":"custom_framework"}}
5050
form: {}
5151
headers:
5252
Accept:
@@ -69,20 +69,20 @@ interactions:
6969
- application/vnd.api+json
7070
status: 200 OK
7171
code: 200
72-
duration: 496.842834ms
72+
duration: 418.422333ms
7373
- id: 2
7474
request:
7575
proto: HTTP/1.1
7676
proto_major: 1
7777
proto_minor: 1
78-
content_length: 285
78+
content_length: 252
7979
transfer_encoding: []
8080
trailer: {}
8181
host: api.datadoghq.com
8282
remote_addr: ""
8383
request_uri: ""
8484
body: |
85-
{"data":{"attributes":{"description":"test description","handle":"terraform-handle","icon_url":"test url","name":"new-framework-terraform","requirements":[{"controls":[{"name":"control1","rules_id":["def-000-be9"]}],"name":"requirement1"}],"version":"1.0"},"type":"custom_framework"}}
85+
{"data":{"attributes":{"handle":"terraform-handle","icon_url":"test-url","name":"new-framework-terraform","requirements":[{"controls":[{"name":"control1","rules_id":["def-000-be9"]}],"name":"requirement1"}],"version":"1.0"},"type":"custom_framework"}}
8686
form: {}
8787
headers:
8888
Accept:
@@ -105,4 +105,4 @@ interactions:
105105
- application/vnd.api+json
106106
status: 409 Conflict
107107
code: 409
108-
duration: 190.623167ms
108+
duration: 174.318959ms
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-05-14T13:21:36.261823-04:00
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
version: 2
3+
interactions:
4+
- id: 0
5+
request:
6+
proto: HTTP/1.1
7+
proto_major: 1
8+
proto_minor: 1
9+
content_length: 230
10+
transfer_encoding: []
11+
trailer: {}
12+
host: api.datadoghq.com
13+
remote_addr: ""
14+
request_uri: ""
15+
body: |
16+
{"data":{"attributes":{"handle":"terraform-handle","name":"new-framework-terraform","requirements":[{"controls":[{"name":"control1","rules_id":["def-000-be9"]}],"name":"requirement1"}],"version":"1.0"},"type":"custom_framework"}}
17+
form: {}
18+
headers:
19+
Accept:
20+
- application/json
21+
Content-Type:
22+
- application/json
23+
url: https://api.datadoghq.com/api/v2/cloud_security_management/custom_frameworks
24+
method: POST
25+
response:
26+
proto: HTTP/1.1
27+
proto_major: 1
28+
proto_minor: 1
29+
transfer_encoding: []
30+
trailer: {}
31+
content_length: 123
32+
uncompressed: false
33+
body: '{"data":{"id":"terraform-handle-1.0","type":"custom_framework","attributes":{"handle":"terraform-handle","version":"1.0"}}}'
34+
headers:
35+
Content-Type:
36+
- application/vnd.api+json
37+
status: 200 OK
38+
code: 200
39+
duration: 422.992708ms
40+
- id: 1
41+
request:
42+
proto: HTTP/1.1
43+
proto_major: 1
44+
proto_minor: 1
45+
content_length: 0
46+
transfer_encoding: []
47+
trailer: {}
48+
host: api.datadoghq.com
49+
remote_addr: ""
50+
request_uri: ""
51+
body: ""
52+
form: {}
53+
headers:
54+
Accept:
55+
- application/json
56+
url: https://api.datadoghq.com/api/v2/cloud_security_management/custom_frameworks/terraform-handle/1.0
57+
method: GET
58+
response:
59+
proto: HTTP/1.1
60+
proto_major: 1
61+
proto_minor: 1
62+
transfer_encoding: []
63+
trailer: {}
64+
content_length: 257
65+
uncompressed: false
66+
body: '{"data":{"id":"terraform-handle-1.0","type":"custom_framework","attributes":{"handle":"terraform-handle","name":"new-framework-terraform","requirements":[{"name":"requirement1","controls":[{"name":"control1","rules_id":["def-000-be9"]}]}],"version":"1.0"}}}'
67+
headers:
68+
Content-Type:
69+
- application/vnd.api+json
70+
status: 200 OK
71+
code: 200
72+
duration: 117.490292ms
73+
- id: 2
74+
request:
75+
proto: HTTP/1.1
76+
proto_major: 1
77+
proto_minor: 1
78+
content_length: 0
79+
transfer_encoding: []
80+
trailer: {}
81+
host: api.datadoghq.com
82+
remote_addr: ""
83+
request_uri: ""
84+
body: ""
85+
form: {}
86+
headers:
87+
Accept:
88+
- application/json
89+
url: https://api.datadoghq.com/api/v2/cloud_security_management/custom_frameworks/terraform-handle/1.0
90+
method: DELETE
91+
response:
92+
proto: HTTP/1.1
93+
proto_major: 1
94+
proto_minor: 1
95+
transfer_encoding: []
96+
trailer: {}
97+
content_length: 187
98+
uncompressed: false
99+
body: '{"data":{"id":"terraform-handle-1.0","type":"custom_framework","attributes":{"description":"","handle":"terraform-handle","icon_url":"","name":"new-framework-terraform","version":"1.0"}}}'
100+
headers:
101+
Content-Type:
102+
- application/vnd.api+json
103+
status: 200 OK
104+
code: 200
105+
duration: 292.465917ms
106+
- id: 3
107+
request:
108+
proto: HTTP/1.1
109+
proto_major: 1
110+
proto_minor: 1
111+
content_length: 0
112+
transfer_encoding: []
113+
trailer: {}
114+
host: api.datadoghq.com
115+
remote_addr: ""
116+
request_uri: ""
117+
body: ""
118+
form: {}
119+
headers:
120+
Accept:
121+
- application/json
122+
url: https://api.datadoghq.com/api/v2/cloud_security_management/custom_frameworks/terraform-handle/1.0
123+
method: GET
124+
response:
125+
proto: HTTP/1.1
126+
proto_major: 1
127+
proto_minor: 1
128+
transfer_encoding: []
129+
trailer: {}
130+
content_length: 51
131+
uncompressed: false
132+
body: '{"errors":[{"status":"400","title":"Bad Request"}]}'
133+
headers:
134+
Content-Type:
135+
- application/vnd.api+json
136+
status: 400 Bad Request
137+
code: 400
138+
duration: 57.986458ms
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2025-05-01T16:09:17.103315-04:00
1+
2025-05-14T13:14:53.105131-04:00

0 commit comments

Comments
 (0)