diff --git a/datadog/tests/cassettes/TestAccDatadogServiceAccountDatasourceMatchFilterExact.freeze b/datadog/tests/cassettes/TestAccDatadogServiceAccountDatasourceMatchFilterExact.freeze new file mode 100644 index 000000000..096e8473e --- /dev/null +++ b/datadog/tests/cassettes/TestAccDatadogServiceAccountDatasourceMatchFilterExact.freeze @@ -0,0 +1 @@ +2024-09-11T11:08:52.529867+02:00 \ No newline at end of file diff --git a/datadog/tests/cassettes/TestAccDatadogServiceAccountDatasourceMatchFilterExact.yaml b/datadog/tests/cassettes/TestAccDatadogServiceAccountDatasourceMatchFilterExact.yaml new file mode 100644 index 000000000..8f2b40230 --- /dev/null +++ b/datadog/tests/cassettes/TestAccDatadogServiceAccountDatasourceMatchFilterExact.yaml @@ -0,0 +1,351 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 262 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"data":{"attributes":{"email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","name":"tf-TestAccServiceAccountExact-d028705b33d5323f - Plus","service_account":true},"relationships":{"roles":{"data":[]}},"type":"users"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v2/service_accounts + method: POST + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"data":{"type":"users","id":"784383e3-701d-11ef-97cb-4e28bace5116","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f - Plus","handle":"784383e3-701d-11ef-97cb-4e28bace5116","created_at":"2024-09-11T09:08:54.582807+00:00","modified_at":"2024-09-11T09:08:54.582807+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":null,"verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active"},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}}} + headers: + Content-Type: + - application/json + status: 201 Created + code: 201 + duration: 539.432958ms + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 255 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"data":{"attributes":{"email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","name":"tf-TestAccServiceAccountExact-d028705b33d5323f","service_account":true},"relationships":{"roles":{"data":[]}},"type":"users"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v2/service_accounts + method: POST + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"data":{"type":"users","id":"78477bc5-701d-11ef-9182-eeea1b3eec34","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f","handle":"78477bc5-701d-11ef-9182-eeea1b3eec34","created_at":"2024-09-11T09:08:54.608812+00:00","modified_at":"2024-09-11T09:08:54.608812+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":null,"verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active"},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}}} + headers: + Content-Type: + - application/json + status: 201 Created + code: 201 + duration: 560.823667ms + - 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/users?filter=tf-TestAccServiceAccountExact-d028705b33d5323f + 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":"users","id":"78477bc5-701d-11ef-9182-eeea1b3eec34","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f","handle":"78477bc5-701d-11ef-9182-eeea1b3eec34","created_at":"2024-09-11T09:08:54.608812+00:00","modified_at":"2024-09-11T09:08:54.608812+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":"","verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active","mfa_enabled":false},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}},{"type":"users","id":"784383e3-701d-11ef-97cb-4e28bace5116","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f - Plus","handle":"784383e3-701d-11ef-97cb-4e28bace5116","created_at":"2024-09-11T09:08:54.582807+00:00","modified_at":"2024-09-11T09:08:54.582807+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":"","verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active","mfa_enabled":false},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}}],"meta":{"page":{"total_count":14,"total_filtered_count":2,"max_page_size":1000}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 174.963041ms + - 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/users?filter=tf-TestAccServiceAccountExact-d028705b33d5323f + 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":"users","id":"784383e3-701d-11ef-97cb-4e28bace5116","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f - Plus","handle":"784383e3-701d-11ef-97cb-4e28bace5116","created_at":"2024-09-11T09:08:54.582807+00:00","modified_at":"2024-09-11T09:08:54.582807+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":"","verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active","mfa_enabled":false},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}},{"type":"users","id":"78477bc5-701d-11ef-9182-eeea1b3eec34","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f","handle":"78477bc5-701d-11ef-9182-eeea1b3eec34","created_at":"2024-09-11T09:08:54.608812+00:00","modified_at":"2024-09-11T09:08:54.608812+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":"","verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active","mfa_enabled":false},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}}],"meta":{"page":{"total_count":14,"total_filtered_count":2,"max_page_size":1000}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 183.675833ms + - 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/users/784383e3-701d-11ef-97cb-4e28bace5116 + 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":"users","id":"784383e3-701d-11ef-97cb-4e28bace5116","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f - Plus","handle":"784383e3-701d-11ef-97cb-4e28bace5116","created_at":"2024-09-11T09:08:54.582807+00:00","modified_at":"2024-09-11T09:08:54.582807+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":null,"verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active","mfa_enabled":false},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 155.121334ms + - id: 5 + 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/users/78477bc5-701d-11ef-9182-eeea1b3eec34 + 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":"users","id":"78477bc5-701d-11ef-9182-eeea1b3eec34","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f","handle":"78477bc5-701d-11ef-9182-eeea1b3eec34","created_at":"2024-09-11T09:08:54.608812+00:00","modified_at":"2024-09-11T09:08:54.608812+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":null,"verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active","mfa_enabled":false},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 164.357375ms + - id: 6 + 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/users?filter=tf-TestAccServiceAccountExact-d028705b33d5323f + 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":"users","id":"784383e3-701d-11ef-97cb-4e28bace5116","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f - Plus","handle":"784383e3-701d-11ef-97cb-4e28bace5116","created_at":"2024-09-11T09:08:54.582807+00:00","modified_at":"2024-09-11T09:08:54.582807+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":"","verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active","mfa_enabled":false},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}},{"type":"users","id":"78477bc5-701d-11ef-9182-eeea1b3eec34","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f","handle":"78477bc5-701d-11ef-9182-eeea1b3eec34","created_at":"2024-09-11T09:08:54.608812+00:00","modified_at":"2024-09-11T09:08:54.608812+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":"","verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active","mfa_enabled":false},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}}],"meta":{"page":{"total_count":14,"total_filtered_count":2,"max_page_size":1000}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 162.603167ms + - id: 7 + 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/users?filter=tf-TestAccServiceAccountExact-d028705b33d5323f + 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":"users","id":"784383e3-701d-11ef-97cb-4e28bace5116","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f - Plus","handle":"784383e3-701d-11ef-97cb-4e28bace5116","created_at":"2024-09-11T09:08:54.582807+00:00","modified_at":"2024-09-11T09:08:54.582807+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":"","verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active","mfa_enabled":false},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}},{"type":"users","id":"78477bc5-701d-11ef-9182-eeea1b3eec34","attributes":{"name":"tf-TestAccServiceAccountExact-d028705b33d5323f","handle":"78477bc5-701d-11ef-9182-eeea1b3eec34","created_at":"2024-09-11T09:08:54.608812+00:00","modified_at":"2024-09-11T09:08:54.608812+00:00","email":"tf-testaccdatadogserviceaccountdatasourcematchfilterexact-local-1726045732@example.com","icon":"https://secure.gravatar.com/avatar/2a3ab7588230887efb015f2dbf2ecde2?s=48&d=retro","title":"","verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active","mfa_enabled":false},"relationships":{"roles":{"data":[]},"org":{"data":{"type":"orgs","id":"29c00926-0d2a-11ef-94c7-da7ad0900002"}}}}],"meta":{"page":{"total_count":14,"total_filtered_count":2,"max_page_size":1000}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 169.975958ms + - id: 8 + 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: + - '*/*' + url: https://api.datadoghq.com/api/v2/users/78477bc5-701d-11ef-9182-eeea1b3eec34 + method: DELETE + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 0 + uncompressed: false + body: "" + headers: {} + status: 204 No Content + code: 204 + duration: 273.817166ms + - id: 9 + 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: + - '*/*' + url: https://api.datadoghq.com/api/v2/users/784383e3-701d-11ef-97cb-4e28bace5116 + method: DELETE + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 0 + uncompressed: false + body: "" + headers: {} + status: 204 No Content + code: 204 + duration: 288.125792ms diff --git a/datadog/tests/data_source_datadog_service_account_test.go b/datadog/tests/data_source_datadog_service_account_test.go index eaccb67af..d4854c62e 100644 --- a/datadog/tests/data_source_datadog_service_account_test.go +++ b/datadog/tests/data_source_datadog_service_account_test.go @@ -47,6 +47,48 @@ func testAccDatasourceServiceAccountConfig(email string, name string) string { }`, email, name) } +func TestAccDatadogServiceAccountDatasourceMatchFilterExact(t *testing.T) { + t.Parallel() + ctx, _, accProviders := testAccFrameworkMuxProviders(context.Background(), t) + unique_hash := fmt.Sprintf("%x", sha256.Sum256([]byte(uniqueEntityName(ctx, t)))) + name := fmt.Sprintf("tf-TestAccServiceAccountExact-%s", unique_hash[:16]) + email := strings.ToLower(uniqueEntityName(ctx, t)) + "@example.com" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: accProviders, + Steps: []resource.TestStep{ + { + Config: testAccDatasourceServiceAccountConfigMatchExact(email, name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair("data.datadog_service_account.test", "id", "datadog_service_account.foo", "id"), + resource.TestCheckResourceAttrPair("data.datadog_service_account.test", "name", "datadog_service_account.foo", "name"), + ), + }, + }, + }) +} + +func testAccDatasourceServiceAccountConfigMatchExact(email string, name string) string { + return fmt.Sprintf(` + data "datadog_service_account" "test" { + filter = "%[2]s" + exact_match = true + depends_on = [ + datadog_service_account.foo, + datadog_service_account.foo_plus, + ] + } + resource "datadog_service_account" "foo" { + email = "%[1]s" + name = "%[2]s" + } + resource "datadog_service_account" "foo_plus" { + email = "%[1]s" + name = "%[2]s - Plus" + }`, email, name) +} + func TestAccDatadogServiceAccountDatasourceMatchID(t *testing.T) { t.Parallel() ctx, _, accProviders := testAccFrameworkMuxProviders(context.Background(), t)