From fca0943ddd59d097fcec931ffc27c4e7d5ab65d2 Mon Sep 17 00:00:00 2001 From: Ting Tu Date: Fri, 20 Sep 2019 14:56:51 +0200 Subject: [PATCH] address comments --- datadog/import_datadog_logs_pipeline_test.go | 15 +- datadog/provider.go | 4 +- datadog/resource_datadog_logs_pipeline.go | 290 +++++++++--------- ...> resource_datadog_logs_pipeline_order.go} | 5 +- ...ource_datadog_logs_pipeline_order_test.go} | 12 +- website/datadog.erb | 6 + website/docs/r/logs_pipeline.html.markdown | 42 +-- .../docs/r/logs_pipeline_order.html.markdown | 50 +++ 8 files changed, 240 insertions(+), 184 deletions(-) rename datadog/{resource_datadog_logs_pipelineorder.go => resource_datadog_logs_pipeline_order.go} (93%) rename datadog/{resource_datadog_logs_pipelineorder_test.go => resource_datadog_logs_pipeline_order_test.go} (85%) create mode 100644 website/docs/r/logs_pipeline_order.html.markdown diff --git a/datadog/import_datadog_logs_pipeline_test.go b/datadog/import_datadog_logs_pipeline_test.go index e32e5220f3..076c243021 100644 --- a/datadog/import_datadog_logs_pipeline_test.go +++ b/datadog/import_datadog_logs_pipeline_test.go @@ -57,6 +57,13 @@ resource "datadog_logs_pipeline" "test_import" { sources = ["date"] } } + processor { + date_remapper { + name = "2nd date remapper" + is_enabled = true + sources = ["other"] + } + } processor { message_remapper { name = "test message remapper" @@ -120,13 +127,13 @@ resource "datadog_logs_pipeline" "test_import" { ` const pipelineorderConfigForImport = ` -resource "datadog_logs_pipelineorder" "pipelines" { +resource "datadog_logs_pipeline_order" "pipelines" { name = "pipelines" pipelines = [ "TOYNsNfjTD6zTXVg8_ej1g", - "VxXfWxegScyjG8mMJwnFIA", - "GGVTp-5PT_O9Xhmsxnsu_w", - "VgZXJneKR2qh2WcfAQi6fA" + "VxXfWxegScyjG8mMJwnFIA", + "GGVTp-5PT_O9Xhmsxnsu_w", + "VgZXJneKR2qh2WcfAQi6fA" ] } ` diff --git a/datadog/provider.go b/datadog/provider.go index b4ba175475..e6924b0e1c 100644 --- a/datadog/provider.go +++ b/datadog/provider.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform/helper/logging" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/terraform" - datadog "github.com/zorkian/go-datadog-api" + "github.com/zorkian/go-datadog-api" ) func Provider() terraform.ResourceProvider { @@ -47,7 +47,7 @@ func Provider() terraform.ResourceProvider { "datadog_timeboard": resourceDatadogTimeboard(), "datadog_user": resourceDatadogUser(), "datadog_logs_pipeline": resourceDatadogLogsPipeline(), - "datadog_logs_pipelineorder": resourceDatadogLogsPipelineOrder(), + "datadog_logs_pipeline_order": resourceDatadogLogsPipelineOrder(), }, ConfigureFunc: providerConfigure, diff --git a/datadog/resource_datadog_logs_pipeline.go b/datadog/resource_datadog_logs_pipeline.go index 808ccc588c..0e0d0bd7b7 100644 --- a/datadog/resource_datadog_logs_pipeline.go +++ b/datadog/resource_datadog_logs_pipeline.go @@ -37,6 +37,20 @@ var tfProcessorTypes = map[string]string{ tfUserAgentParserProcessor: datadog.UserAgentParserType, } +var tfProcessors = map[string]*schema.Schema{ + tfArithmeticProcessor: arithmeticProcessor, + tfAttributeRemapperProcessor: attributeRemapper, + tfCategoryProcessor: categoryProcessor, + tfDateRemapperProcessor: dateRemapper, + tfGrokParserProcessor: grokParser, + tfMessageRemapperProcessor: messageRemapper, + tfServiceRemapperProcessor: serviceRemapper, + tfStatusRemapperProcessor: statusRemmaper, + tfTraceIdRemapperProcessor: traceIdRemapper, + tfUrlParserProcessor: urlParser, + tfUserAgentParserProcessor: userAgentParser, +} + var ddProcessorTypes = map[string]string{ datadog.ArithmeticProcessorType: tfArithmeticProcessor, datadog.AttributeRemapperType: tfAttributeRemapperProcessor, @@ -52,59 +66,132 @@ var ddProcessorTypes = map[string]string{ datadog.UserAgentParserType: tfUserAgentParserProcessor, } -var arithmeticProcessor = map[string]*schema.Schema{ - "name": {Type: schema.TypeString, Optional: true}, - "is_enabled": {Type: schema.TypeBool, Optional: true}, - "expression": {Type: schema.TypeString, Required: true}, - "target": {Type: schema.TypeString, Required: true}, - "is_replace_missing": {Type: schema.TypeBool, Optional: true}, +var arithmeticProcessor = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": {Type: schema.TypeString, Optional: true}, + "is_enabled": {Type: schema.TypeBool, Optional: true}, + "expression": {Type: schema.TypeString, Required: true}, + "target": {Type: schema.TypeString, Required: true}, + "is_replace_missing": {Type: schema.TypeBool, Optional: true}, + }, + }, } -var attributeRemapper = map[string]*schema.Schema{ - "name": {Type: schema.TypeString, Optional: true}, - "is_enabled": {Type: schema.TypeBool, Optional: true}, - "sources": {Type: schema.TypeList, Required: true, Elem: &schema.Schema{Type: schema.TypeString}}, - "source_type": {Type: schema.TypeString, Required: true}, - "target": {Type: schema.TypeString, Required: true}, - "target_type": {Type: schema.TypeString, Required: true}, - "preserve_source": {Type: schema.TypeBool, Optional: true}, - "override_on_conflict": {Type: schema.TypeBool, Optional: true}, +var attributeRemapper = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": {Type: schema.TypeString, Optional: true}, + "is_enabled": {Type: schema.TypeBool, Optional: true}, + "sources": {Type: schema.TypeList, Required: true, Elem: &schema.Schema{Type: schema.TypeString}}, + "source_type": {Type: schema.TypeString, Required: true}, + "target": {Type: schema.TypeString, Required: true}, + "target_type": {Type: schema.TypeString, Required: true}, + "preserve_source": {Type: schema.TypeBool, Optional: true}, + "override_on_conflict": {Type: schema.TypeBool, Optional: true}, + }, + }, } -var categoryProcessor = map[string]*schema.Schema{ - "name": {Type: schema.TypeString, Optional: true}, - "is_enabled": {Type: schema.TypeBool, Optional: true}, - "target": {Type: schema.TypeString, Required: true}, - "category": {Type: schema.TypeList, Required: true, Elem: &schema.Resource{ +var categoryProcessor = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "filter": { + "name": {Type: schema.TypeString, Optional: true}, + "is_enabled": {Type: schema.TypeBool, Optional: true}, + "target": {Type: schema.TypeString, Required: true}, + "category": {Type: schema.TypeList, Required: true, Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "filter": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "query": {Type: schema.TypeString, Required: true}, + }, + }, + }, + "name": {Type: schema.TypeString, Required: true}, + }, + }}, + }, + }, +} + +var dateRemapper = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: sourceRemapper, + }, +} + +var grokParser = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": {Type: schema.TypeString, Optional: true}, + "is_enabled": {Type: schema.TypeBool, Optional: true}, + "source": {Type: schema.TypeString, Required: true}, + "grok": { Type: schema.TypeList, + MaxItems: 1, Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "query": {Type: schema.TypeString, Required: true}, + "support_rules": {Type: schema.TypeString, Required: true}, + "match_rules": {Type: schema.TypeString, Required: true}, }, }, }, - "name": {Type: schema.TypeString, Required: true}, }, - }}, + }, } -var grokParser = map[string]*schema.Schema{ - "name": {Type: schema.TypeString, Optional: true}, - "is_enabled": {Type: schema.TypeBool, Optional: true}, - "source": {Type: schema.TypeString, Required: true}, - "grok": { - Type: schema.TypeList, - MaxItems: 1, - Required: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "support_rules": {Type: schema.TypeString, Required: true}, - "match_rules": {Type: schema.TypeString, Required: true}, - }, - }, +var messageRemapper = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: sourceRemapper, + }, +} + +var serviceRemapper = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: sourceRemapper, + }, +} + +var statusRemmaper = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: sourceRemapper, + }, +} + +var traceIdRemapper = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: sourceRemapper, }, } @@ -114,20 +201,34 @@ var sourceRemapper = map[string]*schema.Schema{ "sources": {Type: schema.TypeList, Required: true, Elem: &schema.Schema{Type: schema.TypeString}}, } -var urlParser = map[string]*schema.Schema{ - "name": {Type: schema.TypeString, Optional: true}, - "is_enabled": {Type: schema.TypeBool, Optional: true}, - "sources": {Type: schema.TypeList, Required: true, Elem: &schema.Schema{Type: schema.TypeString}}, - "target": {Type: schema.TypeString, Required: true}, - "normalize_ending_slashes": {Type: schema.TypeBool, Optional: true}, +var urlParser = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": {Type: schema.TypeString, Optional: true}, + "is_enabled": {Type: schema.TypeBool, Optional: true}, + "sources": {Type: schema.TypeList, Required: true, Elem: &schema.Schema{Type: schema.TypeString}}, + "target": {Type: schema.TypeString, Required: true}, + "normalize_ending_slashes": {Type: schema.TypeBool, Optional: true}, + }, + }, } -var userAgentParser = map[string]*schema.Schema{ - "name": {Type: schema.TypeString, Optional: true}, - "is_enabled": {Type: schema.TypeBool, Optional: true}, - "sources": {Type: schema.TypeList, Required: true, Elem: &schema.Schema{Type: schema.TypeString}}, - "target": {Type: schema.TypeString, Required: true}, - "is_encoded": {Type: schema.TypeBool, Optional: true}, +var userAgentParser = &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": {Type: schema.TypeString, Optional: true}, + "is_enabled": {Type: schema.TypeBool, Optional: true}, + "sources": {Type: schema.TypeList, Required: true, Elem: &schema.Schema{Type: schema.TypeString}}, + "target": {Type: schema.TypeString, Required: true}, + "is_encoded": {Type: schema.TypeBool, Optional: true}, + }, + }, } func resourceDatadogLogsPipeline() *schema.Resource { @@ -613,93 +714,8 @@ func getProcessorSchema(isNested bool) map[string]*schema.Schema { }, } } - processorsSchema[tfArithmeticProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: arithmeticProcessor, - }, - } - processorsSchema[tfAttributeRemapperProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: attributeRemapper, - }, - } - processorsSchema[tfCategoryProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: categoryProcessor, - }, - } - processorsSchema[tfDateRemapperProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: sourceRemapper, - }, - } - processorsSchema[tfGrokParserProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: grokParser, - }, - } - processorsSchema[tfMessageRemapperProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: sourceRemapper, - }, - } - processorsSchema[tfServiceRemapperProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: sourceRemapper, - }, - } - processorsSchema[tfStatusRemapperProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: sourceRemapper, - }, - } - processorsSchema[tfTraceIdRemapperProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: sourceRemapper, - }, - } - processorsSchema[tfUrlParserProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: urlParser, - }, - } - processorsSchema[tfUserAgentParserProcessor] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: userAgentParser, - }, + for tfProcessorType, processor := range tfProcessors { + processorsSchema[tfProcessorType] = processor } return processorsSchema } diff --git a/datadog/resource_datadog_logs_pipelineorder.go b/datadog/resource_datadog_logs_pipeline_order.go similarity index 93% rename from datadog/resource_datadog_logs_pipelineorder.go rename to datadog/resource_datadog_logs_pipeline_order.go index d1d81f7f80..508ce886b7 100644 --- a/datadog/resource_datadog_logs_pipelineorder.go +++ b/datadog/resource_datadog_logs_pipeline_order.go @@ -71,8 +71,5 @@ func resourceDatadogLogsPipelineOrderDelete(d *schema.ResourceData, meta interfa } func resourceDatadogLogsPipelineOrderExists(d *schema.ResourceData, meta interface{}) (bool, error) { - if pipelineList, err := meta.(*datadog.Client).GetLogsPipelineList(); err == nil && len(pipelineList.PipelineIds) > 0 { - return true, nil - } - return false, nil + return true, nil } diff --git a/datadog/resource_datadog_logs_pipelineorder_test.go b/datadog/resource_datadog_logs_pipeline_order_test.go similarity index 85% rename from datadog/resource_datadog_logs_pipelineorder_test.go rename to datadog/resource_datadog_logs_pipeline_order_test.go index 4a6de662cb..691c1ee6f9 100644 --- a/datadog/resource_datadog_logs_pipelineorder_test.go +++ b/datadog/resource_datadog_logs_pipeline_order_test.go @@ -21,7 +21,7 @@ resource "datadog_logs_pipeline" "pipeline_2" { } } -resource "datadog_logs_pipelineorder" "pipelines" { +resource "datadog_logs_pipeline_order" "pipelines" { depends_on = [ "datadog_logs_pipeline.pipeline_1", "datadog_logs_pipeline.pipeline_2" @@ -53,7 +53,7 @@ resource "datadog_logs_pipeline" "pipeline_2" { } } -resource "datadog_logs_pipelineorder" "pipelines" { +resource "datadog_logs_pipeline_order" "pipelines" { depends_on = [ "datadog_logs_pipeline.pipeline_1", "datadog_logs_pipeline.pipeline_2" @@ -81,9 +81,9 @@ func TestAccDatadogLogsPipelineOrder_basic(t *testing.T) { testAccCheckPipelineExists("datadog_logs_pipeline.pipeline_1"), testAccCheckPipelineExists("datadog_logs_pipeline.pipeline_2"), resource.TestCheckResourceAttr( - "datadog_logs_pipelineorder.pipelines", "name", "pipelines"), + "datadog_logs_pipeline_order.pipelines", "name", "pipelines"), resource.TestCheckResourceAttr( - "datadog_logs_pipelineorder.pipelines", "pipelines.#", "5"), + "datadog_logs_pipeline_order.pipelines", "pipelines.#", "5"), ), }, { @@ -92,9 +92,9 @@ func TestAccDatadogLogsPipelineOrder_basic(t *testing.T) { testAccCheckPipelineExists("datadog_logs_pipeline.pipeline_2"), testAccCheckPipelineExists("datadog_logs_pipeline.pipeline_1"), resource.TestCheckResourceAttr( - "datadog_logs_pipelineorder.pipelines", "name", "pipelines"), + "datadog_logs_pipeline_order.pipelines", "name", "pipelines"), resource.TestCheckResourceAttr( - "datadog_logs_pipelineorder.pipelines", "pipelines.#", "5"), + "datadog_logs_pipeline_order.pipelines", "pipelines.#", "5"), ), }, }, diff --git a/website/datadog.erb b/website/datadog.erb index 987f88418f..0b1b861354 100644 --- a/website/datadog.erb +++ b/website/datadog.erb @@ -13,6 +13,9 @@ > Resources