2018-11-22 00:14:46 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This file is automatically generated by Magic Modules and manual
|
|
|
|
// changes will be clobbered when the file is regenerated.
|
|
|
|
//
|
|
|
|
// Please read more about how to change this file in
|
|
|
|
// .github/CONTRIBUTING.md.
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-01-03 00:05:38 +00:00
|
|
|
"strings"
|
2018-11-22 00:14:46 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2019-01-03 00:44:08 +00:00
|
|
|
context := map[string]interface{}{
|
|
|
|
"random_suffix": acctest.RandString(10),
|
|
|
|
}
|
|
|
|
|
2018-11-22 00:14:46 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2019-01-03 00:44:08 +00:00
|
|
|
Config: testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(context),
|
2018-11-22 00:14:46 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_monitoring_uptime_check_config.http",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-03 00:44:08 +00:00
|
|
|
func testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(context map[string]interface{}) string {
|
|
|
|
return Nprintf(`
|
2018-11-22 00:14:46 +00:00
|
|
|
resource "google_monitoring_uptime_check_config" "http" {
|
2019-01-03 00:44:08 +00:00
|
|
|
display_name = "http-uptime-check-%{random_suffix}"
|
2018-11-22 00:14:46 +00:00
|
|
|
timeout = "60s"
|
|
|
|
|
2018-12-26 23:44:30 +00:00
|
|
|
http_check {
|
2018-11-22 00:14:46 +00:00
|
|
|
path = "/some-path"
|
|
|
|
port = "8010"
|
|
|
|
}
|
|
|
|
|
|
|
|
monitored_resource {
|
|
|
|
type = "uptime_url"
|
|
|
|
labels = {
|
|
|
|
project_id = "example"
|
|
|
|
host = "192.168.1.1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-26 23:44:30 +00:00
|
|
|
content_matchers {
|
2018-11-22 00:14:46 +00:00
|
|
|
content = "example"
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 00:44:08 +00:00
|
|
|
`, context)
|
2018-11-22 00:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2019-01-03 00:44:08 +00:00
|
|
|
context := map[string]interface{}{
|
|
|
|
"random_suffix": acctest.RandString(10),
|
|
|
|
}
|
|
|
|
|
2018-11-22 00:14:46 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2019-01-03 00:44:08 +00:00
|
|
|
Config: testAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(context),
|
2018-11-22 00:14:46 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_monitoring_uptime_check_config.tcp_group",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-03 00:44:08 +00:00
|
|
|
func testAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(context map[string]interface{}) string {
|
|
|
|
return Nprintf(`
|
2018-11-22 00:14:46 +00:00
|
|
|
resource "google_monitoring_uptime_check_config" "tcp_group" {
|
2019-01-03 00:44:08 +00:00
|
|
|
display_name = "tcp-uptime-check-%{random_suffix}"
|
2018-11-22 00:14:46 +00:00
|
|
|
timeout = "60s"
|
|
|
|
|
2018-12-26 23:44:30 +00:00
|
|
|
tcp_check {
|
2018-11-22 00:14:46 +00:00
|
|
|
port = 888
|
|
|
|
}
|
|
|
|
|
|
|
|
resource_group {
|
|
|
|
resource_type = "INSTANCE"
|
|
|
|
group_id = "${google_monitoring_group.check.name}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resource "google_monitoring_group" "check" {
|
2019-01-03 00:44:08 +00:00
|
|
|
display_name = "uptime-check-group-%{random_suffix}"
|
2018-11-22 00:14:46 +00:00
|
|
|
filter = "resource.metadata.name=has_substring(\"foo\")"
|
|
|
|
}
|
2019-01-03 00:44:08 +00:00
|
|
|
`, context)
|
2018-11-22 00:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckMonitoringUptimeCheckConfigDestroy(s *terraform.State) error {
|
2019-01-03 00:05:38 +00:00
|
|
|
for name, rs := range s.RootModule().Resources {
|
2018-11-22 00:14:46 +00:00
|
|
|
if rs.Type != "google_monitoring_uptime_check_config" {
|
|
|
|
continue
|
|
|
|
}
|
2019-01-03 00:05:38 +00:00
|
|
|
if strings.HasPrefix(name, "data.") {
|
|
|
|
continue
|
|
|
|
}
|
2018-11-22 00:14:46 +00:00
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
url, err := replaceVarsForTest(rs, "https://monitoring.googleapis.com/v3/{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = sendRequest(config, "GET", url, nil)
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("MonitoringUptimeCheckConfig still exists at %s", url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|