2018-09-24 20:54:33 +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-09-24 20:54:33 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
2018-10-26 18:03:43 +00:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2018-09-24 20:54:33 +00:00
|
|
|
)
|
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func TestAccComputeAutoscaler_autoscalerBasicExample(t *testing.T) {
|
2018-09-24 20:54:33 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2019-01-03 00:44:08 +00:00
|
|
|
context := map[string]interface{}{
|
|
|
|
"random_suffix": acctest.RandString(10),
|
|
|
|
}
|
|
|
|
|
2018-09-24 20:54:33 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeAutoscalerDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2019-01-03 00:44:08 +00:00
|
|
|
Config: testAccComputeAutoscaler_autoscalerBasicExample(context),
|
2018-09-24 20:54:33 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_compute_autoscaler.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-03 00:44:08 +00:00
|
|
|
func testAccComputeAutoscaler_autoscalerBasicExample(context map[string]interface{}) string {
|
|
|
|
return Nprintf(`
|
2018-09-24 20:54:33 +00:00
|
|
|
resource "google_compute_autoscaler" "foobar" {
|
2019-01-03 00:44:08 +00:00
|
|
|
name = "my-autoscaler-%{random_suffix}"
|
2018-09-24 20:54:33 +00:00
|
|
|
zone = "us-central1-f"
|
|
|
|
target = "${google_compute_instance_group_manager.foobar.self_link}"
|
|
|
|
|
2018-12-27 18:14:07 +00:00
|
|
|
autoscaling_policy {
|
2018-09-24 20:54:33 +00:00
|
|
|
max_replicas = 5
|
|
|
|
min_replicas = 1
|
|
|
|
cooldown_period = 60
|
|
|
|
|
|
|
|
cpu_utilization {
|
|
|
|
target = 0.5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
2019-01-03 00:44:08 +00:00
|
|
|
name = "my-instance-template-%{random_suffix}"
|
2018-09-24 20:54:33 +00:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
can_ip_forward = false
|
|
|
|
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
|
|
|
source_image = "${data.google_compute_image.debian_9.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
2018-12-27 15:51:23 +00:00
|
|
|
metadata = {
|
2018-09-24 20:54:33 +00:00
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
service_account {
|
|
|
|
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_target_pool" "foobar" {
|
2019-01-03 00:44:08 +00:00
|
|
|
name = "my-target-pool-%{random_suffix}"
|
2018-09-24 20:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance_group_manager" "foobar" {
|
2019-01-03 00:44:08 +00:00
|
|
|
name = "my-igm-%{random_suffix}"
|
2018-09-24 20:54:33 +00:00
|
|
|
zone = "us-central1-f"
|
|
|
|
|
|
|
|
instance_template = "${google_compute_instance_template.foobar.self_link}"
|
2019-03-05 00:11:03 +00:00
|
|
|
|
2018-09-24 20:54:33 +00:00
|
|
|
target_pools = ["${google_compute_target_pool.foobar.self_link}"]
|
|
|
|
base_instance_name = "foobar"
|
|
|
|
}
|
|
|
|
|
|
|
|
data "google_compute_image" "debian_9" {
|
|
|
|
family = "debian-9"
|
|
|
|
project = "debian-cloud"
|
|
|
|
}
|
2019-01-03 00:44:08 +00:00
|
|
|
`, context)
|
2018-09-24 20:54:33 +00:00
|
|
|
}
|
2018-10-26 18:03:43 +00:00
|
|
|
|
|
|
|
func testAccCheckComputeAutoscalerDestroy(s *terraform.State) error {
|
2019-01-03 00:05:38 +00:00
|
|
|
for name, rs := range s.RootModule().Resources {
|
2018-10-26 18:03:43 +00:00
|
|
|
if rs.Type != "google_compute_autoscaler" {
|
|
|
|
continue
|
|
|
|
}
|
2019-01-03 00:05:38 +00:00
|
|
|
if strings.HasPrefix(name, "data.") {
|
|
|
|
continue
|
|
|
|
}
|
2018-10-26 18:03:43 +00:00
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/autoscalers/{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = sendRequest(config, "GET", url, nil)
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("ComputeAutoscaler still exists at %s", url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|