Skip to content

Commit

Permalink
Merge pull request #495 from skarimo/sherz/logs-custom-pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
gzussa authored May 8, 2020
2 parents 52de2c6 + dd63f6a commit a565234
Show file tree
Hide file tree
Showing 307 changed files with 3,403 additions and 2,395 deletions.
367 changes: 207 additions & 160 deletions datadog/cassettes/TestAccDatadogLogsPipeline_basic.yaml

Large diffs are not rendered by default.

256 changes: 143 additions & 113 deletions datadog/cassettes/TestAccLogsCustomPipeline_importBasic.yaml

Large diffs are not rendered by default.

596 changes: 398 additions & 198 deletions datadog/resource_datadog_logs_custom_pipeline.go

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions datadog/resource_datadog_logs_custom_pipeline_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package datadog

import (
"context"
"fmt"
"strings"
"testing"

datadogV1 "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/zorkian/go-datadog-api"
)

const pipelineConfigForCreation = `
Expand Down Expand Up @@ -273,20 +274,21 @@ func TestAccDatadogLogsPipeline_basic(t *testing.T) {
func testAccCheckPipelineExists(accProvider *schema.Provider) resource.TestCheckFunc {
return func(s *terraform.State) error {
providerConf := accProvider.Meta().(*ProviderConfiguration)
client := providerConf.CommunityClient
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1

if err := pipelineExistsChecker(s, client); err != nil {
if err := pipelineExistsChecker(s, authV1, datadogClientV1); err != nil {
return err
}
return nil
}
}

func pipelineExistsChecker(s *terraform.State, client *datadog.Client) error {
func pipelineExistsChecker(s *terraform.State, authV1 context.Context, datadogClientV1 *datadogV1.APIClient) error {
for _, r := range s.RootModule().Resources {
if r.Type == "datadog_logs_custom_pipeline" {
id := r.Primary.ID
if _, err := client.GetLogsPipeline(id); err != nil {
if _, _, err := datadogClientV1.LogsPipelinesApi.GetLogsPipeline(authV1, id).Execute(); err != nil {
return fmt.Errorf("received an error when retrieving pipeline, (%s)", err)
}
}
Expand All @@ -297,28 +299,29 @@ func pipelineExistsChecker(s *terraform.State, client *datadog.Client) error {
func testAccCheckPipelineDestroy(accProvider *schema.Provider) func(*terraform.State) error {
return func(s *terraform.State) error {
providerConf := accProvider.Meta().(*ProviderConfiguration)
client := providerConf.CommunityClient
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1

if err := pipelineDestroyHelper(s, client); err != nil {
if err := pipelineDestroyHelper(s, authV1, datadogClientV1); err != nil {
return err
}
return nil
}
}

func pipelineDestroyHelper(s *terraform.State, client *datadog.Client) error {
func pipelineDestroyHelper(s *terraform.State, authV1 context.Context, datadogClientV1 *datadogV1.APIClient) error {
for _, r := range s.RootModule().Resources {
if r.Type == "datadog_logs_custom_pipeline" {
id := r.Primary.ID
p, err := client.GetLogsPipeline(id)
p, _, err := datadogClientV1.LogsPipelinesApi.GetLogsPipeline(authV1, id).Execute()

if err != nil {
if strings.Contains(err.Error(), "400 Bad Request") {
continue
}
return fmt.Errorf("received an error when retrieving pipeline, (%s)", err)
}
if p != nil {
if &p != nil {
return fmt.Errorf("pipeline still exists")
}
}
Expand Down
16 changes: 8 additions & 8 deletions datadog/resource_datadog_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,21 @@ func buildMonitorStruct(d *schema.ResourceData) *datadogV1.Monitor {
}

monitorType := datadogV1.MonitorType(d.Get("type").(string))
m := datadogV1.NewMonitor()
m.SetType(monitorType)
m.SetQuery(d.Get("query").(string))
m.SetName(d.Get("name").(string))
m.SetMessage(d.Get("message").(string))
m.SetOptions(o)

if m.GetType() == datadogV1.MONITORTYPE_LOG_ALERT {
if monitorType == datadogV1.MONITORTYPE_LOG_ALERT {
if attr, ok := d.GetOk("enable_logs_sample"); ok {
o.SetEnableLogsSample(attr.(bool))
} else {
o.SetEnableLogsSample(false)
}
}

m := datadogV1.NewMonitor()
m.SetType(monitorType)
m.SetQuery(d.Get("query").(string))
m.SetName(d.Get("name").(string))
m.SetMessage(d.Get("message").(string))
m.SetOptions(o)

tags := make([]string, 0)
if attr, ok := d.GetOk("tags"); ok {
for _, s := range attr.(*schema.Set).List() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/terraform-providers/terraform-provider-datadog

require (
github.com/DataDog/datadog-api-client-go v1.0.0-beta.1
github.com/DataDog/datadog-api-client-go v1.0.0-beta.2
github.com/cenkalti/backoff v2.1.1+incompatible // indirect
github.com/dnaeon/go-vcr v1.0.1
github.com/hashicorp/go-cleanhttp v0.5.1
Expand Down
23 changes: 17 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbf
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/datadog-api-client-go v1.0.0-beta.1 h1:4X9VgqL0izi6j75TWLwn6wmUDlxOhD1qVufuQ0aTkdA=
github.com/DataDog/datadog-api-client-go v1.0.0-beta.1/go.mod h1:X1aGaD32hd7pc/bi1K3EKj08hmbc/+PP7okMsk3ipDQ=
github.com/DataDog/datadog-api-client-go v1.0.0-beta.2 h1:tav6+lH/q19H4wEuxhkhvN6KRmotqkqIBWuhxGYxk7M=
github.com/DataDog/datadog-api-client-go v1.0.0-beta.2/go.mod h1:ZIerq9SI/pcS9fBjSAe1k68EfexOJrzcp9uiOpJQhrA=
github.com/DataDog/datadog-go v3.6.0+incompatible h1:ILg7c5Y1KvZFDOaVS0higGmJ5Fal5O1KQrkrT9j6dSM=
github.com/DataDog/datadog-go v3.6.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
Expand Down Expand Up @@ -109,8 +111,6 @@ github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8
github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A=
github.com/hashicorp/terraform-json v0.4.0 h1:KNh29iNxozP5adfUFBJ4/fWd0Cu3taGgjHB38JYqOF4=
github.com/hashicorp/terraform-json v0.4.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU=
github.com/hashicorp/terraform-plugin-sdk v1.6.0 h1:Um5hsAL7kKsfTHtan8lybY/d03F2bHu4fjRB1H6Ag4U=
github.com/hashicorp/terraform-plugin-sdk v1.6.0/go.mod h1:H5QLx/uhwfxBZ59Bc5SqT19M4i+fYt7LZjHTpbLZiAg=
github.com/hashicorp/terraform-plugin-sdk v1.10.0 h1:JLV3dUnsAF8TKGUdEPkvl9H0Xb2LdcHxLJyDPZ1A5/U=
github.com/hashicorp/terraform-plugin-sdk v1.10.0/go.mod h1:HiWIPD/T9HixIhQUwaSoDQxo4BLFdmiBi/Qz5gjB8Q0=
github.com/hashicorp/terraform-plugin-test v1.3.0 h1:hU5LoxrOn9qvOo+LTKN6mSav2J+dAMprbdxJPEQvp4U=
Expand Down Expand Up @@ -166,6 +166,10 @@ github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ=
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -179,11 +183,14 @@ github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tinylib/msgp v1.1.2 h1:gWmO7n0Ys2RBEb7GPYB9Ujq8Mk5p2U08lRnmMcGy6BQ=
github.com/tinylib/msgp v1.1.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok=
github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down Expand Up @@ -253,16 +260,18 @@ golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa h1:KIDDMLT1O0Nr7TSxp8xM5tJcdn8tgyAONntO829og1M=
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f h1:gWF768j/LaZugp8dyS4UwsslYCYz9XgFxvlgsn0n9H8=
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down Expand Up @@ -305,6 +314,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk=
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
gopkg.in/DataDog/dd-trace-go.v1 v1.23.1 h1:WwxQG9Sk+kcW/vepd1zFrRZUTzJHoYL/Cl0ArmMlVXo=
gopkg.in/DataDog/dd-trace-go.v1 v1.23.1/go.mod h1:DVp8HmDh8PuTu2Z0fVVlBsyWaC++fzwVCaGWylTe3tg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/DataDog/datadog-api-client-go/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions vendor/github.com/DataDog/datadog-api-client-go/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions vendor/github.com/DataDog/datadog-api-client-go/RELEASING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a565234

Please sign in to comment.