diff --git a/datadog/cassettes/TestAccDatadogIpRangesDatasource_existing.yaml b/datadog/cassettes/TestAccDatadogIpRangesDatasource_existing.yaml index 9c97ba6af..d8b429b1a 100644 --- a/datadog/cassettes/TestAccDatadogIpRangesDatasource_existing.yaml +++ b/datadog/cassettes/TestAccDatadogIpRangesDatasource_existing.yaml @@ -5,9 +5,13 @@ interactions: body: "" form: {} headers: + Accept: + - application/json + Dd-Operation-Id: + - GetIPRanges User-Agent: - - Datadog/dev/terraform (go1.13) - url: https://ip-ranges.datadoghq.com + - datadog-api-client-go/1.0.0-beta.1+dev.1 (go go1.13; os darwin; arch amd64) + url: https://ip-ranges.datadoghq.com/ method: GET response: body: | @@ -896,7 +900,7 @@ interactions: Content-Type: - application/json Date: - - Mon, 16 Mar 2020 13:06:39 GMT + - Wed, 29 Apr 2020 14:48:20 GMT Last-Modified: - Wed, 13 Nov 2019 16:02:25 GMT Server: @@ -904,13 +908,13 @@ interactions: Vary: - Accept-Encoding Via: - - 1.1 4ba0e9deb9465045a3261b8712935964.cloudfront.net (CloudFront) + - 1.1 ca58d8de88ffcf8b392312b62a4bdee8.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - QCBZTZhjgjW_j1-W3Z806f3lvOozeahgiwgOnLJwQFtXCQ29Vi743w== + - VSv6DCx272yN05pN1T4_8EDQ84cjNRoNaol0Kfo-uyK0c8DrmVk0ag== X-Amz-Cf-Pop: - - FRA53 + - LHR62-C1 X-Cache: - - Miss from cloudfront + - RefreshHit from cloudfront status: 200 OK code: 200 duration: "" @@ -918,9 +922,13 @@ interactions: body: "" form: {} headers: + Accept: + - application/json + Dd-Operation-Id: + - GetIPRanges User-Agent: - - Datadog/dev/terraform (go1.13) - url: https://ip-ranges.datadoghq.com + - datadog-api-client-go/1.0.0-beta.1+dev.1 (go go1.13; os darwin; arch amd64) + url: https://ip-ranges.datadoghq.com/ method: GET response: body: | @@ -1809,7 +1817,7 @@ interactions: Content-Type: - application/json Date: - - Mon, 16 Mar 2020 13:06:39 GMT + - Wed, 29 Apr 2020 14:48:20 GMT Last-Modified: - Wed, 13 Nov 2019 16:02:25 GMT Server: @@ -1817,11 +1825,11 @@ interactions: Vary: - Accept-Encoding Via: - - 1.1 4ba0e9deb9465045a3261b8712935964.cloudfront.net (CloudFront) + - 1.1 ca58d8de88ffcf8b392312b62a4bdee8.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - fgQILALEBi6ihw8b2gcl8_pBQz-ZB4DbYe5g6PFk55OJfoiyxAu-bA== + - wgnyosYRyRtHxuF1_O0RWZYGZ0ZUO6JHWSd0gEx6qpc_V99oFjyBOA== X-Amz-Cf-Pop: - - FRA53 + - LHR62-C1 X-Cache: - Miss from cloudfront status: 200 OK @@ -1831,9 +1839,13 @@ interactions: body: "" form: {} headers: + Accept: + - application/json + Dd-Operation-Id: + - GetIPRanges User-Agent: - - Datadog/dev/terraform (go1.13) - url: https://ip-ranges.datadoghq.com + - datadog-api-client-go/1.0.0-beta.1+dev.1 (go go1.13; os darwin; arch amd64) + url: https://ip-ranges.datadoghq.com/ method: GET response: body: | @@ -2722,7 +2734,7 @@ interactions: Content-Type: - application/json Date: - - Mon, 16 Mar 2020 13:06:39 GMT + - Wed, 29 Apr 2020 14:48:20 GMT Last-Modified: - Wed, 13 Nov 2019 16:02:25 GMT Server: @@ -2730,11 +2742,11 @@ interactions: Vary: - Accept-Encoding Via: - - 1.1 4ba0e9deb9465045a3261b8712935964.cloudfront.net (CloudFront) + - 1.1 ca58d8de88ffcf8b392312b62a4bdee8.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - 7lYx9adeiE6jQFQVdHr6b5vYDm5GZr94W7QJzNuW-b3KndllfWGphg== + - 1WEoqO7t6NmPiZSQg1blZhNlLjrRbfebr3hPLzYiViIAem_KNgaN6w== X-Amz-Cf-Pop: - - FRA53 + - LHR62-C1 X-Cache: - Hit from cloudfront status: 200 OK @@ -2744,9 +2756,13 @@ interactions: body: "" form: {} headers: + Accept: + - application/json + Dd-Operation-Id: + - GetIPRanges User-Agent: - - Datadog/dev/terraform (go1.13) - url: https://ip-ranges.datadoghq.com + - datadog-api-client-go/1.0.0-beta.1+dev.1 (go go1.13; os darwin; arch amd64) + url: https://ip-ranges.datadoghq.com/ method: GET response: body: | @@ -3630,12 +3646,14 @@ interactions: } } headers: + Age: + - "1" Connection: - keep-alive Content-Type: - application/json Date: - - Mon, 16 Mar 2020 13:06:39 GMT + - Wed, 29 Apr 2020 14:48:20 GMT Last-Modified: - Wed, 13 Nov 2019 16:02:25 GMT Server: @@ -3643,11 +3661,11 @@ interactions: Vary: - Accept-Encoding Via: - - 1.1 4ba0e9deb9465045a3261b8712935964.cloudfront.net (CloudFront) + - 1.1 ca58d8de88ffcf8b392312b62a4bdee8.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - EkPmn1ya1Fe33hvopmAb4tx85OsUU7i--oC4ToUyJ6lWWkoFQDg-QQ== + - 6HKYazpDbjrJywXDef7ooAzHYBt9DATXyx9ebsKauDgYVace07-peQ== X-Amz-Cf-Pop: - - FRA53 + - LHR62-C1 X-Cache: - Hit from cloudfront status: 200 OK diff --git a/datadog/data_source_datadog_ip_ranges.go b/datadog/data_source_datadog_ip_ranges.go index 36a05e05d..99d92c493 100644 --- a/datadog/data_source_datadog_ip_ranges.go +++ b/datadog/data_source_datadog_ip_ranges.go @@ -6,7 +6,7 @@ import ( func dataSourceDatadogIpRanges() *schema.Resource { return &schema.Resource{ - Read: dataSourceDatadogIpRangesRead, + Read: dataSourceDatadogIPRangesRead, // IP ranges are divided between ipv4 and ipv6 Schema: map[string]*schema.Schema{ @@ -86,112 +86,54 @@ func dataSourceDatadogIpRanges() *schema.Resource { } } -func dataSourceDatadogIpRangesRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceDatadogIPRangesRead(d *schema.ResourceData, meta interface{}) error { providerConf := meta.(*ProviderConfiguration) - client := providerConf.CommunityClient + client := providerConf.DatadogClientV1 + auth := providerConf.AuthV1 - ipAddresses, err := client.GetIPRanges() + ipAddresses, _, err := client.IPRangesApi.GetIPRanges(auth).Execute() if err != nil { - return translateClientError(err, "error getting ip range") + return err } // v4 and v6 - if len(ipAddresses.Agents["prefixes_ipv4"])+len(ipAddresses.API["prefixes_ipv4"])+ - len(ipAddresses.Apm["prefixes_ipv4"])+len(ipAddresses.Logs["prefixes_ipv4"])+ - len(ipAddresses.Process["prefixes_ipv4"])+len(ipAddresses.Synthetics["prefixes_ipv4"])+ - len(ipAddresses.Webhooks["prefixes_ipv4"])+len(ipAddresses.Agents["prefixes_ipv6"])+ - len(ipAddresses.API["prefixes_ipv6"])+len(ipAddresses.Apm["prefixes_ipv6"])+ - len(ipAddresses.Logs["prefixes_ipv6"])+len(ipAddresses.Process["prefixes_ipv6"])+ - len(ipAddresses.Synthetics["prefixes_ipv6"])+len(ipAddresses.Webhooks["prefixes_ipv6"]) > 0 { + ipAddressesPtr := &ipAddresses + agents := ipAddressesPtr.GetAgents() + api := ipAddressesPtr.GetAgents() + apm := ipAddressesPtr.GetAgents() + logs := ipAddressesPtr.GetAgents() + process := ipAddressesPtr.GetAgents() + synthetics := ipAddressesPtr.GetAgents() + webhook := ipAddressesPtr.GetAgents() + + if len(agents.GetPrefixesIpv4())+len(api.GetPrefixesIpv4())+ + len(apm.GetPrefixesIpv4())+len(logs.GetPrefixesIpv4())+ + len(process.GetPrefixesIpv4())+len(synthetics.GetPrefixesIpv4())+ + len(webhook.GetPrefixesIpv4())+len(agents.GetPrefixesIpv6())+ + len(api.GetPrefixesIpv6())+len(apm.GetPrefixesIpv6())+ + len(logs.GetPrefixesIpv6())+len(process.GetPrefixesIpv6())+ + len(synthetics.GetPrefixesIpv6())+len(webhook.GetPrefixesIpv6()) > 0 { d.SetId("datadog-ip-ranges") } // Set ranges when the list is not empty // v4 - if len(ipAddresses.Agents["prefixes_ipv4"]) > 0 { - d.Set("agents_ipv4", ipAddresses.Agents["prefixes_ipv4"]) - } else { - d.Set("agents_ipv4", []string{}) - } - - if len(ipAddresses.API["prefixes_ipv4"]) > 0 { - d.Set("api_ipv4", ipAddresses.API["prefixes_ipv4"]) - } else { - d.Set("api_ipv4", []string{}) - } - - if len(ipAddresses.Apm["prefixes_ipv4"]) > 0 { - d.Set("apm_ipv4", ipAddresses.Apm["prefixes_ipv4"]) - } else { - d.Set("apm_ipv4", []string{}) - } - - if len(ipAddresses.Logs["prefixes_ipv4"]) > 0 { - d.Set("logs_ipv4", ipAddresses.Logs["prefixes_ipv4"]) - } else { - d.Set("logs_ipv4", []string{}) - } - - if len(ipAddresses.Process["prefixes_ipv4"]) > 0 { - d.Set("process_ipv4", ipAddresses.Process["prefixes_ipv4"]) - } else { - d.Set("process_ipv4", []string{}) - } - - if len(ipAddresses.Synthetics["prefixes_ipv4"]) > 0 { - d.Set("synthetics_ipv4", ipAddresses.Synthetics["prefixes_ipv4"]) - } else { - d.Set("synthetics_ipv4", []string{}) - } - - if len(ipAddresses.Webhooks["prefixes_ipv4"]) > 0 { - d.Set("webhooks_ipv4", ipAddresses.Webhooks["prefixes_ipv4"]) - } else { - d.Set("webhooks_ipv4", []string{}) - } + d.Set("agents_ipv4", agents.GetPrefixesIpv4()) + d.Set("api_ipv4", api.GetPrefixesIpv4()) + d.Set("apm_ipv4", apm.GetPrefixesIpv4()) + d.Set("logs_ipv4", logs.GetPrefixesIpv4()) + d.Set("process_ipv4", process.GetPrefixesIpv4()) + d.Set("synthetics_ipv4", synthetics.GetPrefixesIpv4()) + d.Set("webhooks_ipv4", webhook.GetPrefixesIpv4()) // v6 - if len(ipAddresses.Agents["prefixes_ipv6"]) > 0 { - d.Set("agents_ipv6", ipAddresses.Agents["prefixes_ipv6"]) - } else { - d.Set("agents_ipv6", []string{}) - } - - if len(ipAddresses.API["prefixes_ipv6"]) > 0 { - d.Set("api_ipv6", ipAddresses.API["prefixes_ipv6"]) - } else { - d.Set("api_ipv6", []string{}) - } - - if len(ipAddresses.Apm["prefixes_ipv6"]) > 0 { - d.Set("apm_ipv6", ipAddresses.Apm["prefixes_ipv6"]) - } else { - d.Set("apm_ipv6", []string{}) - } - - if len(ipAddresses.Logs["prefixes_ipv6"]) > 0 { - d.Set("logs_ipv6", ipAddresses.Logs["prefixes_ipv6"]) - } else { - d.Set("logs_ipv6", []string{}) - } - - if len(ipAddresses.Process["prefixes_ipv6"]) > 0 { - d.Set("process_ipv6", ipAddresses.Process["prefixes_ipv6"]) - } else { - d.Set("process_ipv6", []string{}) - } - - if len(ipAddresses.Synthetics["prefixes_ipv6"]) > 0 { - d.Set("synthetics_ipv6", ipAddresses.Synthetics["prefixes_ipv6"]) - } else { - d.Set("synthetics_ipv6", []string{}) - } - - if len(ipAddresses.Webhooks["prefixes_ipv6"]) > 0 { - d.Set("webhooks_ipv6", ipAddresses.Webhooks["prefixes_ipv6"]) - } else { - d.Set("webhooks_ipv6", []string{}) - } + d.Set("agents_ipv6", agents.GetPrefixesIpv6()) + d.Set("api_ipv6", api.GetPrefixesIpv6()) + d.Set("apm_ipv6", apm.GetPrefixesIpv6()) + d.Set("logs_ipv6", logs.GetPrefixesIpv6()) + d.Set("process_ipv6", process.GetPrefixesIpv6()) + d.Set("synthetics_ipv6", synthetics.GetPrefixesIpv6()) + d.Set("webhooks_ipv6", webhook.GetPrefixesIpv6()) return nil }