Skip to content

Commit

Permalink
Merge pull request #544 from txominpelu/inigo.mediavilla/logs_archive…
Browse files Browse the repository at this point in the history
…s_provider
  • Loading branch information
gzussa authored Jun 26, 2020
2 parents 1cca0c4 + 1463897 commit 288436d
Show file tree
Hide file tree
Showing 35 changed files with 5,089 additions and 99 deletions.
648 changes: 648 additions & 0 deletions datadog/cassettes/TestAccDatadogDashboard_update.yaml

Large diffs are not rendered by default.

547 changes: 547 additions & 0 deletions datadog/cassettes/TestAccDatadogLogsArchiveAzure_basic.yaml

Large diffs are not rendered by default.

829 changes: 829 additions & 0 deletions datadog/cassettes/TestAccDatadogLogsArchiveGCS_basic.yaml

Large diffs are not rendered by default.

1,356 changes: 1,356 additions & 0 deletions datadog/cassettes/TestAccDatadogLogsArchiveS3Update_basic.yaml

Large diffs are not rendered by default.

829 changes: 829 additions & 0 deletions datadog/cassettes/TestAccDatadogLogsArchiveS3_basic.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion datadog/data_source_datadog_ip_ranges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestAccDatadogIpRangesDatasource_existing(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)

resource.ParallelTest(t, resource.TestCase{
Expand Down
2 changes: 1 addition & 1 deletion datadog/import_datadog_downtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestDatadogDowntime_import(t *testing.T) {
resourceName := "datadog_downtime.foo"
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
2 changes: 1 addition & 1 deletion datadog/import_datadog_integration_pagerduty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestDatadogIntegrationPagerduty_import(t *testing.T) {
resourceName := "datadog_integration_pagerduty.pd"
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
2 changes: 1 addition & 1 deletion datadog/import_datadog_logs_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ resource "datadog_logs_custom_pipeline" "test_import" {
`

func TestAccLogsCustomPipeline_importBasic(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
4 changes: 2 additions & 2 deletions datadog/import_datadog_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestDatadogMonitor_import(t *testing.T) {
resourceName := "datadog_monitor.foo"
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand All @@ -31,7 +31,7 @@ func TestDatadogMonitor_import(t *testing.T) {

func TestDatadogMonitor_import_no_recovery(t *testing.T) {
resourceName := "datadog_monitor.foo"
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
2 changes: 1 addition & 1 deletion datadog/import_datadog_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestDatadogUser_import(t *testing.T) {
resourceName := "datadog_user.foo"
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
1 change: 1 addition & 0 deletions datadog/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func Provider() terraform.ResourceProvider {
"datadog_integration_gcp": resourceDatadogIntegrationGcp(),
"datadog_integration_pagerduty": resourceDatadogIntegrationPagerduty(),
"datadog_integration_pagerduty_service_object": resourceDatadogIntegrationPagerdutySO(),
"datadog_logs_archive": resourceDatadogLogsArchive(),
"datadog_logs_custom_pipeline": resourceDatadogLogsCustomPipeline(),
"datadog_logs_index": resourceDatadogLogsIndex(),
"datadog_logs_index_order": resourceDatadogLogsIndexOrder(),
Expand Down
78 changes: 44 additions & 34 deletions datadog/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,45 @@ func initAccProvider(t *testing.T, httpClient *http.Client) *schema.Provider {
return p
}

func buildAuthV1(apiKey string, appKey string, apiURL string) (context.Context, error) {
authV1 := context.WithValue(
context.Background(),
datadogV1.ContextAPIKeys,
map[string]datadogV1.APIKey{
"apiKeyAuth": datadogV1.APIKey{
Key: apiKey,
},
"appKeyAuth": datadogV1.APIKey{
Key: appKey,
},
},
)
if apiURL != "" {
parsedApiUrl, parseErr := url.Parse(apiURL)
if parseErr != nil {
return nil, fmt.Errorf(`invalid API Url : %v`, parseErr)
}
if parsedApiUrl.Host == "" || parsedApiUrl.Scheme == "" {
return nil, fmt.Errorf(`missing protocol or host : %v`, apiURL)
}
// If api url is passed, set and use the api name and protocol on ServerIndex{1}
authV1 = context.WithValue(authV1, datadogV1.ContextServerIndex, 1)
authV1 = context.WithValue(authV1, datadogV1.ContextServerVariables, map[string]string{
"name": parsedApiUrl.Host,
"protocol": parsedApiUrl.Scheme,
})
}
return authV1, nil
}

func buildDatadogClientV1(httpClient *http.Client) *datadogV1.APIClient {
//Datadog V1 API config.HTTPClient
configV1 := datadogV1.NewConfiguration()
configV1.Debug = isDebug()
configV1.HTTPClient = httpClient
return datadogV1.NewAPIClient(configV1)
}

func testProviderConfigure(httpClient *http.Client) schema.ConfigureFunc {
return func(d *schema.ResourceData) (interface{}, error) {
communityClient := datadogCommunity.NewClient(d.Get("api_key").(string), d.Get("app_key").(string))
Expand All @@ -153,39 +192,11 @@ func testProviderConfigure(httpClient *http.Client) schema.ConfigureFunc {
communityClient.HttpClient = c
communityClient.ExtraHeader["User-Agent"] = fmt.Sprintf("Datadog/%s/terraform (%s)", version.ProviderVersion, runtime.Version())

// Initialize the official datadog client
authV1 := context.WithValue(
context.Background(),
datadogV1.ContextAPIKeys,
map[string]datadogV1.APIKey{
"apiKeyAuth": datadogV1.APIKey{
Key: d.Get("api_key").(string),
},
"appKeyAuth": datadogV1.APIKey{
Key: d.Get("app_key").(string),
},
},
)
//Datadog V1 API config.HTTPClient
configV1 := datadogV1.NewConfiguration()
configV1.Debug = isDebug()
configV1.HTTPClient = c
if apiURL := d.Get("api_url").(string); apiURL != "" {
parsedApiUrl, parseErr := url.Parse(apiURL)
if parseErr != nil {
return nil, fmt.Errorf(`invalid API Url : %v`, parseErr)
}
if parsedApiUrl.Host == "" || parsedApiUrl.Scheme == "" {
return nil, fmt.Errorf(`missing protocol or host : %v`, apiURL)
}
// If api url is passed, set and use the api name and protocol on ServerIndex{1}
authV1 = context.WithValue(authV1, datadogV1.ContextServerIndex, 1)
authV1 = context.WithValue(authV1, datadogV1.ContextServerVariables, map[string]string{
"name": parsedApiUrl.Host,
"protocol": parsedApiUrl.Scheme,
})
authV1, err := buildAuthV1(d.Get("api_key").(string), d.Get("app_key").(string), d.Get("api_url").(string))
if err != nil {
return nil, err
}
datadogClientV1 := datadogV1.NewAPIClient(configV1)
datadogClientV1 := buildDatadogClientV1(httpClient)

// Initialize the official datadog v2 API client
authV2 := context.WithValue(
Expand Down Expand Up @@ -238,8 +249,7 @@ func testAccProvidersWithHttpClient(t *testing.T, httpClient *http.Client) map[s
}
}

func testAccProviders(t *testing.T) (map[string]terraform.ResourceProvider, func(t *testing.T)) {
rec := initRecorder(t)
func testAccProviders(t *testing.T, rec *recorder.Recorder) (map[string]terraform.ResourceProvider, func(t *testing.T)) {
c := cleanhttp.DefaultClient()
c.Transport = logging.NewTransport("Datadog", rec)
return testAccProvidersWithHttpClient(t, c), func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion datadog/resource_datadog_dashboard_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ resource "datadog_dashboard" "screen" {

func TestDatadogDashListImport(t *testing.T) {
resourceName := "datadog_dashboard_list.new_list"
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
12 changes: 6 additions & 6 deletions datadog/resource_datadog_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,8 @@ var datadogFreeDashboardAsserts = []string{
"template_variable_preset.1.template_variable.0.value = var_1_value",
}

func TestAccDatadogOrderedDashboard(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
func TestAccDatadogDashboard_update(t *testing.T) {
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand All @@ -959,7 +959,7 @@ func TestAccDatadogOrderedDashboard(t *testing.T) {
}

func TestAccDatadogFreeDashboard(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand All @@ -979,7 +979,7 @@ func TestAccDatadogFreeDashboard(t *testing.T) {
}

func TestAccDatadogDashboard_import(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down Expand Up @@ -1043,7 +1043,7 @@ func checkDashboardDestroy(accProvider *schema.Provider) resource.TestCheckFunc
}

func testAccDatadogDashboardWidgetUtil(t *testing.T, config string, name string, assertions []string) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand All @@ -1063,7 +1063,7 @@ func testAccDatadogDashboardWidgetUtil(t *testing.T, config string, name string,
}

func testAccDatadogDashboardWidgetUtil_import(t *testing.T, config string, name string) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
24 changes: 12 additions & 12 deletions datadog/resource_datadog_downtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func TestAccDatadogDowntime_Basic(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down Expand Up @@ -50,7 +50,7 @@ func TestAccDatadogDowntime_Basic(t *testing.T) {
}

func TestAccDatadogDowntime_BasicWithMonitor(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand All @@ -76,7 +76,7 @@ func TestAccDatadogDowntime_BasicWithMonitor(t *testing.T) {
}

func TestAccDatadogDowntime_BasicWithMonitorTags(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand All @@ -102,7 +102,7 @@ func TestAccDatadogDowntime_BasicWithMonitorTags(t *testing.T) {
}

func TestAccDatadogDowntime_BasicMultiScope(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down Expand Up @@ -138,7 +138,7 @@ func TestAccDatadogDowntime_BasicMultiScope(t *testing.T) {
}

func TestAccDatadogDowntime_BasicNoRecurrence(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down Expand Up @@ -168,7 +168,7 @@ func TestAccDatadogDowntime_BasicNoRecurrence(t *testing.T) {
}

func TestAccDatadogDowntime_BasicUntilDateRecurrence(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down Expand Up @@ -204,7 +204,7 @@ func TestAccDatadogDowntime_BasicUntilDateRecurrence(t *testing.T) {
}

func TestAccDatadogDowntime_BasicUntilOccurrencesRecurrence(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down Expand Up @@ -240,7 +240,7 @@ func TestAccDatadogDowntime_BasicUntilOccurrencesRecurrence(t *testing.T) {
}

func TestAccDatadogDowntime_WeekDayRecurring(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down Expand Up @@ -278,7 +278,7 @@ func TestAccDatadogDowntime_WeekDayRecurring(t *testing.T) {
}

func TestAccDatadogDowntime_Updated(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down Expand Up @@ -332,7 +332,7 @@ func TestAccDatadogDowntime_Updated(t *testing.T) {
}

func TestAccDatadogDowntime_TrimWhitespace(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down Expand Up @@ -392,7 +392,7 @@ func testAccCheckDatadogDowntimeExists(accProvider *schema.Provider, n string) r
}

func TestAccDatadogDowntimeDates(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down Expand Up @@ -426,7 +426,7 @@ func TestAccDatadogDowntimeDates(t *testing.T) {
}

func TestAccDatadogDowntimeDatesConflict(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ resource "datadog_integration_aws_lambda_arn" "main_collector" {
`

func TestAccDatadogIntegrationAWSLambdaArn(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ resource "datadog_integration_aws_log_collection" "main" {
`

func TestAccDatadogIntegrationAWSLogCollection(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
2 changes: 1 addition & 1 deletion datadog/resource_datadog_integration_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ resource "datadog_integration_aws" "account" {
`

func TestAccDatadogIntegrationAWS(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
2 changes: 1 addition & 1 deletion datadog/resource_datadog_integration_gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ resource "datadog_integration_gcp" "awesome_gcp_project_integration" {
`

func TestAccDatadogIntegrationGCP(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// We're not testing for schedules because Datadog actively verifies it with Pagerduty

func TestAccDatadogIntegrationPagerdutyServiceObject_Basic(t *testing.T) {
accProviders, cleanup := testAccProviders(t)
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)

Expand Down
Loading

0 comments on commit 288436d

Please sign in to comment.