mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 00:56:43 +00:00
![Paddy Carver](/assets/img/avatar_default.png)
We had several calls to `d.Set` that returned errors we weren't catching, that turning on the panic flag for the tests caught. This PR addresses them, and fixes the one test that was not safe to run in parallel because it relied on a hardcoded name being unique. This is largely just removing calls to `d.Set` for fields that don't exist in the Schema, fixing how Sets get set, correcting typos, and converting types.
90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
)
|
|
|
|
func TestAccDataSourceRegionInstanceGroup(t *testing.T) {
|
|
t.Parallel()
|
|
name := "acctest-" + acctest.RandString(6)
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccDataSourceRegionInstanceGroup_basic(name),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr("data.google_compute_region_instance_group.data_source", "name", name),
|
|
resource.TestCheckResourceAttr("data.google_compute_region_instance_group.data_source", "project", getTestProjectFromEnv()),
|
|
resource.TestCheckResourceAttr("data.google_compute_region_instance_group.data_source", "instances.#", "10")),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccDataSourceRegionInstanceGroup_basic(instanceManagerName string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_compute_health_check" "autohealing" {
|
|
name = "%s"
|
|
check_interval_sec = 1
|
|
timeout_sec = 1
|
|
healthy_threshold = 2
|
|
unhealthy_threshold = 10
|
|
|
|
http_health_check {
|
|
request_path = "/"
|
|
port = "80"
|
|
}
|
|
}
|
|
|
|
resource "google_compute_target_pool" "foo" {
|
|
name = "%s"
|
|
}
|
|
|
|
data "google_compute_image" "debian" {
|
|
project = "debian-cloud"
|
|
name = "debian-9-stretch-v20171129"
|
|
}
|
|
|
|
resource "google_compute_instance_template" "foo" {
|
|
machine_type = "n1-standard-1"
|
|
disk {
|
|
source_image = "${data.google_compute_image.debian.self_link}"
|
|
}
|
|
network_interface {
|
|
access_config {
|
|
}
|
|
network = "default"
|
|
}
|
|
}
|
|
|
|
resource "google_compute_region_instance_group_manager" "foo" {
|
|
name = "%s"
|
|
base_instance_name = "foo"
|
|
instance_template = "${google_compute_instance_template.foo.self_link}"
|
|
region = "us-central1"
|
|
target_pools = ["${google_compute_target_pool.foo.self_link}"]
|
|
target_size = 10
|
|
|
|
named_port {
|
|
name = "web"
|
|
port = 80
|
|
}
|
|
wait_for_instances = true
|
|
|
|
auto_healing_policies {
|
|
health_check = "${google_compute_health_check.autohealing.self_link}"
|
|
initial_delay_sec = 600
|
|
}
|
|
}
|
|
|
|
data "google_compute_region_instance_group" "data_source" {
|
|
self_link = "${google_compute_region_instance_group_manager.foo.instance_group}"
|
|
}
|
|
`, acctest.RandomWithPrefix("test-rigm-"), acctest.RandomWithPrefix("test-rigm-"), instanceManagerName)
|
|
}
|