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

Handle encryption field for S3 destinations for Logs Archives #2740

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion datadog/resource_datadog_logs_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func resourceDatadogLogsArchive() *schema.Resource {
Required: true,
ValidateDiagFunc: validators.ValidateAWSAccountID,
},
"role_name": {Description: "Your AWS role name", Type: schema.TypeString, Required: true},
"role_name": {Description: "Your AWS role name", Type: schema.TypeString, Required: true},
"encryption_type": {Description: "The type of encryption on your archive.", Type: schema.TypeString, Optional: true, Default: "NO_OVERRIDE"},
"encryption_key": {Description: "The AWS KMS encryption key.", Type: schema.TypeString, Optional: true},
},
},
},
Expand Down Expand Up @@ -253,8 +255,15 @@ func buildGCSMap(destination datadogV2.LogsArchiveDestinationGCS) map[string]int
func buildS3Map(destination datadogV2.LogsArchiveDestinationS3) map[string]interface{} {
result := make(map[string]interface{})
integration := destination.GetIntegration()
encryption := destination.GetEncryption()
result["account_id"] = integration.GetAccountId()
result["role_name"] = integration.GetRoleName()
if encryptionType, ok := encryption.GetTypeOk(); ok {
result["encryption_type"] = encryptionType
}
if encryptionKey, ok := encryption.GetKeyOk(); ok {
result["encryption_key"] = encryptionKey
}
result["bucket"] = destination.GetBucket()
result["path"] = destination.GetPath()
return result
Expand Down Expand Up @@ -421,11 +430,25 @@ func buildS3Destination(dest interface{}) (*datadogV2.LogsArchiveDestinationS3,
if !ok {
path = ""
}

destination := datadogV2.NewLogsArchiveDestinationS3(
bucket.(string),
*integration,
datadogV2.LOGSARCHIVEDESTINATIONS3TYPE_S3,
)

encryptionType, ok := d["encryption_type"]
if ok && encryptionType != "" {
encryption := datadogV2.NewLogsArchiveEncryptionS3(
datadogV2.LogsArchiveEncryptionS3Type(encryptionType.(string)),
)
encryptionKey, ok := d["encryption_key"]
if ok && encryptionKey != "" {
encryption.SetKey(encryptionKey.(string))
}
destination.SetEncryption(*encryption)
}

destination.Path = datadog.PtrString(path.(string))
return destination, nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021-03-12T17:11:37.185942-05:00
2025-01-23T18:41:36.656668-05:00
267 changes: 179 additions & 88 deletions datadog/tests/cassettes/TestAccDatadogLogsArchiveOrder_basic.yaml
Original file line number Diff line number Diff line change
@@ -1,90 +1,181 @@
---
version: 2
interactions:
- request:
body: |
{"data":{"attributes":{"archive_ids":[]},"type":"archive_order"}}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.datadoghq.com/api/v2/logs/config/archive-order
method: PUT
id: 0
response:
body: '{"errors":["Missing order for archive FDhaAaBtQ9yXG41RPzHFzQ"]}'
headers:
Content-Type:
- application/json
status: 422 Unprocessable Entity
code: 422
duration: "0ms"
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/logs/config/archive-order
method: GET
id: 1
response:
body: '{"data":{"type":"archive_order","attributes":{"archive_ids":["FDhaAaBtQ9yXG41RPzHFzQ"]}}}'
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: "0ms"
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/logs/config/archive-order
method: GET
id: 2
response:
body: '{"data":{"type":"archive_order","attributes":{"archive_ids":["FDhaAaBtQ9yXG41RPzHFzQ"]}}}'
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: "0ms"
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/logs/config/archive-order
method: GET
id: 3
response:
body: '{"data":{"type":"archive_order","attributes":{"archive_ids":["FDhaAaBtQ9yXG41RPzHFzQ"]}}}'
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: "0ms"
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/logs/config/archive-order
method: GET
id: 4
response:
body: '{"data":{"type":"archive_order","attributes":{"archive_ids":["FDhaAaBtQ9yXG41RPzHFzQ"]}}}'
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: "0ms"
- id: 0
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 66
transfer_encoding: []
trailer: {}
host: api.datadoghq.com
remote_addr: ""
request_uri: ""
body: |
{"data":{"attributes":{"archive_ids":[]},"type":"archive_order"}}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.datadoghq.com/api/v2/logs/config/archive-order
method: PUT
response:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
transfer_encoding:
- chunked
trailer: {}
content_length: -1
uncompressed: true
body: |
{"errors":["Missing order for archive BKmiim5bQXC9RDfsaq9bjQ"]}
headers:
Content-Type:
- application/json
status: 422 Unprocessable Entity
code: 422
duration: 147.416375ms
- id: 1
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 0
transfer_encoding: []
trailer: {}
host: api.datadoghq.com
remote_addr: ""
request_uri: ""
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/logs/config/archive-order
method: GET
response:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
transfer_encoding:
- chunked
trailer: {}
content_length: -1
uncompressed: true
body: |
{"data":{"type":"archive_order","attributes":{"archive_ids":["FDhaAaBtQ9yXG41RPzHFzQ","k97y1-gSTWKLXkJwfmNVbQ","s8blIHa5QmmFJZkyYK-MQg","CbNClyqUTbaVHga-YXGkIQ","BKmiim5bQXC9RDfsaq9bjQ","eEXtNWT_TamG48WUDiyGNQ"]}}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 70.391916ms
- id: 2
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 0
transfer_encoding: []
trailer: {}
host: api.datadoghq.com
remote_addr: ""
request_uri: ""
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/logs/config/archive-order
method: GET
response:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
transfer_encoding:
- chunked
trailer: {}
content_length: -1
uncompressed: true
body: |
{"data":{"type":"archive_order","attributes":{"archive_ids":["FDhaAaBtQ9yXG41RPzHFzQ","k97y1-gSTWKLXkJwfmNVbQ","s8blIHa5QmmFJZkyYK-MQg","CbNClyqUTbaVHga-YXGkIQ","BKmiim5bQXC9RDfsaq9bjQ","eEXtNWT_TamG48WUDiyGNQ"]}}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 77.23625ms
- id: 3
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 0
transfer_encoding: []
trailer: {}
host: api.datadoghq.com
remote_addr: ""
request_uri: ""
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/logs/config/archive-order
method: GET
response:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
transfer_encoding:
- chunked
trailer: {}
content_length: -1
uncompressed: true
body: |
{"data":{"type":"archive_order","attributes":{"archive_ids":["FDhaAaBtQ9yXG41RPzHFzQ","k97y1-gSTWKLXkJwfmNVbQ","s8blIHa5QmmFJZkyYK-MQg","CbNClyqUTbaVHga-YXGkIQ","BKmiim5bQXC9RDfsaq9bjQ","eEXtNWT_TamG48WUDiyGNQ"]}}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 66.465667ms
- id: 4
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 0
transfer_encoding: []
trailer: {}
host: api.datadoghq.com
remote_addr: ""
request_uri: ""
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/logs/config/archive-order
method: GET
response:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
transfer_encoding:
- chunked
trailer: {}
content_length: -1
uncompressed: true
body: |
{"data":{"type":"archive_order","attributes":{"archive_ids":["FDhaAaBtQ9yXG41RPzHFzQ","k97y1-gSTWKLXkJwfmNVbQ","s8blIHa5QmmFJZkyYK-MQg","CbNClyqUTbaVHga-YXGkIQ","BKmiim5bQXC9RDfsaq9bjQ","eEXtNWT_TamG48WUDiyGNQ"]}}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: 69.449ms
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021-03-12T17:11:39.333811-05:00
2025-01-23T18:43:49.757164-05:00
Loading
Loading