provider/google: limit hardcoded test resource names
This commit is contained in:
parent
96976222bb
commit
9a0ecd05eb
|
@ -12,6 +12,8 @@ import (
|
|||
|
||||
func TestAccComputeFirewall_basic(t *testing.T) {
|
||||
var firewall compute.Firewall
|
||||
networkName := fmt.Sprintf("firewall-test-%s", acctest.RandString(10))
|
||||
firewallName := fmt.Sprintf("firewall-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -19,7 +21,7 @@ func TestAccComputeFirewall_basic(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeFirewallDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeFirewall_basic,
|
||||
Config: testAccComputeFirewall_basic(networkName, firewallName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeFirewallExists(
|
||||
"google_compute_firewall.foobar", &firewall),
|
||||
|
@ -31,6 +33,8 @@ func TestAccComputeFirewall_basic(t *testing.T) {
|
|||
|
||||
func TestAccComputeFirewall_update(t *testing.T) {
|
||||
var firewall compute.Firewall
|
||||
networkName := fmt.Sprintf("firewall-test-%s", acctest.RandString(10))
|
||||
firewallName := fmt.Sprintf("firewall-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -38,14 +42,14 @@ func TestAccComputeFirewall_update(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeFirewallDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeFirewall_basic,
|
||||
Config: testAccComputeFirewall_basic(networkName, firewallName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeFirewallExists(
|
||||
"google_compute_firewall.foobar", &firewall),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccComputeFirewall_update,
|
||||
Config: testAccComputeFirewall_update(networkName, firewallName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeFirewallExists(
|
||||
"google_compute_firewall.foobar", &firewall),
|
||||
|
@ -119,7 +123,8 @@ func testAccCheckComputeFirewallPorts(
|
|||
}
|
||||
}
|
||||
|
||||
var testAccComputeFirewall_basic = fmt.Sprintf(`
|
||||
func testAccComputeFirewall_basic(network, firewall string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_network" "foobar" {
|
||||
name = "firewall-test-%s"
|
||||
ipv4_range = "10.0.0.0/16"
|
||||
|
@ -134,9 +139,11 @@ resource "google_compute_firewall" "foobar" {
|
|||
allow {
|
||||
protocol = "icmp"
|
||||
}
|
||||
}`, acctest.RandString(10), acctest.RandString(10))
|
||||
}`, network, firewall)
|
||||
}
|
||||
|
||||
var testAccComputeFirewall_update = fmt.Sprintf(`
|
||||
func testAccComputeFirewall_update(network, firewall string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_network" "foobar" {
|
||||
name = "firewall-test-%s"
|
||||
ipv4_range = "10.0.0.0/16"
|
||||
|
@ -152,4 +159,5 @@ resource "google_compute_firewall" "foobar" {
|
|||
protocol = "tcp"
|
||||
ports = ["80-255"]
|
||||
}
|
||||
}`, acctest.RandString(10), acctest.RandString(10))
|
||||
}`, network, firewall)
|
||||
}
|
||||
|
|
|
@ -10,13 +10,20 @@ import (
|
|||
)
|
||||
|
||||
func TestAccComputeGlobalForwardingRule_basic(t *testing.T) {
|
||||
fr := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
proxy1 := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
proxy2 := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
backend := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
hc := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
urlmap := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeGlobalForwardingRule_basic1,
|
||||
Config: testAccComputeGlobalForwardingRule_basic1(fr, proxy1, proxy2, backend, hc, urlmap),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeGlobalForwardingRuleExists(
|
||||
"google_compute_global_forwarding_rule.foobar"),
|
||||
|
@ -27,13 +34,20 @@ func TestAccComputeGlobalForwardingRule_basic(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccComputeGlobalForwardingRule_update(t *testing.T) {
|
||||
fr := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
proxy1 := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
proxy2 := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
backend := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
hc := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
urlmap := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeGlobalForwardingRule_basic1,
|
||||
Config: testAccComputeGlobalForwardingRule_basic1(fr, proxy1, proxy2, backend, hc, urlmap),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeGlobalForwardingRuleExists(
|
||||
"google_compute_global_forwarding_rule.foobar"),
|
||||
|
@ -41,7 +55,7 @@ func TestAccComputeGlobalForwardingRule_update(t *testing.T) {
|
|||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testAccComputeGlobalForwardingRule_basic2,
|
||||
Config: testAccComputeGlobalForwardingRule_basic2(fr, proxy1, proxy2, backend, hc, urlmap),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeGlobalForwardingRuleExists(
|
||||
"google_compute_global_forwarding_rule.foobar"),
|
||||
|
@ -96,41 +110,42 @@ func testAccCheckComputeGlobalForwardingRuleExists(n string) resource.TestCheckF
|
|||
}
|
||||
}
|
||||
|
||||
var testAccComputeGlobalForwardingRule_basic1 = fmt.Sprintf(`
|
||||
func testAccComputeGlobalForwardingRule_basic1(fr, proxy1, proxy2, backend, hc, urlmap string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_global_forwarding_rule" "foobar" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
ip_protocol = "TCP"
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
port_range = "80"
|
||||
target = "${google_compute_target_http_proxy.foobar1.self_link}"
|
||||
}
|
||||
|
||||
resource "google_compute_target_http_proxy" "foobar1" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
url_map = "${google_compute_url_map.foobar.self_link}"
|
||||
}
|
||||
|
||||
resource "google_compute_target_http_proxy" "foobar2" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
url_map = "${google_compute_url_map.foobar.self_link}"
|
||||
}
|
||||
|
||||
resource "google_compute_backend_service" "foobar" {
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
|
||||
}
|
||||
|
||||
resource "google_compute_http_health_check" "zero" {
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
request_path = "/"
|
||||
check_interval_sec = 1
|
||||
timeout_sec = 1
|
||||
}
|
||||
|
||||
resource "google_compute_url_map" "foobar" {
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
default_service = "${google_compute_backend_service.foobar.self_link}"
|
||||
host_rule {
|
||||
hosts = ["mysite.com", "myothersite.com"]
|
||||
|
@ -149,45 +164,45 @@ resource "google_compute_url_map" "foobar" {
|
|||
path = "/*"
|
||||
service = "${google_compute_backend_service.foobar.self_link}"
|
||||
}
|
||||
}`, fr, proxy1, proxy2, backend, hc, urlmap)
|
||||
}
|
||||
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10),
|
||||
acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
||||
|
||||
var testAccComputeGlobalForwardingRule_basic2 = fmt.Sprintf(`
|
||||
func testAccComputeGlobalForwardingRule_basic2(fr, proxy1, proxy2, backend, hc, urlmap string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_global_forwarding_rule" "foobar" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
ip_protocol = "TCP"
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
port_range = "80"
|
||||
target = "${google_compute_target_http_proxy.foobar2.self_link}"
|
||||
}
|
||||
|
||||
resource "google_compute_target_http_proxy" "foobar1" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
url_map = "${google_compute_url_map.foobar.self_link}"
|
||||
}
|
||||
|
||||
resource "google_compute_target_http_proxy" "foobar2" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
url_map = "${google_compute_url_map.foobar.self_link}"
|
||||
}
|
||||
|
||||
resource "google_compute_backend_service" "foobar" {
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
|
||||
}
|
||||
|
||||
resource "google_compute_http_health_check" "zero" {
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
request_path = "/"
|
||||
check_interval_sec = 1
|
||||
timeout_sec = 1
|
||||
}
|
||||
|
||||
resource "google_compute_url_map" "foobar" {
|
||||
name = "gforward-test-%s"
|
||||
name = "%s"
|
||||
default_service = "${google_compute_backend_service.foobar.self_link}"
|
||||
host_rule {
|
||||
hosts = ["mysite.com", "myothersite.com"]
|
||||
|
@ -206,6 +221,5 @@ resource "google_compute_url_map" "foobar" {
|
|||
path = "/*"
|
||||
service = "${google_compute_backend_service.foobar.self_link}"
|
||||
}
|
||||
}`, fr, proxy1, proxy2, backend, hc, urlmap)
|
||||
}
|
||||
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10),
|
||||
acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
||||
|
|
|
@ -14,13 +14,18 @@ import (
|
|||
func TestAccInstanceGroupManager_basic(t *testing.T) {
|
||||
var manager compute.InstanceGroupManager
|
||||
|
||||
template := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
||||
target := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
||||
igm1 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
||||
igm2 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceGroupManager_basic,
|
||||
Config: testAccInstanceGroupManager_basic(template, target, igm1, igm2),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckInstanceGroupManagerExists(
|
||||
"google_compute_instance_group_manager.igm-basic", &manager),
|
||||
|
@ -35,26 +40,31 @@ func TestAccInstanceGroupManager_basic(t *testing.T) {
|
|||
func TestAccInstanceGroupManager_update(t *testing.T) {
|
||||
var manager compute.InstanceGroupManager
|
||||
|
||||
template1 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
||||
target := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
||||
template2 := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
||||
igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceGroupManager_update,
|
||||
Config: testAccInstanceGroupManager_update(template1, target, igm),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckInstanceGroupManagerExists(
|
||||
"google_compute_instance_group_manager.igm-update", &manager),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceGroupManager_update2,
|
||||
Config: testAccInstanceGroupManager_update2(template1, target, template2, igm),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckInstanceGroupManagerExists(
|
||||
"google_compute_instance_group_manager.igm-update", &manager),
|
||||
testAccCheckInstanceGroupManagerUpdated(
|
||||
"google_compute_instance_group_manager.igm-update", 3,
|
||||
"google_compute_target_pool.igm-update", "terraform-test-igm-update2"),
|
||||
"google_compute_target_pool.igm-update", template2),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -147,9 +157,10 @@ func testAccCheckInstanceGroupManagerUpdated(n string, size int64, targetPool st
|
|||
}
|
||||
}
|
||||
|
||||
var testAccInstanceGroupManager_basic = fmt.Sprintf(`
|
||||
func testAccInstanceGroupManager_basic(template, target, igm1, igm2 string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance_template" "igm-basic" {
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
can_ip_forward = false
|
||||
tags = ["foo", "bar"]
|
||||
|
@ -175,13 +186,13 @@ resource "google_compute_instance_template" "igm-basic" {
|
|||
|
||||
resource "google_compute_target_pool" "igm-basic" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
session_affinity = "CLIENT_IP_PROTO"
|
||||
}
|
||||
|
||||
resource "google_compute_instance_group_manager" "igm-basic" {
|
||||
description = "Terraform test instance group manager"
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
instance_template = "${google_compute_instance_template.igm-basic.self_link}"
|
||||
target_pools = ["${google_compute_target_pool.igm-basic.self_link}"]
|
||||
base_instance_name = "igm-basic"
|
||||
|
@ -191,17 +202,19 @@ resource "google_compute_instance_group_manager" "igm-basic" {
|
|||
|
||||
resource "google_compute_instance_group_manager" "igm-no-tp" {
|
||||
description = "Terraform test instance group manager"
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
instance_template = "${google_compute_instance_template.igm-basic.self_link}"
|
||||
base_instance_name = "igm-no-tp"
|
||||
zone = "us-central1-c"
|
||||
target_size = 2
|
||||
}
|
||||
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
||||
`, template, target, igm1, igm2)
|
||||
}
|
||||
|
||||
var testAccInstanceGroupManager_update = fmt.Sprintf(`
|
||||
func testAccInstanceGroupManager_update(template, target, igm string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance_template" "igm-update" {
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
can_ip_forward = false
|
||||
tags = ["foo", "bar"]
|
||||
|
@ -227,24 +240,26 @@ resource "google_compute_instance_template" "igm-update" {
|
|||
|
||||
resource "google_compute_target_pool" "igm-update" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
session_affinity = "CLIENT_IP_PROTO"
|
||||
}
|
||||
|
||||
resource "google_compute_instance_group_manager" "igm-update" {
|
||||
description = "Terraform test instance group manager"
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
instance_template = "${google_compute_instance_template.igm-update.self_link}"
|
||||
target_pools = ["${google_compute_target_pool.igm-update.self_link}"]
|
||||
base_instance_name = "igm-update"
|
||||
zone = "us-central1-c"
|
||||
target_size = 2
|
||||
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
||||
}`, template, target, igm)
|
||||
}
|
||||
|
||||
// Change IGM's instance template and target size
|
||||
var testAccInstanceGroupManager_update2 = fmt.Sprintf(`
|
||||
func testAccInstanceGroupManager_update2(template1, target, template2, igm string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance_template" "igm-update" {
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
can_ip_forward = false
|
||||
tags = ["foo", "bar"]
|
||||
|
@ -270,12 +285,12 @@ resource "google_compute_instance_template" "igm-update" {
|
|||
|
||||
resource "google_compute_target_pool" "igm-update" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
session_affinity = "CLIENT_IP_PROTO"
|
||||
}
|
||||
|
||||
resource "google_compute_instance_template" "igm-update2" {
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
can_ip_forward = false
|
||||
tags = ["foo", "bar"]
|
||||
|
@ -301,10 +316,11 @@ resource "google_compute_instance_template" "igm-update2" {
|
|||
|
||||
resource "google_compute_instance_group_manager" "igm-update" {
|
||||
description = "Terraform test instance group manager"
|
||||
name = "igm-test-%s"
|
||||
name = "%s"
|
||||
instance_template = "${google_compute_instance_template.igm-update2.self_link}"
|
||||
target_pools = ["${google_compute_target_pool.igm-update.self_link}"]
|
||||
base_instance_name = "igm-update"
|
||||
zone = "us-central1-c"
|
||||
target_size = 3
|
||||
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
||||
}`, template1, target, template2, igm)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
func TestAccComputeInstance_basic_deprecated_network(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -20,13 +21,13 @@ func TestAccComputeInstance_basic_deprecated_network(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_basic_deprecated_network,
|
||||
Config: testAccComputeInstance_basic_deprecated_network(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceTag(&instance, "foo"),
|
||||
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
||||
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
||||
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -35,6 +36,7 @@ func TestAccComputeInstance_basic_deprecated_network(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_basic1(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -42,14 +44,14 @@ func TestAccComputeInstance_basic1(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_basic,
|
||||
Config: testAccComputeInstance_basic(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceTag(&instance, "foo"),
|
||||
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
||||
testAccCheckComputeInstanceMetadata(&instance, "baz", "qux"),
|
||||
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
||||
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -58,6 +60,7 @@ func TestAccComputeInstance_basic1(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_basic2(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -65,13 +68,13 @@ func TestAccComputeInstance_basic2(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_basic2,
|
||||
Config: testAccComputeInstance_basic2(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceTag(&instance, "foo"),
|
||||
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
||||
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
||||
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -80,6 +83,7 @@ func TestAccComputeInstance_basic2(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_basic3(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -87,13 +91,13 @@ func TestAccComputeInstance_basic3(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_basic3,
|
||||
Config: testAccComputeInstance_basic3(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceTag(&instance, "foo"),
|
||||
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
||||
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
||||
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -102,6 +106,8 @@ func TestAccComputeInstance_basic3(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_IP(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var ipName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -109,7 +115,7 @@ func TestAccComputeInstance_IP(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_ip,
|
||||
Config: testAccComputeInstance_ip(ipName, instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
|
@ -122,6 +128,8 @@ func TestAccComputeInstance_IP(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_disks(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
var diskName = fmt.Sprintf("instance-testd-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -129,12 +137,12 @@ func TestAccComputeInstance_disks(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_disks,
|
||||
Config: testAccComputeInstance_disks(diskName, instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
||||
testAccCheckComputeInstanceDisk(&instance, "terraform-test-disk", false, false),
|
||||
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
||||
testAccCheckComputeInstanceDisk(&instance, diskName, false, false),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -143,6 +151,7 @@ func TestAccComputeInstance_disks(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_local_ssd(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -150,11 +159,11 @@ func TestAccComputeInstance_local_ssd(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_local_ssd,
|
||||
Config: testAccComputeInstance_local_ssd(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.local-ssd", &instance),
|
||||
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
||||
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -163,6 +172,7 @@ func TestAccComputeInstance_local_ssd(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_update_deprecated_network(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -170,14 +180,14 @@ func TestAccComputeInstance_update_deprecated_network(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_basic_deprecated_network,
|
||||
Config: testAccComputeInstance_basic_deprecated_network(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_update_deprecated_network,
|
||||
Config: testAccComputeInstance_update_deprecated_network(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
|
@ -192,6 +202,7 @@ func TestAccComputeInstance_update_deprecated_network(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -199,14 +210,14 @@ func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_basic,
|
||||
Config: testAccComputeInstance_basic(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_forceNewAndChangeMetadata,
|
||||
Config: testAccComputeInstance_forceNewAndChangeMetadata(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
|
@ -220,6 +231,7 @@ func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_update(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -227,14 +239,14 @@ func TestAccComputeInstance_update(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_basic,
|
||||
Config: testAccComputeInstance_basic(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_update,
|
||||
Config: testAccComputeInstance_update(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
|
@ -250,6 +262,7 @@ func TestAccComputeInstance_update(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_service_account(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -257,7 +270,7 @@ func TestAccComputeInstance_service_account(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_service_account,
|
||||
Config: testAccComputeInstance_service_account(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
|
@ -275,6 +288,7 @@ func TestAccComputeInstance_service_account(t *testing.T) {
|
|||
|
||||
func TestAccComputeInstance_scheduling(t *testing.T) {
|
||||
var instance compute.Instance
|
||||
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -282,7 +296,7 @@ func TestAccComputeInstance_scheduling(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstance_scheduling,
|
||||
Config: testAccComputeInstance_scheduling(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceExists(
|
||||
"google_compute_instance.foobar", &instance),
|
||||
|
@ -437,9 +451,10 @@ func testAccCheckComputeInstanceServiceAccount(instance *compute.Instance, scope
|
|||
}
|
||||
}
|
||||
|
||||
var testAccComputeInstance_basic_deprecated_network = fmt.Sprintf(`
|
||||
func testAccComputeInstance_basic_deprecated_network(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
can_ip_forward = false
|
||||
|
@ -456,11 +471,13 @@ resource "google_compute_instance" "foobar" {
|
|||
metadata {
|
||||
foo = "bar"
|
||||
}
|
||||
}`, acctest.RandString(10))
|
||||
}`, instance)
|
||||
}
|
||||
|
||||
var testAccComputeInstance_update_deprecated_network = fmt.Sprintf(`
|
||||
func testAccComputeInstance_update_deprecated_network(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
tags = ["baz"]
|
||||
|
@ -476,11 +493,13 @@ resource "google_compute_instance" "foobar" {
|
|||
metadata {
|
||||
bar = "baz"
|
||||
}
|
||||
}`, acctest.RandString(10))
|
||||
}`, instance)
|
||||
}
|
||||
|
||||
var testAccComputeInstance_basic = fmt.Sprintf(`
|
||||
func testAccComputeInstance_basic(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
can_ip_forward = false
|
||||
|
@ -500,11 +519,13 @@ resource "google_compute_instance" "foobar" {
|
|||
}
|
||||
|
||||
metadata_startup_script = "echo Hello"
|
||||
}`, acctest.RandString(10))
|
||||
}`, instance)
|
||||
}
|
||||
|
||||
var testAccComputeInstance_basic2 = fmt.Sprintf(`
|
||||
func testAccComputeInstance_basic2(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
can_ip_forward = false
|
||||
|
@ -522,11 +543,13 @@ resource "google_compute_instance" "foobar" {
|
|||
metadata {
|
||||
foo = "bar"
|
||||
}
|
||||
}`, acctest.RandString(10))
|
||||
}`, instance)
|
||||
}
|
||||
|
||||
var testAccComputeInstance_basic3 = fmt.Sprintf(`
|
||||
func testAccComputeInstance_basic3(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
can_ip_forward = false
|
||||
|
@ -543,13 +566,15 @@ resource "google_compute_instance" "foobar" {
|
|||
metadata {
|
||||
foo = "bar"
|
||||
}
|
||||
}`, acctest.RandString(10))
|
||||
}`, instance)
|
||||
}
|
||||
|
||||
// Update zone to ForceNew, and change metadata k/v entirely
|
||||
// Generates diff mismatch
|
||||
var testAccComputeInstance_forceNewAndChangeMetadata = fmt.Sprintf(`
|
||||
func testAccComputeInstance_forceNewAndChangeMetadata(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
zone = "us-central1-b"
|
||||
|
@ -567,12 +592,14 @@ resource "google_compute_instance" "foobar" {
|
|||
metadata {
|
||||
qux = "true"
|
||||
}
|
||||
}`, acctest.RandString(10))
|
||||
}`, instance)
|
||||
}
|
||||
|
||||
// Update metadata, tags, and network_interface
|
||||
var testAccComputeInstance_update = fmt.Sprintf(`
|
||||
func testAccComputeInstance_update(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
tags = ["baz"]
|
||||
|
@ -589,15 +616,17 @@ resource "google_compute_instance" "foobar" {
|
|||
metadata {
|
||||
bar = "baz"
|
||||
}
|
||||
}`, acctest.RandString(10))
|
||||
}`, instance)
|
||||
}
|
||||
|
||||
var testAccComputeInstance_ip = fmt.Sprintf(`
|
||||
func testAccComputeInstance_ip(ip, instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_address" "foo" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
tags = ["foo", "bar"]
|
||||
|
@ -616,18 +645,20 @@ resource "google_compute_instance" "foobar" {
|
|||
metadata {
|
||||
foo = "bar"
|
||||
}
|
||||
}`, acctest.RandString(10), acctest.RandString(10))
|
||||
}`, ip, instance)
|
||||
}
|
||||
|
||||
var testAccComputeInstance_disks = fmt.Sprintf(`
|
||||
func testAccComputeInstance_disks(disk, instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_disk" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
size = 10
|
||||
type = "pd-ssd"
|
||||
zone = "us-central1-a"
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
|
||||
|
@ -647,11 +678,13 @@ resource "google_compute_instance" "foobar" {
|
|||
metadata {
|
||||
foo = "bar"
|
||||
}
|
||||
}`, acctest.RandString(10), acctest.RandString(10))
|
||||
}`, disk, instance)
|
||||
}
|
||||
|
||||
var testAccComputeInstance_local_ssd = fmt.Sprintf(`
|
||||
func testAccComputeInstance_local_ssd(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "local-ssd" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
|
||||
|
@ -668,11 +701,13 @@ resource "google_compute_instance" "local-ssd" {
|
|||
network = "default"
|
||||
}
|
||||
|
||||
}`, acctest.RandString(10))
|
||||
}`, instance)
|
||||
}
|
||||
|
||||
var testAccComputeInstance_service_account = fmt.Sprintf(`
|
||||
func testAccComputeInstance_service_account(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
|
||||
|
@ -691,11 +726,13 @@ resource "google_compute_instance" "foobar" {
|
|||
"storage-ro",
|
||||
]
|
||||
}
|
||||
}`, acctest.RandString(10))
|
||||
}`, instance)
|
||||
}
|
||||
|
||||
var testAccComputeInstance_scheduling = fmt.Sprintf(`
|
||||
func testAccComputeInstance_scheduling(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
name = "%s"
|
||||
machine_type = "n1-standard-1"
|
||||
zone = "us-central1-a"
|
||||
|
||||
|
@ -709,4 +746,5 @@ resource "google_compute_instance" "foobar" {
|
|||
|
||||
scheduling {
|
||||
}
|
||||
}`, acctest.RandString(10))
|
||||
}`, instance)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,11 @@ import (
|
|||
)
|
||||
|
||||
func TestAccComputeTargetHttpProxy_basic(t *testing.T) {
|
||||
target := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
||||
backend := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
||||
hc := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
||||
urlmap1 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
||||
urlmap2 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -17,7 +22,7 @@ func TestAccComputeTargetHttpProxy_basic(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeTargetHttpProxy_basic1,
|
||||
Config: testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeTargetHttpProxyExists(
|
||||
"google_compute_target_http_proxy.foobar"),
|
||||
|
@ -28,6 +33,11 @@ func TestAccComputeTargetHttpProxy_basic(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccComputeTargetHttpProxy_update(t *testing.T) {
|
||||
target := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
||||
backend := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
||||
hc := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
||||
urlmap1 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
||||
urlmap2 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -35,7 +45,7 @@ func TestAccComputeTargetHttpProxy_update(t *testing.T) {
|
|||
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeTargetHttpProxy_basic1,
|
||||
Config: testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeTargetHttpProxyExists(
|
||||
"google_compute_target_http_proxy.foobar"),
|
||||
|
@ -43,7 +53,7 @@ func TestAccComputeTargetHttpProxy_update(t *testing.T) {
|
|||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testAccComputeTargetHttpProxy_basic2,
|
||||
Config: testAccComputeTargetHttpProxy_basic2(target, backend, hc, urlmap1, urlmap2),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeTargetHttpProxyExists(
|
||||
"google_compute_target_http_proxy.foobar"),
|
||||
|
@ -98,27 +108,28 @@ func testAccCheckComputeTargetHttpProxyExists(n string) resource.TestCheckFunc {
|
|||
}
|
||||
}
|
||||
|
||||
var testAccComputeTargetHttpProxy_basic1 = fmt.Sprintf(`
|
||||
func testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2 string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_target_http_proxy" "foobar" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
name = "httpproxy-test-%s"
|
||||
name = "%s"
|
||||
url_map = "${google_compute_url_map.foobar1.self_link}"
|
||||
}
|
||||
|
||||
resource "google_compute_backend_service" "foobar" {
|
||||
name = "httpproxy-test-%s"
|
||||
name = "%s"
|
||||
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
|
||||
}
|
||||
|
||||
resource "google_compute_http_health_check" "zero" {
|
||||
name = "httpproxy-test-%s"
|
||||
name = "%s"
|
||||
request_path = "/"
|
||||
check_interval_sec = 1
|
||||
timeout_sec = 1
|
||||
}
|
||||
|
||||
resource "google_compute_url_map" "foobar1" {
|
||||
name = "httpproxy-test-%s"
|
||||
name = "%s"
|
||||
default_service = "${google_compute_backend_service.foobar.self_link}"
|
||||
host_rule {
|
||||
hosts = ["mysite.com", "myothersite.com"]
|
||||
|
@ -140,7 +151,7 @@ resource "google_compute_url_map" "foobar1" {
|
|||
}
|
||||
|
||||
resource "google_compute_url_map" "foobar2" {
|
||||
name = "httpproxy-test-%s"
|
||||
name = "%s"
|
||||
default_service = "${google_compute_backend_service.foobar.self_link}"
|
||||
host_rule {
|
||||
hosts = ["mysite.com", "myothersite.com"]
|
||||
|
@ -160,29 +171,31 @@ resource "google_compute_url_map" "foobar2" {
|
|||
service = "${google_compute_backend_service.foobar.self_link}"
|
||||
}
|
||||
}
|
||||
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
||||
`, target, backend, hc, urlmap1, urlmap2)
|
||||
}
|
||||
|
||||
var testAccComputeTargetHttpProxy_basic2 = fmt.Sprintf(`
|
||||
func testAccComputeTargetHttpProxy_basic2(target, backend, hc, urlmap1, urlmap2 string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_target_http_proxy" "foobar" {
|
||||
description = "Resource created for Terraform acceptance testing"
|
||||
name = "httpproxy-test-%s"
|
||||
name = "%s"
|
||||
url_map = "${google_compute_url_map.foobar2.self_link}"
|
||||
}
|
||||
|
||||
resource "google_compute_backend_service" "foobar" {
|
||||
name = "httpproxy-test-%s"
|
||||
name = "%s"
|
||||
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
|
||||
}
|
||||
|
||||
resource "google_compute_http_health_check" "zero" {
|
||||
name = "httpproxy-test-%s"
|
||||
name = "%s"
|
||||
request_path = "/"
|
||||
check_interval_sec = 1
|
||||
timeout_sec = 1
|
||||
}
|
||||
|
||||
resource "google_compute_url_map" "foobar1" {
|
||||
name = "httpproxy-test-%s"
|
||||
name = "%s"
|
||||
default_service = "${google_compute_backend_service.foobar.self_link}"
|
||||
host_rule {
|
||||
hosts = ["mysite.com", "myothersite.com"]
|
||||
|
@ -204,7 +217,7 @@ resource "google_compute_url_map" "foobar1" {
|
|||
}
|
||||
|
||||
resource "google_compute_url_map" "foobar2" {
|
||||
name = "httpproxy-test-%s"
|
||||
name = "%s"
|
||||
default_service = "${google_compute_backend_service.foobar.self_link}"
|
||||
host_rule {
|
||||
hosts = ["mysite.com", "myothersite.com"]
|
||||
|
@ -224,4 +237,5 @@ resource "google_compute_url_map" "foobar2" {
|
|||
service = "${google_compute_backend_service.foobar.self_link}"
|
||||
}
|
||||
}
|
||||
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
||||
`, target, backend, hc, urlmap1, urlmap2)
|
||||
}
|
||||
|
|
|
@ -10,16 +10,17 @@ import (
|
|||
)
|
||||
|
||||
func TestAccDnsRecordSet_basic(t *testing.T) {
|
||||
zoneName := fmt.Sprintf("dnszone-test-%s", acctest.RandString(10))
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckDnsRecordSetDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccDnsRecordSet_basic,
|
||||
Config: testAccDnsRecordSet_basic(zoneName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckDnsRecordSetExists(
|
||||
"google_dns_record_set.foobar"),
|
||||
"google_dns_record_set.foobar", zoneName),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -43,11 +44,11 @@ func testAccCheckDnsRecordSetDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func testAccCheckDnsRecordSetExists(name string) resource.TestCheckFunc {
|
||||
func testAccCheckDnsRecordSetExists(resourceType, resourceName string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[name]
|
||||
rs, ok := s.RootModule().Resources[resourceType]
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", name)
|
||||
return fmt.Errorf("Not found: %s", resourceName)
|
||||
}
|
||||
|
||||
dnsName := rs.Primary.Attributes["name"]
|
||||
|
@ -60,7 +61,7 @@ func testAccCheckDnsRecordSetExists(name string) resource.TestCheckFunc {
|
|||
config := testAccProvider.Meta().(*Config)
|
||||
|
||||
resp, err := config.clientDns.ResourceRecordSets.List(
|
||||
config.Project, "terraform-test-zone").Name(dnsName).Type(dnsType).Do()
|
||||
config.Project, resourceName).Name(dnsName).Type(dnsType).Do()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error confirming DNS RecordSet existence: %#v", err)
|
||||
}
|
||||
|
@ -77,9 +78,10 @@ func testAccCheckDnsRecordSetExists(name string) resource.TestCheckFunc {
|
|||
}
|
||||
}
|
||||
|
||||
var testAccDnsRecordSet_basic = fmt.Sprintf(`
|
||||
func testAccDnsRecordSet_basic(zoneName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_dns_managed_zone" "parent-zone" {
|
||||
name = "dnsrecord-test-%s"
|
||||
name = "%s"
|
||||
dns_name = "terraform.test."
|
||||
description = "Test Description"
|
||||
}
|
||||
|
@ -90,4 +92,5 @@ resource "google_dns_record_set" "foobar" {
|
|||
rrdatas = ["127.0.0.1", "127.0.0.10"]
|
||||
ttl = 600
|
||||
}
|
||||
`, acctest.RandString(10))
|
||||
`, zoneName)
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ func testAccGoogleSqlDatabaseDestroy(s *terraform.State) error {
|
|||
|
||||
var testGoogleSqlDatabase_basic = fmt.Sprintf(`
|
||||
resource "google_sql_database_instance" "instance" {
|
||||
name = "sqldatabase-test-%s"
|
||||
name = "sqldatabasetest%s"
|
||||
region = "us-central"
|
||||
settings {
|
||||
tier = "D0"
|
||||
|
@ -109,7 +109,7 @@ resource "google_sql_database_instance" "instance" {
|
|||
}
|
||||
|
||||
resource "google_sql_database" "database" {
|
||||
name = "sqldatabase-test-%s"
|
||||
name = "sqldatabasetest%s"
|
||||
instance = "${google_sql_database_instance.instance.name}"
|
||||
}
|
||||
`, acctest.RandString(10), acctest.RandString(10))
|
||||
|
|
Loading…
Reference in New Issue