-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 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]>
- Loading branch information
1 parent
c737a36
commit 36b2cc5
Showing
6 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-datasource | ||
monitoring: `google_monitoring_uptime_check_ips` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceGoogleMonitoringUptimeCheckIps() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceGoogleMonitoringUptimeCheckIpsRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"uptime_check_ips": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"region": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"location": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ip_address": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceGoogleMonitoringUptimeCheckIpsRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
url := "https://monitoring.googleapis.com/v3/uptimeCheckIps" | ||
|
||
uptimeCheckIps, err := paginatedListRequest("", url, config, flattenUptimeCheckIpsList) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving monitoring uptime check ips: %s", err) | ||
} | ||
|
||
if err := d.Set("uptime_check_ips", uptimeCheckIps); err != nil { | ||
return fmt.Errorf("Error retrieving monitoring uptime check ips: %s", err) | ||
} | ||
d.SetId(time.Now().UTC().String()) | ||
return nil | ||
} | ||
|
||
func flattenUptimeCheckIpsList(resp map[string]interface{}) []interface{} { | ||
ipObjList := resp["uptimeCheckIps"].([]interface{}) | ||
uptimeCheckIps := make([]interface{}, len(ipObjList)) | ||
for i, u := range ipObjList { | ||
ipObj := u.(map[string]interface{}) | ||
uptimeCheckIps[i] = map[string]interface{}{ | ||
"region": ipObj["region"], | ||
"location": ipObj["location"], | ||
"ip_address": ipObj["ipAddress"], | ||
} | ||
} | ||
return uptimeCheckIps | ||
} |
33 changes: 33 additions & 0 deletions
33
google/data_source_google_monitoring_uptime_check_ips_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package google | ||
|
||
import ( | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceGoogleMonitoringUptimeCheckIps_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleMonitoringUptimeCheckIps_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestMatchResourceAttr("data.google_monitoring_uptime_check_ips.foobar", | ||
"uptime_check_ips.0.ip_address", regexp.MustCompile("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$")), | ||
resource.TestMatchResourceAttr("data.google_monitoring_uptime_check_ips.foobar", | ||
"uptime_check_ips.0.location", regexp.MustCompile("^[A-Z][a-z-]+$")), | ||
resource.TestMatchResourceAttr("data.google_monitoring_uptime_check_ips.foobar", | ||
"uptime_check_ips.0.region", regexp.MustCompile("^[A-Z_]+$")), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccDataSourceGoogleMonitoringUptimeCheckIps_basic = ` | ||
data "google_monitoring_uptime_check_ips" "foobar" { | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
website/docs/d/datasource_google_monitoring_uptime_check_ips.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
subcategory: "Stackdriver Monitoring" | ||
layout: "google" | ||
page_title: "Google: google_monitoring_uptime_check_ips" | ||
sidebar_current: "docs-google-datasource-google-monitoring-uptime-check-ips" | ||
description: |- | ||
Returns the list of IP addresses Stackdriver Monitoring uses for uptime checking. | ||
--- | ||
|
||
# google\_monitoring\_uptime\_check\_ips | ||
|
||
Returns the list of IP addresses that checkers run from. For more information see | ||
the [official documentation](https://cloud.google.com/monitoring/uptime-checks#get-ips). | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "google_monitoring_uptime_check_ips" "ips" { | ||
} | ||
output "ip_list" { | ||
value = data.google_monitoring_uptime_check_ips.ips.uptime_check_ips | ||
} | ||
``` | ||
|
||
## Attributes Reference | ||
|
||
The following computed attributes are exported: | ||
|
||
* `uptime_check_ips` - A list of uptime check IPs used by Stackdriver Monitoring. Each `uptime_check_ip` contains: | ||
* `region` - A broad region category in which the IP address is located. | ||
* `location` - A more specific location within the region that typically encodes a particular city/town/metro | ||
(and its containing state/province or country) within the broader umbrella region category. | ||
* `ip_address` - The IP address from which the Uptime check originates. This is a fully specified IP address | ||
(not an IP address range). Most IP addresses, as of this publication, are in IPv4 format; however, one should not | ||
rely on the IP addresses being in IPv4 format indefinitely, and should support interpreting this field in either | ||
IPv4 or IPv6 format. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters