From 8f2a1bac7414303c399109b1c60152fcba7d74fe Mon Sep 17 00:00:00 2001 From: Sam Cohen Date: Thu, 9 Feb 2023 15:14:02 -0500 Subject: [PATCH 01/10] add pagerduty integration so data source --- ...source_datadog_pagerduty_service_object.go | 67 ++++++++ datadog/provider.go | 53 +++--- ...dogPagerdutyIntegrationSODatasource.freeze | 1 + ...tadogPagerdutyIntegrationSODatasource.yaml | 154 ++++++++++++++++++ ...e_datadog_pagerduty_service_object_test.go | 56 +++++++ datadog/tests/provider_test.go | 1 + 6 files changed, 306 insertions(+), 26 deletions(-) create mode 100644 datadog/data_source_datadog_pagerduty_service_object.go create mode 100644 datadog/tests/cassettes/TestAccDatadogPagerdutyIntegrationSODatasource.freeze create mode 100644 datadog/tests/cassettes/TestAccDatadogPagerdutyIntegrationSODatasource.yaml create mode 100644 datadog/tests/data_source_datadog_pagerduty_service_object_test.go diff --git a/datadog/data_source_datadog_pagerduty_service_object.go b/datadog/data_source_datadog_pagerduty_service_object.go new file mode 100644 index 0000000000..58d63ee5fa --- /dev/null +++ b/datadog/data_source_datadog_pagerduty_service_object.go @@ -0,0 +1,67 @@ +package datadog + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + + "github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceDatadogIntegrationPagerdutySO() *schema.Resource { + return &schema.Resource{ + Description: "Use this data source to retrieve individual Service Objects of Datadog - PagerDuty integrations. Note that the Datadog - PagerDuty integration must be activated in the Datadog UI in order for this resource to be usable.", + ReadContext: dataSourceDatadogIntegrationPagerdutySORead, + + Schema: map[string]*schema.Schema{ + "service_name": { + Description: "Your Service name in PagerDuty.", + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + } +} + +func dataSourceDatadogIntegrationPagerdutySORead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + providerConf := meta.(*ProviderConfiguration) + apiInstances := providerConf.DatadogApiInstances + auth := providerConf.Auth + + err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + searchedName := d.Get("service_name") + + resp, httpresp, err := apiInstances.GetPagerDutyIntegrationApiV1().GetPagerDutyIntegrationService(auth, searchedName.(string)) + + if err != nil { + if httpresp != nil && (httpresp.StatusCode == 504 || httpresp.StatusCode == 502) { + return resource.RetryableError(utils.TranslateClientError(err, httpresp, "error querying pagerduty integrations, retrying")) + } + if httpresp != nil && httpresp.StatusCode == 404 { + d.SetId("") + return resource.NonRetryableError(utils.TranslateClientError(err, httpresp, "pagerduty integration not found")) + } + return resource.NonRetryableError(utils.TranslateClientError(err, httpresp, "error querying pagerduty integrations")) + } + + if serviceName, ok := resp.GetServiceNameOk(); !ok { + d.SetId("") + return resource.NonRetryableError(fmt.Errorf("couldn't find a pagerduty integration named %s", *serviceName)) + } else { + d.SetId(*serviceName) + } + + return nil + }) + if err != nil { + return diag.FromErr(err) + } + + return nil +} diff --git a/datadog/provider.go b/datadog/provider.go index f64c6c45a5..59abeae523 100644 --- a/datadog/provider.go +++ b/datadog/provider.go @@ -180,32 +180,33 @@ func Provider() *schema.Provider { }, DataSourcesMap: map[string]*schema.Resource{ - "datadog_api_key": dataSourceDatadogApiKey(), - "datadog_application_key": dataSourceDatadogApplicationKey(), - "datadog_cloud_workload_security_agent_rules": dataSourceDatadogCloudWorkloadSecurityAgentRules(), - "datadog_dashboard": dataSourceDatadogDashboard(), - "datadog_dashboard_list": dataSourceDatadogDashboardList(), - "datadog_integration_aws_logs_services": dataSourceDatadogIntegrationAWSLogsServices(), - "datadog_ip_ranges": dataSourceDatadogIPRanges(), - "datadog_logs_archives_order": dataSourceDatadogLogsArchivesOrder(), - "datadog_logs_indexes": dataSourceDatadogLogsIndexes(), - "datadog_logs_indexes_order": dataSourceDatadogLogsIndexesOrder(), - "datadog_logs_pipelines": dataSourceDatadogLogsPipelines(), - "datadog_monitor": dataSourceDatadogMonitor(), - "datadog_monitors": dataSourceDatadogMonitors(), - "datadog_monitor_config_policies": dataSourceDatadogMonitorConfigPolicies(), - "datadog_permissions": dataSourceDatadogPermissions(), - "datadog_role": dataSourceDatadogRole(), - "datadog_roles": dataSourceDatadogRoles(), - "datadog_rum_application": dataSourceDatadogRUMApplication(), - "datadog_security_monitoring_rules": dataSourceDatadogSecurityMonitoringRules(), - "datadog_security_monitoring_filters": dataSourceDatadogSecurityMonitoringFilters(), - "datadog_service_level_objective": dataSourceDatadogServiceLevelObjective(), - "datadog_service_level_objectives": dataSourceDatadogServiceLevelObjectives(), - "datadog_synthetics_locations": dataSourceDatadogSyntheticsLocations(), - "datadog_synthetics_global_variable": dataSourceDatadogSyntheticsGlobalVariable(), - "datadog_synthetics_test": dataSourceDatadogSyntheticsTest(), - "datadog_user": dataSourceDatadogUser(), + "datadog_api_key": dataSourceDatadogApiKey(), + "datadog_application_key": dataSourceDatadogApplicationKey(), + "datadog_cloud_workload_security_agent_rules": dataSourceDatadogCloudWorkloadSecurityAgentRules(), + "datadog_dashboard": dataSourceDatadogDashboard(), + "datadog_dashboard_list": dataSourceDatadogDashboardList(), + "datadog_integration_aws_logs_services": dataSourceDatadogIntegrationAWSLogsServices(), + "datadog_ip_ranges": dataSourceDatadogIPRanges(), + "datadog_logs_archives_order": dataSourceDatadogLogsArchivesOrder(), + "datadog_logs_indexes": dataSourceDatadogLogsIndexes(), + "datadog_logs_indexes_order": dataSourceDatadogLogsIndexesOrder(), + "datadog_logs_pipelines": dataSourceDatadogLogsPipelines(), + "datadog_monitor": dataSourceDatadogMonitor(), + "datadog_monitors": dataSourceDatadogMonitors(), + "datadog_monitor_config_policies": dataSourceDatadogMonitorConfigPolicies(), + "datadog_permissions": dataSourceDatadogPermissions(), + "datadog_role": dataSourceDatadogRole(), + "datadog_roles": dataSourceDatadogRoles(), + "datadog_rum_application": dataSourceDatadogRUMApplication(), + "datadog_security_monitoring_rules": dataSourceDatadogSecurityMonitoringRules(), + "datadog_security_monitoring_filters": dataSourceDatadogSecurityMonitoringFilters(), + "datadog_service_level_objective": dataSourceDatadogServiceLevelObjective(), + "datadog_service_level_objectives": dataSourceDatadogServiceLevelObjectives(), + "datadog_synthetics_locations": dataSourceDatadogSyntheticsLocations(), + "datadog_synthetics_global_variable": dataSourceDatadogSyntheticsGlobalVariable(), + "datadog_synthetics_test": dataSourceDatadogSyntheticsTest(), + "datadog_user": dataSourceDatadogUser(), + "datadog_integration_pagerduty_service_object": dataSourceDatadogIntegrationPagerdutySO(), }, ConfigureContextFunc: providerConfigure, diff --git a/datadog/tests/cassettes/TestAccDatadogPagerdutyIntegrationSODatasource.freeze b/datadog/tests/cassettes/TestAccDatadogPagerdutyIntegrationSODatasource.freeze new file mode 100644 index 0000000000..9058da7503 --- /dev/null +++ b/datadog/tests/cassettes/TestAccDatadogPagerdutyIntegrationSODatasource.freeze @@ -0,0 +1 @@ +2023-02-09T15:11:35.55929-05:00 \ No newline at end of file diff --git a/datadog/tests/cassettes/TestAccDatadogPagerdutyIntegrationSODatasource.yaml b/datadog/tests/cassettes/TestAccDatadogPagerdutyIntegrationSODatasource.yaml new file mode 100644 index 0000000000..dac0b8f98e --- /dev/null +++ b/datadog/tests/cassettes/TestAccDatadogPagerdutyIntegrationSODatasource.yaml @@ -0,0 +1,154 @@ +--- +version: 1 +interactions: +- request: + body: | + {"service_key":"tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495","service_name":"tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495"} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v1/integration/pagerduty/configuration/services + method: POST + response: + body: | + {"service_name":"tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495"} + headers: + Content-Type: + - application/json + status: 201 Created + code: 201 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v1/integration/pagerduty/configuration/services/tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495 + method: GET + response: + body: | + {"service_name":"tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495"} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v1/integration/pagerduty/configuration/services/tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495 + method: GET + response: + body: | + {"service_name":"tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495"} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: {} + url: https://api.datadoghq.com/api/v1/integration/pagerduty + method: GET + response: + body: | + {"show_all_incidents":false,"filter_services":[],"schedules":["https://ddog.pagerduty.com/schedules/X123VF"],"api_token":"*****","services":[{"service_name":"tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495","service_key":"*****"}],"subdomain":"testdomain"} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v1/integration/pagerduty/configuration/services/tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495 + method: GET + response: + body: | + {"service_name":"tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495"} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v1/integration/pagerduty/configuration/services/tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495 + method: GET + response: + body: | + {"service_name":"tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495"} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v1/integration/pagerduty/configuration/services/tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495 + method: GET + response: + body: | + {"service_name":"tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495"} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v1/integration/pagerduty/configuration/services/tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495 + method: GET + response: + body: | + {"service_name":"tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495"} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - '*/*' + url: https://api.datadoghq.com/api/v1/integration/pagerduty/configuration/services/tf-TestAccDatadogPagerdutyIntegrationSODatasource-local-1675973495 + method: DELETE + response: + body: "" + headers: {} + status: 204 No Content + code: 204 + duration: "" diff --git a/datadog/tests/data_source_datadog_pagerduty_service_object_test.go b/datadog/tests/data_source_datadog_pagerduty_service_object_test.go new file mode 100644 index 0000000000..adb89689d8 --- /dev/null +++ b/datadog/tests/data_source_datadog_pagerduty_service_object_test.go @@ -0,0 +1,56 @@ +package test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func TestAccDatadogPagerdutyIntegrationSODatasource(t *testing.T) { + t.Parallel() + ctx, accProviders := testAccProviders(context.Background(), t) + uniq := uniqueEntityName(ctx, t) + accProvider := testAccProvider(t, accProviders) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: accProviders, + CheckDestroy: testAccCheckDatadogIntegrationPagerdutyDestroy(accProvider), + Steps: []resource.TestStep{ + { + Config: testAccDatasourcePagerdutyIntegrationSOConfig(uniq), + Check: checkDatasourcePagerdutyIntegrationSOAttrs(accProvider, uniq), + }, + }, + }) +} + +func checkDatasourcePagerdutyIntegrationSOAttrs(accProvider func() (*schema.Provider, error), uniq string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + testAccCheckDatadogIntegrationPagerdutyExists(accProvider), + resource.TestCheckResourceAttr("data.datadog_integration_pagerduty_service_object.foo", "service_name", uniq), + ) +} + +func testAccPagerdutyIntegrationSOConfig(uniq string) string { + return fmt.Sprintf(` +resource "datadog_integration_pagerduty_service_object" "foo" { + service_name = "%s" + service_key = "%s" +} +`, uniq, uniq) +} + +func testAccDatasourcePagerdutyIntegrationSOConfig(uniq string) string { + return fmt.Sprintf(` +%s +data "datadog_integration_pagerduty_service_object" "foo" { + depends_on = [ + datadog_integration_pagerduty_service_object.foo + ] + service_name = "%s" +}`, testAccPagerdutyIntegrationSOConfig(uniq), uniq) +} diff --git a/datadog/tests/provider_test.go b/datadog/tests/provider_test.go index b5c14cb03e..8f974ffe31 100644 --- a/datadog/tests/provider_test.go +++ b/datadog/tests/provider_test.go @@ -77,6 +77,7 @@ var testFiles2EndpointTags = map[string]string{ "tests/data_source_datadog_synthetics_locations_test": "synthetics", "tests/data_source_datadog_synthetics_global_variable_test": "synthetics", "tests/data_source_datadog_synthetics_test_test": "synthetics", + "tests/data_source_datadog_pagerduty_service_object_test": "integration-pagerduty-service-object", "tests/import_datadog_downtime_test": "downtimes", "tests/import_datadog_integration_pagerduty_test": "integration-pagerduty", "tests/import_datadog_logs_pipeline_test": "logs-pipelines", From 5517fbda1e23b004b39c5b7d8250637ab9ec05ee Mon Sep 17 00:00:00 2001 From: Sam Cohen Date: Thu, 9 Feb 2023 18:09:03 -0500 Subject: [PATCH 02/10] properly set data source ID, service name key and value --- ...e_datadog_integration_pagerduty_service_object.go} | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) rename datadog/{data_source_datadog_pagerduty_service_object.go => data_source_datadog_integration_pagerduty_service_object.go} (90%) diff --git a/datadog/data_source_datadog_pagerduty_service_object.go b/datadog/data_source_datadog_integration_pagerduty_service_object.go similarity index 90% rename from datadog/data_source_datadog_pagerduty_service_object.go rename to datadog/data_source_datadog_integration_pagerduty_service_object.go index 58d63ee5fa..3aa707e56f 100644 --- a/datadog/data_source_datadog_pagerduty_service_object.go +++ b/datadog/data_source_datadog_integration_pagerduty_service_object.go @@ -44,19 +44,20 @@ func dataSourceDatadogIntegrationPagerdutySORead(ctx context.Context, d *schema. return resource.RetryableError(utils.TranslateClientError(err, httpresp, "error querying pagerduty integrations, retrying")) } if httpresp != nil && httpresp.StatusCode == 404 { - d.SetId("") - return resource.NonRetryableError(utils.TranslateClientError(err, httpresp, "pagerduty integration not found")) + d.Set("service_name", "") + return nil } return resource.NonRetryableError(utils.TranslateClientError(err, httpresp, "error querying pagerduty integrations")) } if serviceName, ok := resp.GetServiceNameOk(); !ok { - d.SetId("") - return resource.NonRetryableError(fmt.Errorf("couldn't find a pagerduty integration named %s", *serviceName)) + d.Set("service_name", "") + return resource.NonRetryableError(fmt.Errorf("couldn't find a pagerduty integration service named %s", *serviceName)) } else { - d.SetId(*serviceName) + d.Set("service_name", *serviceName) } + d.SetId("pagerduty-service-object") return nil }) if err != nil { From ab5842f85bfee2b65c7896f50f61c81817fd0e8a Mon Sep 17 00:00:00 2001 From: Sam Cohen Date: Thu, 9 Feb 2023 18:14:30 -0500 Subject: [PATCH 03/10] remove unnecessary 404 block --- ...ata_source_datadog_integration_pagerduty_service_object.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/datadog/data_source_datadog_integration_pagerduty_service_object.go b/datadog/data_source_datadog_integration_pagerduty_service_object.go index 3aa707e56f..587c98da94 100644 --- a/datadog/data_source_datadog_integration_pagerduty_service_object.go +++ b/datadog/data_source_datadog_integration_pagerduty_service_object.go @@ -43,10 +43,6 @@ func dataSourceDatadogIntegrationPagerdutySORead(ctx context.Context, d *schema. if httpresp != nil && (httpresp.StatusCode == 504 || httpresp.StatusCode == 502) { return resource.RetryableError(utils.TranslateClientError(err, httpresp, "error querying pagerduty integrations, retrying")) } - if httpresp != nil && httpresp.StatusCode == 404 { - d.Set("service_name", "") - return nil - } return resource.NonRetryableError(utils.TranslateClientError(err, httpresp, "error querying pagerduty integrations")) } From 85af52b6512f1751fde300efc03f1ecda6bbd815 Mon Sep 17 00:00:00 2001 From: Sam Cohen Date: Thu, 9 Feb 2023 18:16:59 -0500 Subject: [PATCH 04/10] add back 404 block to distinguish between 404 not found and error getting service name after 200 response --- ...ta_source_datadog_integration_pagerduty_service_object.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/datadog/data_source_datadog_integration_pagerduty_service_object.go b/datadog/data_source_datadog_integration_pagerduty_service_object.go index 587c98da94..1665ffc7bb 100644 --- a/datadog/data_source_datadog_integration_pagerduty_service_object.go +++ b/datadog/data_source_datadog_integration_pagerduty_service_object.go @@ -43,6 +43,11 @@ func dataSourceDatadogIntegrationPagerdutySORead(ctx context.Context, d *schema. if httpresp != nil && (httpresp.StatusCode == 504 || httpresp.StatusCode == 502) { return resource.RetryableError(utils.TranslateClientError(err, httpresp, "error querying pagerduty integrations, retrying")) } + if httpresp != nil && httpresp.StatusCode == 404 { + d.Set("service_name", "") + d.SetId("pagerduty-service-object") + return nil + } return resource.NonRetryableError(utils.TranslateClientError(err, httpresp, "error querying pagerduty integrations")) } From 8e35c33880da3219bc39af72b1364d3bcd8a5e14 Mon Sep 17 00:00:00 2001 From: Sam Cohen Date: Fri, 10 Feb 2023 08:44:57 -0500 Subject: [PATCH 05/10] undo recent changes to pagerduty so data source --- ...source_datadog_integration_pagerduty_service_object.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/datadog/data_source_datadog_integration_pagerduty_service_object.go b/datadog/data_source_datadog_integration_pagerduty_service_object.go index 1665ffc7bb..60f7a43885 100644 --- a/datadog/data_source_datadog_integration_pagerduty_service_object.go +++ b/datadog/data_source_datadog_integration_pagerduty_service_object.go @@ -44,21 +44,19 @@ func dataSourceDatadogIntegrationPagerdutySORead(ctx context.Context, d *schema. return resource.RetryableError(utils.TranslateClientError(err, httpresp, "error querying pagerduty integrations, retrying")) } if httpresp != nil && httpresp.StatusCode == 404 { - d.Set("service_name", "") - d.SetId("pagerduty-service-object") + d.SetId("") return nil } return resource.NonRetryableError(utils.TranslateClientError(err, httpresp, "error querying pagerduty integrations")) } if serviceName, ok := resp.GetServiceNameOk(); !ok { - d.Set("service_name", "") + d.SetId("") return resource.NonRetryableError(fmt.Errorf("couldn't find a pagerduty integration service named %s", *serviceName)) } else { - d.Set("service_name", *serviceName) + d.SetId(*serviceName) } - d.SetId("pagerduty-service-object") return nil }) if err != nil { From 7e327e9c422f81de57c54f708c70b5245fa09fb5 Mon Sep 17 00:00:00 2001 From: Sam Cohen Date: Fri, 10 Feb 2023 10:46:19 -0500 Subject: [PATCH 06/10] generate docs --- .../integration_pagerduty_service_object.md | 38 +++++++++++++++++++ .../data-source.tf | 9 +++++ 2 files changed, 47 insertions(+) create mode 100644 docs/data-sources/integration_pagerduty_service_object.md create mode 100644 examples/data-sources/datadog_integration_pagerduty_service_object/data-source.tf diff --git a/docs/data-sources/integration_pagerduty_service_object.md b/docs/data-sources/integration_pagerduty_service_object.md new file mode 100644 index 0000000000..8ce3b8dcfd --- /dev/null +++ b/docs/data-sources/integration_pagerduty_service_object.md @@ -0,0 +1,38 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "datadog_integration_pagerduty_service_object Data Source - terraform-provider-datadog" +subcategory: "" +description: |- + Use this data source to retrieve individual Service Objects of Datadog - PagerDuty integrations. Note that the Datadog - PagerDuty integration must be activated in the Datadog UI in order for this resource to be usable. +--- + +# datadog_integration_pagerduty_service_object (Data Source) + +Use this data source to retrieve individual Service Objects of Datadog - PagerDuty integrations. Note that the Datadog - PagerDuty integration must be activated in the Datadog UI in order for this resource to be usable. + +## Example Usage + +```terraform +data "datadog_integration_pagerduty_service_object" "foo" { + service_name = "foo" +} + +resource "datadog_integration_pagerduty_service_object" "foo" { + count = length(datadog_integration_pagerduty_service_object.foo) > 0 ? 1 : 0 + service_name = "foo" + service_key = "foo" +} +``` + + +## Schema + +### Required + +- `service_name` (String) Your Service name in PagerDuty. + +### Read-Only + +- `id` (String) The ID of this resource. + + diff --git a/examples/data-sources/datadog_integration_pagerduty_service_object/data-source.tf b/examples/data-sources/datadog_integration_pagerduty_service_object/data-source.tf new file mode 100644 index 0000000000..c87e3ca328 --- /dev/null +++ b/examples/data-sources/datadog_integration_pagerduty_service_object/data-source.tf @@ -0,0 +1,9 @@ +data "datadog_integration_pagerduty_service_object" "foo" { + service_name = "foo" +} + +resource "datadog_integration_pagerduty_service_object" "foo" { + count = length(datadog_integration_pagerduty_service_object.foo) > 0 ? 1 : 0 + service_name = "foo" + service_key = "foo" +} \ No newline at end of file From 8c0c04ea6f23e8364f7d965e3dfae98db0e5198b Mon Sep 17 00:00:00 2001 From: Kevin Zou Date: Fri, 10 Feb 2023 13:47:10 -0500 Subject: [PATCH 07/10] make fmt and docs --- docs/data-sources/integration_pagerduty_service_object.md | 4 ++-- .../data-source.tf | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/data-sources/integration_pagerduty_service_object.md b/docs/data-sources/integration_pagerduty_service_object.md index 8ce3b8dcfd..46a85d82cc 100644 --- a/docs/data-sources/integration_pagerduty_service_object.md +++ b/docs/data-sources/integration_pagerduty_service_object.md @@ -18,9 +18,9 @@ data "datadog_integration_pagerduty_service_object" "foo" { } resource "datadog_integration_pagerduty_service_object" "foo" { - count = length(datadog_integration_pagerduty_service_object.foo) > 0 ? 1 : 0 + count = length(datadog_integration_pagerduty_service_object.foo) > 0 ? 1 : 0 service_name = "foo" - service_key = "foo" + service_key = "foo" } ``` diff --git a/examples/data-sources/datadog_integration_pagerduty_service_object/data-source.tf b/examples/data-sources/datadog_integration_pagerduty_service_object/data-source.tf index c87e3ca328..5e29a9b0fd 100644 --- a/examples/data-sources/datadog_integration_pagerduty_service_object/data-source.tf +++ b/examples/data-sources/datadog_integration_pagerduty_service_object/data-source.tf @@ -3,7 +3,7 @@ data "datadog_integration_pagerduty_service_object" "foo" { } resource "datadog_integration_pagerduty_service_object" "foo" { - count = length(datadog_integration_pagerduty_service_object.foo) > 0 ? 1 : 0 + count = length(datadog_integration_pagerduty_service_object.foo) > 0 ? 1 : 0 service_name = "foo" - service_key = "foo" + service_key = "foo" } \ No newline at end of file From 73224b2b95ce39b23fd6bf682cf72f66872579d4 Mon Sep 17 00:00:00 2001 From: Kevin Zou Date: Fri, 10 Feb 2023 14:20:03 -0500 Subject: [PATCH 08/10] reorder test file and change endpoint --- datadog/tests/provider_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datadog/tests/provider_test.go b/datadog/tests/provider_test.go index 8f974ffe31..004d0f15ac 100644 --- a/datadog/tests/provider_test.go +++ b/datadog/tests/provider_test.go @@ -65,6 +65,7 @@ var testFiles2EndpointTags = map[string]string{ "tests/data_source_datadog_monitors_test": "monitors", "tests/data_source_datadog_monitor_config_policy_test": "monitor-config-policies", "tests/data_source_datadog_monitor_config_policies_test": "monitor-config-policies", + "tests/data_source_datadog_pagerduty_service_object_test": "integration-pagerduty", "tests/data_source_datadog_permissions_test": "permissions", "tests/data_source_datadog_role_test": "roles", "tests/data_source_datadog_roles_test": "roles", @@ -77,7 +78,6 @@ var testFiles2EndpointTags = map[string]string{ "tests/data_source_datadog_synthetics_locations_test": "synthetics", "tests/data_source_datadog_synthetics_global_variable_test": "synthetics", "tests/data_source_datadog_synthetics_test_test": "synthetics", - "tests/data_source_datadog_pagerduty_service_object_test": "integration-pagerduty-service-object", "tests/import_datadog_downtime_test": "downtimes", "tests/import_datadog_integration_pagerduty_test": "integration-pagerduty", "tests/import_datadog_logs_pipeline_test": "logs-pipelines", From 798b2ec87eef2c3184c05a7d9e8c3d91052030af Mon Sep 17 00:00:00 2001 From: Kevin Zou <17015060+nkzou@users.noreply.github.com> Date: Fri, 10 Feb 2023 16:52:59 -0500 Subject: [PATCH 09/10] Update datadog/data_source_datadog_integration_pagerduty_service_object.go Co-authored-by: Heston Hoffman --- .../data_source_datadog_integration_pagerduty_service_object.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datadog/data_source_datadog_integration_pagerduty_service_object.go b/datadog/data_source_datadog_integration_pagerduty_service_object.go index 60f7a43885..d18bde5430 100644 --- a/datadog/data_source_datadog_integration_pagerduty_service_object.go +++ b/datadog/data_source_datadog_integration_pagerduty_service_object.go @@ -15,7 +15,7 @@ import ( func dataSourceDatadogIntegrationPagerdutySO() *schema.Resource { return &schema.Resource{ - Description: "Use this data source to retrieve individual Service Objects of Datadog - PagerDuty integrations. Note that the Datadog - PagerDuty integration must be activated in the Datadog UI in order for this resource to be usable.", + Description: "Use this data source to retrieve individual Service Objects of Datadog PagerDuty integrations. Note that the Datadog PagerDuty integration must be activated in the Datadog UI in order for this resource to be usable.", ReadContext: dataSourceDatadogIntegrationPagerdutySORead, Schema: map[string]*schema.Schema{ From c403c901498b90c177af7c78410df7f77f23abac Mon Sep 17 00:00:00 2001 From: Kevin Zou Date: Mon, 13 Feb 2023 09:27:13 -0500 Subject: [PATCH 10/10] make docs --- docs/data-sources/integration_pagerduty_service_object.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/data-sources/integration_pagerduty_service_object.md b/docs/data-sources/integration_pagerduty_service_object.md index 46a85d82cc..a8e2d1a420 100644 --- a/docs/data-sources/integration_pagerduty_service_object.md +++ b/docs/data-sources/integration_pagerduty_service_object.md @@ -3,12 +3,12 @@ page_title: "datadog_integration_pagerduty_service_object Data Source - terraform-provider-datadog" subcategory: "" description: |- - Use this data source to retrieve individual Service Objects of Datadog - PagerDuty integrations. Note that the Datadog - PagerDuty integration must be activated in the Datadog UI in order for this resource to be usable. + Use this data source to retrieve individual Service Objects of Datadog PagerDuty integrations. Note that the Datadog PagerDuty integration must be activated in the Datadog UI in order for this resource to be usable. --- # datadog_integration_pagerduty_service_object (Data Source) -Use this data source to retrieve individual Service Objects of Datadog - PagerDuty integrations. Note that the Datadog - PagerDuty integration must be activated in the Datadog UI in order for this resource to be usable. +Use this data source to retrieve individual Service Objects of Datadog PagerDuty integrations. Note that the Datadog PagerDuty integration must be activated in the Datadog UI in order for this resource to be usable. ## Example Usage