Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/GoogleCloudPlatform/terraformer

go 1.24.0

require (
cloud.google.com/go v0.116.0 // indirect
cloud.google.com/go/logging v1.12.0
Expand Down Expand Up @@ -352,7 +353,7 @@ require (
cloud.google.com/go/cloudtasks v1.13.2
cloud.google.com/go/iam v1.2.2
cloud.google.com/go/monitoring v1.21.2
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/bradleyfalzon/ghinstallation/v2 v2.1.0
github.com/manicminer/hamilton v0.44.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,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/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0 h1:3c8yed4lgqTt+oTQ+JNMDo+F4xprBf+O/il4ZC0nRLw=
Expand Down
42 changes: 23 additions & 19 deletions providers/datadog/downtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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))
}

Expand All @@ -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,
)
Expand All @@ -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()))
}
}
}
Expand All @@ -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
}