Skip to content

Commit 8d2e6ff

Browse files
Add monitoring uptime check ips datasource (#3320) (#1912)
* Add monitoring uptime check ips datasource * Remove project * Update third_party/terraform/website/docs/d/datasource_google_monitoring_uptime_check_ips.html.markdown Co-Authored-By: Dana Hoffman <[email protected]> Co-authored-by: Dana Hoffman <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Dana Hoffman <[email protected]>
1 parent 1273877 commit 8d2e6ff

File tree

6 files changed

+146
-0
lines changed

6 files changed

+146
-0
lines changed

.changelog/3320.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-datasource
2+
monitoring: `google_monitoring_uptime_check_ips`
3+
```
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
)
9+
10+
func dataSourceGoogleMonitoringUptimeCheckIps() *schema.Resource {
11+
return &schema.Resource{
12+
Read: dataSourceGoogleMonitoringUptimeCheckIpsRead,
13+
14+
Schema: map[string]*schema.Schema{
15+
"uptime_check_ips": {
16+
Type: schema.TypeList,
17+
Computed: true,
18+
Elem: &schema.Resource{
19+
Schema: map[string]*schema.Schema{
20+
"region": {
21+
Type: schema.TypeString,
22+
Computed: true,
23+
},
24+
"location": {
25+
Type: schema.TypeString,
26+
Computed: true,
27+
},
28+
"ip_address": {
29+
Type: schema.TypeString,
30+
Computed: true,
31+
},
32+
},
33+
},
34+
},
35+
},
36+
}
37+
}
38+
39+
func dataSourceGoogleMonitoringUptimeCheckIpsRead(d *schema.ResourceData, meta interface{}) error {
40+
config := meta.(*Config)
41+
42+
url := "https://monitoring.googleapis.com/v3/uptimeCheckIps"
43+
44+
uptimeCheckIps, err := paginatedListRequest("", url, config, flattenUptimeCheckIpsList)
45+
if err != nil {
46+
return fmt.Errorf("Error retrieving monitoring uptime check ips: %s", err)
47+
}
48+
49+
if err := d.Set("uptime_check_ips", uptimeCheckIps); err != nil {
50+
return fmt.Errorf("Error retrieving monitoring uptime check ips: %s", err)
51+
}
52+
d.SetId(time.Now().UTC().String())
53+
return nil
54+
}
55+
56+
func flattenUptimeCheckIpsList(resp map[string]interface{}) []interface{} {
57+
ipObjList := resp["uptimeCheckIps"].([]interface{})
58+
uptimeCheckIps := make([]interface{}, len(ipObjList))
59+
for i, u := range ipObjList {
60+
ipObj := u.(map[string]interface{})
61+
uptimeCheckIps[i] = map[string]interface{}{
62+
"region": ipObj["region"],
63+
"location": ipObj["location"],
64+
"ip_address": ipObj["ipAddress"],
65+
}
66+
}
67+
return uptimeCheckIps
68+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package google
2+
3+
import (
4+
"regexp"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
8+
)
9+
10+
func TestAccDataSourceGoogleMonitoringUptimeCheckIps_basic(t *testing.T) {
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheck(t) },
13+
Providers: testAccProviders,
14+
Steps: []resource.TestStep{
15+
{
16+
Config: testAccDataSourceGoogleMonitoringUptimeCheckIps_basic,
17+
Check: resource.ComposeTestCheckFunc(
18+
resource.TestMatchResourceAttr("data.google_monitoring_uptime_check_ips.foobar",
19+
"uptime_check_ips.0.ip_address", regexp.MustCompile("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$")),
20+
resource.TestMatchResourceAttr("data.google_monitoring_uptime_check_ips.foobar",
21+
"uptime_check_ips.0.location", regexp.MustCompile("^[A-Z][a-z-]+$")),
22+
resource.TestMatchResourceAttr("data.google_monitoring_uptime_check_ips.foobar",
23+
"uptime_check_ips.0.region", regexp.MustCompile("^[A-Z_]+$")),
24+
),
25+
},
26+
},
27+
})
28+
}
29+
30+
const testAccDataSourceGoogleMonitoringUptimeCheckIps_basic = `
31+
data "google_monitoring_uptime_check_ips" "foobar" {
32+
}
33+
`

google-beta/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ func Provider() terraform.ResourceProvider {
553553
"google_folder": dataSourceGoogleFolder(),
554554
"google_folder_organization_policy": dataSourceGoogleFolderOrganizationPolicy(),
555555
"google_monitoring_notification_channel": dataSourceMonitoringNotificationChannel(),
556+
"google_monitoring_uptime_check_ips": dataSourceGoogleMonitoringUptimeCheckIps(),
556557
"google_netblock_ip_ranges": dataSourceGoogleNetblockIpRanges(),
557558
"google_organization": dataSourceGoogleOrganization(),
558559
"google_project": dataSourceGoogleProject(),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
subcategory: "Stackdriver Monitoring"
3+
layout: "google"
4+
page_title: "Google: google_monitoring_uptime_check_ips"
5+
sidebar_current: "docs-google-datasource-google-monitoring-uptime-check-ips"
6+
description: |-
7+
Returns the list of IP addresses Stackdriver Monitoring uses for uptime checking.
8+
---
9+
10+
# google\_monitoring\_uptime\_check\_ips
11+
12+
Returns the list of IP addresses that checkers run from. For more information see
13+
the [official documentation](https://cloud.google.com/monitoring/uptime-checks#get-ips).
14+
15+
## Example Usage
16+
17+
```hcl
18+
data "google_monitoring_uptime_check_ips" "ips" {
19+
}
20+
21+
output "ip_list" {
22+
value = data.google_monitoring_uptime_check_ips.ips.uptime_check_ips
23+
}
24+
```
25+
26+
## Attributes Reference
27+
28+
The following computed attributes are exported:
29+
30+
* `uptime_check_ips` - A list of uptime check IPs used by Stackdriver Monitoring. Each `uptime_check_ip` contains:
31+
* `region` - A broad region category in which the IP address is located.
32+
* `location` - A more specific location within the region that typically encodes a particular city/town/metro
33+
(and its containing state/province or country) within the broader umbrella region category.
34+
* `ip_address` - The IP address from which the Uptime check originates. This is a fully specified IP address
35+
(not an IP address range). Most IP addresses, as of this publication, are in IPv4 format; however, one should not
36+
rely on the IP addresses being in IPv4 format indefinitely, and should support interpreting this field in either
37+
IPv4 or IPv6 format.
38+

website/google.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@
171171
<li<%= sidebar_current("docs-google-datasource-monitoring-notification-channel") %>>
172172
<a href="/docs/providers/google/d/datasource_monitoring_notification_channel.html">google_monitoring_notification_channel</a>
173173
</li>
174+
<li<%= sidebar_current("docs-google-datasource-google-monitoring-uptime-check-ips") %>>
175+
<a href="/docs/providers/google/d/datasource_google_monitoring_uptime_check_ips.html">google_monitoring_uptime_check_ips</a>
176+
</li>
174177
<li<%= sidebar_current("docs-google-datasource-netblock-ip-ranges") %>>
175178
<a href="/docs/providers/google/d/datasource_google_netblock_ip_ranges.html">google_netblock_ip_ranges</a>
176179
</li>

0 commit comments

Comments
 (0)