Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tt810 committed Sep 20, 2019
1 parent f868a6a commit fca0943
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 184 deletions.
15 changes: 11 additions & 4 deletions datadog/import_datadog_logs_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
]
}
`
Expand Down
4 changes: 2 additions & 2 deletions datadog/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
290 changes: 153 additions & 137 deletions datadog/resource_datadog_logs_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading

0 comments on commit fca0943

Please sign in to comment.