diff --git a/go.mod b/go.mod index ac705d93b..786244db7 100644 --- a/go.mod +++ b/go.mod @@ -257,7 +257,7 @@ require ( github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.1.0 // indirect github.com/google/jsonapi v1.0.0 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/google/uuid v1.5.0 // indirect github.com/googleapis/gax-go/v2 v2.12.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect @@ -323,7 +323,7 @@ require ( go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.17.0 // indirect golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect - golang.org/x/net v0.15.0 // indirect + golang.org/x/net v0.17.0 // indirect golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/term v0.15.0 // indirect @@ -355,7 +355,7 @@ require ( cloud.google.com/go/cloudtasks v1.10.0 cloud.google.com/go/iam v0.13.0 cloud.google.com/go/monitoring v1.13.0 - github.com/DataDog/datadog-api-client-go/v2 v2.11.0 + github.com/DataDog/datadog-api-client-go/v2 v2.25.0 github.com/Myra-Security-GmbH/myrasec-go/v2 v2.28.0 github.com/manicminer/hamilton v0.44.0 github.com/opalsecurity/opal-go v1.0.19 @@ -376,6 +376,7 @@ require ( github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.5 // indirect github.com/go-openapi/swag v0.19.14 // indirect + github.com/goccy/go-json v0.10.2 // indirect github.com/golang-jwt/jwt/v4 v4.4.3 // indirect github.com/google/gnostic v0.5.7-v3refs // indirect github.com/google/s2a-go v0.1.4 // indirect diff --git a/go.sum b/go.sum index 31eccc180..8b016428b 100644 --- a/go.sum +++ b/go.sum @@ -253,8 +253,8 @@ github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChrisTrenkamp/goxpath v0.0.0-20170922090931-c385f95c6022/go.mod h1:nuWgzSkT5PnyOd+272uUmV0dnAnAn42Mk7PiQC5VzN4= -github.com/DataDog/datadog-api-client-go/v2 v2.11.0 h1:7KCEQ3S90PIH1GcqFHcnwDpNfZbqa2BsiF8OYmLb4Jk= -github.com/DataDog/datadog-api-client-go/v2 v2.11.0/go.mod h1:kntOqXEh1SmjwSDzW/eJkr9kS7EqttvEkelglWtJRbg= +github.com/DataDog/datadog-api-client-go/v2 v2.25.0 h1:9Zq42D6M3U///VDxjx2SS1g+EW55WhZYZFHtzM+cO4k= +github.com/DataDog/datadog-api-client-go/v2 v2.25.0/go.mod h1:QKOu6vscsh87fMY1lHfLEmNSunyXImj8BUaUWJXOehc= github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/IBM-Cloud/bluemix-go v0.0.0-20220624043500-d538cb4fd9be h1:PTW3J9z39tJYnmtdAxi8WvTWQXfkOflTJw6noyjnno4= @@ -770,6 +770,8 @@ github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWe github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gocql/gocql v0.0.0-20210707082121-9a3953d1826d h1:k544nNVphXK4Yt0FTduvOvCfJabEY/DMkdNw0zpCwBE= github.com/gocql/gocql v0.0.0-20210707082121-9a3953d1826d/go.mod h1:3gM2c4D3AnkISwBxGnMMsS8Oy4y2lhbPRsH4xnJrHG8= github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE= @@ -893,8 +895,9 @@ github.com/google/s2a-go v0.1.4/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkj github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= +github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8= github.com/googleapis/enterprise-certificate-proxy v0.1.0/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8= github.com/googleapis/enterprise-certificate-proxy v0.2.0/go.mod h1:8C0jb7/mgJe/9KK8Lm7X9ctZC2t60YyIpYEI16jx0Qg= @@ -1864,8 +1867,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= diff --git a/providers/datadog/downtime.go b/providers/datadog/downtime.go index 289daa853..ae11c23ad 100644 --- a/providers/datadog/downtime.go +++ b/providers/datadog/downtime.go @@ -17,11 +17,8 @@ package datadog import ( "context" "fmt" - "strconv" - "github.com/DataDog/datadog-api-client-go/v2/api/datadog" - "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" - + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" "github.com/GoogleCloudPlatform/terraformer/terraformutils" ) @@ -35,10 +32,10 @@ type DowntimeGenerator struct { DatadogService } -func (g *DowntimeGenerator) createResources(downtimes []datadogV1.Downtime) []terraformutils.Resource { +func (g *DowntimeGenerator) createResources(downtimes []datadogV2.DowntimeResponseData) []terraformutils.Resource { resources := []terraformutils.Resource{} for _, downtime := range downtimes { - resourceName := strconv.FormatInt(downtime.GetId(), 10) + resourceName := downtime.GetId() resources = append(resources, g.createResource(resourceName)) } @@ -48,8 +45,8 @@ func (g *DowntimeGenerator) createResources(downtimes []datadogV1.Downtime) []te func (g *DowntimeGenerator) createResource(downtimeID string) terraformutils.Resource { return terraformutils.NewSimpleResource( downtimeID, - fmt.Sprintf("downtime_%s", downtimeID), - "datadog_downtime", + fmt.Sprintf("downtime_schedule_%s", downtimeID), + "datadog_downtime_schedule", "datadog", DowntimeAllowEmptyValues, ) @@ -61,23 +58,18 @@ func (g *DowntimeGenerator) createResource(downtimeID string) terraformutils.Res func (g *DowntimeGenerator) InitResources() error { datadogClient := g.Args["datadogClient"].(*datadog.APIClient) auth := g.Args["auth"].(context.Context) - api := datadogV1.NewDowntimesApi(datadogClient) + api := datadogV2.NewDowntimesApi(datadogClient) resources := []terraformutils.Resource{} for _, filter := range g.Filter { if filter.FieldPath == "id" && filter.IsApplicable("downtime") { for _, value := range filter.AcceptableValues { - i, err := strconv.ParseInt(value, 10, 64) - if err != nil { - return err - } - - monitor, _, err := api.GetDowntime(auth, i) + downtime, _, err := api.GetDowntime(auth, value) if err != nil { return err } - resources = append(resources, g.createResource(strconv.FormatInt(monitor.GetId(), 10))) + resources = append(resources, g.createResource(downtime.Data.GetId())) } } } @@ -87,10 +79,22 @@ func (g *DowntimeGenerator) InitResources() error { return nil } - downtimes, _, err := api.ListDowntimes(auth) - if err != nil { - return err + var downtimes []datadogV2.DowntimeResponseData + optionalParameters := *datadogV2.NewListDowntimesOptionalParameters() + downtimesChan, _ := api.ListDowntimesWithPagination(auth, + *optionalParameters.WithPageLimit(1000)) + + for { + pageResult, more := <-downtimesChan + if !more { + break + } + if pageResult.Error != nil { + return pageResult.Error + } + downtimes = append(downtimes, pageResult.Item) } + g.Resources = g.createResources(downtimes) return nil }