provider/google: limit hardcoded test resource names

This commit is contained in:
Lars Wander 2016-01-05 19:49:06 -05:00
parent 96976222bb
commit 9a0ecd05eb
7 changed files with 735 additions and 642 deletions

View File

@ -12,6 +12,8 @@ import (
func TestAccComputeFirewall_basic(t *testing.T) { func TestAccComputeFirewall_basic(t *testing.T) {
var firewall compute.Firewall 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -19,7 +21,7 @@ func TestAccComputeFirewall_basic(t *testing.T) {
CheckDestroy: testAccCheckComputeFirewallDestroy, CheckDestroy: testAccCheckComputeFirewallDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeFirewall_basic, Config: testAccComputeFirewall_basic(networkName, firewallName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeFirewallExists( testAccCheckComputeFirewallExists(
"google_compute_firewall.foobar", &firewall), "google_compute_firewall.foobar", &firewall),
@ -31,6 +33,8 @@ func TestAccComputeFirewall_basic(t *testing.T) {
func TestAccComputeFirewall_update(t *testing.T) { func TestAccComputeFirewall_update(t *testing.T) {
var firewall compute.Firewall 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -38,14 +42,14 @@ func TestAccComputeFirewall_update(t *testing.T) {
CheckDestroy: testAccCheckComputeFirewallDestroy, CheckDestroy: testAccCheckComputeFirewallDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeFirewall_basic, Config: testAccComputeFirewall_basic(networkName, firewallName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeFirewallExists( testAccCheckComputeFirewallExists(
"google_compute_firewall.foobar", &firewall), "google_compute_firewall.foobar", &firewall),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccComputeFirewall_update, Config: testAccComputeFirewall_update(networkName, firewallName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeFirewallExists( testAccCheckComputeFirewallExists(
"google_compute_firewall.foobar", &firewall), "google_compute_firewall.foobar", &firewall),
@ -119,37 +123,41 @@ func testAccCheckComputeFirewallPorts(
} }
} }
var testAccComputeFirewall_basic = fmt.Sprintf(` func testAccComputeFirewall_basic(network, firewall string) string {
resource "google_compute_network" "foobar" { return fmt.Sprintf(`
name = "firewall-test-%s" resource "google_compute_network" "foobar" {
ipv4_range = "10.0.0.0/16" name = "firewall-test-%s"
ipv4_range = "10.0.0.0/16"
}
resource "google_compute_firewall" "foobar" {
name = "firewall-test-%s"
description = "Resource created for Terraform acceptance testing"
network = "${google_compute_network.foobar.name}"
source_tags = ["foo"]
allow {
protocol = "icmp"
}
}`, network, firewall)
} }
resource "google_compute_firewall" "foobar" { func testAccComputeFirewall_update(network, firewall string) string {
name = "firewall-test-%s" return fmt.Sprintf(`
description = "Resource created for Terraform acceptance testing" resource "google_compute_network" "foobar" {
network = "${google_compute_network.foobar.name}" name = "firewall-test-%s"
source_tags = ["foo"] ipv4_range = "10.0.0.0/16"
allow {
protocol = "icmp"
} }
}`, acctest.RandString(10), acctest.RandString(10))
var testAccComputeFirewall_update = fmt.Sprintf(` resource "google_compute_firewall" "foobar" {
resource "google_compute_network" "foobar" { name = "firewall-test-%s"
name = "firewall-test-%s" description = "Resource created for Terraform acceptance testing"
ipv4_range = "10.0.0.0/16" network = "${google_compute_network.foobar.name}"
source_tags = ["foo"]
allow {
protocol = "tcp"
ports = ["80-255"]
}
}`, network, firewall)
} }
resource "google_compute_firewall" "foobar" {
name = "firewall-test-%s"
description = "Resource created for Terraform acceptance testing"
network = "${google_compute_network.foobar.name}"
source_tags = ["foo"]
allow {
protocol = "tcp"
ports = ["80-255"]
}
}`, acctest.RandString(10), acctest.RandString(10))

View File

@ -10,13 +10,20 @@ import (
) )
func TestAccComputeGlobalForwardingRule_basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroy, CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeGlobalForwardingRule_basic1, Config: testAccComputeGlobalForwardingRule_basic1(fr, proxy1, proxy2, backend, hc, urlmap),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeGlobalForwardingRuleExists( testAccCheckComputeGlobalForwardingRuleExists(
"google_compute_global_forwarding_rule.foobar"), "google_compute_global_forwarding_rule.foobar"),
@ -27,13 +34,20 @@ func TestAccComputeGlobalForwardingRule_basic(t *testing.T) {
} }
func TestAccComputeGlobalForwardingRule_update(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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroy, CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeGlobalForwardingRule_basic1, Config: testAccComputeGlobalForwardingRule_basic1(fr, proxy1, proxy2, backend, hc, urlmap),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeGlobalForwardingRuleExists( testAccCheckComputeGlobalForwardingRuleExists(
"google_compute_global_forwarding_rule.foobar"), "google_compute_global_forwarding_rule.foobar"),
@ -41,7 +55,7 @@ func TestAccComputeGlobalForwardingRule_update(t *testing.T) {
}, },
resource.TestStep{ resource.TestStep{
Config: testAccComputeGlobalForwardingRule_basic2, Config: testAccComputeGlobalForwardingRule_basic2(fr, proxy1, proxy2, backend, hc, urlmap),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeGlobalForwardingRuleExists( testAccCheckComputeGlobalForwardingRuleExists(
"google_compute_global_forwarding_rule.foobar"), "google_compute_global_forwarding_rule.foobar"),
@ -96,116 +110,116 @@ func testAccCheckComputeGlobalForwardingRuleExists(n string) resource.TestCheckF
} }
} }
var testAccComputeGlobalForwardingRule_basic1 = fmt.Sprintf(` func testAccComputeGlobalForwardingRule_basic1(fr, proxy1, proxy2, backend, hc, urlmap string) string {
resource "google_compute_global_forwarding_rule" "foobar" { return fmt.Sprintf(`
description = "Resource created for Terraform acceptance testing" resource "google_compute_global_forwarding_rule" "foobar" {
ip_protocol = "TCP" description = "Resource created for Terraform acceptance testing"
name = "gforward-test-%s" ip_protocol = "TCP"
port_range = "80" name = "%s"
target = "${google_compute_target_http_proxy.foobar1.self_link}" 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"
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"
url_map = "${google_compute_url_map.foobar.self_link}"
}
resource "google_compute_backend_service" "foobar" {
name = "gforward-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "gforward-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "gforward-test-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "boop"
} }
path_matcher {
resource "google_compute_target_http_proxy" "foobar1" {
description = "Resource created for Terraform acceptance testing"
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 = "%s"
url_map = "${google_compute_url_map.foobar.self_link}"
}
resource "google_compute_backend_service" "foobar" {
name = "%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "%s"
default_service = "${google_compute_backend_service.foobar.self_link}" default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop" host_rule {
path_rule { hosts = ["mysite.com", "myothersite.com"]
paths = ["/*"] path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}" service = "${google_compute_backend_service.foobar.self_link}"
} }
}`, fr, proxy1, proxy2, backend, hc, urlmap)
}
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 = "%s"
port_range = "80"
target = "${google_compute_target_http_proxy.foobar2.self_link}"
} }
test {
host = "mysite.com" resource "google_compute_target_http_proxy" "foobar1" {
path = "/*" description = "Resource created for Terraform acceptance testing"
service = "${google_compute_backend_service.foobar.self_link}" name = "%s"
url_map = "${google_compute_url_map.foobar.self_link}"
} }
}
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10),
acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
var testAccComputeGlobalForwardingRule_basic2 = fmt.Sprintf(` resource "google_compute_target_http_proxy" "foobar2" {
resource "google_compute_global_forwarding_rule" "foobar" { description = "Resource created for Terraform acceptance testing"
description = "Resource created for Terraform acceptance testing" name = "%s"
ip_protocol = "TCP" url_map = "${google_compute_url_map.foobar.self_link}"
name = "gforward-test-%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"
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"
url_map = "${google_compute_url_map.foobar.self_link}"
}
resource "google_compute_backend_service" "foobar" {
name = "gforward-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "gforward-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "gforward-test-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "boop"
} }
path_matcher {
resource "google_compute_backend_service" "foobar" {
name = "%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "%s"
default_service = "${google_compute_backend_service.foobar.self_link}" default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop" host_rule {
path_rule { hosts = ["mysite.com", "myothersite.com"]
paths = ["/*"] path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}" service = "${google_compute_backend_service.foobar.self_link}"
} }
} }`, fr, proxy1, proxy2, backend, hc, urlmap)
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}"
}
} }
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10),
acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))

View File

@ -14,13 +14,18 @@ import (
func TestAccInstanceGroupManager_basic(t *testing.T) { func TestAccInstanceGroupManager_basic(t *testing.T) {
var manager compute.InstanceGroupManager 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceGroupManagerDestroy, CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccInstanceGroupManager_basic, Config: testAccInstanceGroupManager_basic(template, target, igm1, igm2),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceGroupManagerExists( testAccCheckInstanceGroupManagerExists(
"google_compute_instance_group_manager.igm-basic", &manager), "google_compute_instance_group_manager.igm-basic", &manager),
@ -35,26 +40,31 @@ func TestAccInstanceGroupManager_basic(t *testing.T) {
func TestAccInstanceGroupManager_update(t *testing.T) { func TestAccInstanceGroupManager_update(t *testing.T) {
var manager compute.InstanceGroupManager 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceGroupManagerDestroy, CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccInstanceGroupManager_update, Config: testAccInstanceGroupManager_update(template1, target, igm),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceGroupManagerExists( testAccCheckInstanceGroupManagerExists(
"google_compute_instance_group_manager.igm-update", &manager), "google_compute_instance_group_manager.igm-update", &manager),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccInstanceGroupManager_update2, Config: testAccInstanceGroupManager_update2(template1, target, template2, igm),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceGroupManagerExists( testAccCheckInstanceGroupManagerExists(
"google_compute_instance_group_manager.igm-update", &manager), "google_compute_instance_group_manager.igm-update", &manager),
testAccCheckInstanceGroupManagerUpdated( testAccCheckInstanceGroupManagerUpdated(
"google_compute_instance_group_manager.igm-update", 3, "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,164 +157,170 @@ func testAccCheckInstanceGroupManagerUpdated(n string, size int64, targetPool st
} }
} }
var testAccInstanceGroupManager_basic = fmt.Sprintf(` func testAccInstanceGroupManager_basic(template, target, igm1, igm2 string) string {
resource "google_compute_instance_template" "igm-basic" { return fmt.Sprintf(`
name = "igm-test-%s" resource "google_compute_instance_template" "igm-basic" {
machine_type = "n1-standard-1" name = "%s"
can_ip_forward = false machine_type = "n1-standard-1"
tags = ["foo", "bar"] can_ip_forward = false
tags = ["foo", "bar"]
disk { disk {
source_image = "debian-cloud/debian-7-wheezy-v20140814" source_image = "debian-cloud/debian-7-wheezy-v20140814"
auto_delete = true auto_delete = true
boot = true boot = true
}
network_interface {
network = "default"
}
metadata {
foo = "bar"
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
} }
network_interface { resource "google_compute_target_pool" "igm-basic" {
network = "default" description = "Resource created for Terraform acceptance testing"
name = "%s"
session_affinity = "CLIENT_IP_PROTO"
} }
metadata { resource "google_compute_instance_group_manager" "igm-basic" {
foo = "bar" description = "Terraform test instance group manager"
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"
zone = "us-central1-c"
target_size = 2
} }
service_account { resource "google_compute_instance_group_manager" "igm-no-tp" {
scopes = ["userinfo-email", "compute-ro", "storage-ro"] description = "Terraform test instance group manager"
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
} }
`, template, target, igm1, igm2)
} }
resource "google_compute_target_pool" "igm-basic" { func testAccInstanceGroupManager_update(template, target, igm string) string {
description = "Resource created for Terraform acceptance testing" return fmt.Sprintf(`
name = "igm-test-%s" resource "google_compute_instance_template" "igm-update" {
session_affinity = "CLIENT_IP_PROTO" name = "%s"
} machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
resource "google_compute_instance_group_manager" "igm-basic" { disk {
description = "Terraform test instance group manager" source_image = "debian-cloud/debian-7-wheezy-v20140814"
name = "igm-test-%s" auto_delete = true
instance_template = "${google_compute_instance_template.igm-basic.self_link}" boot = true
target_pools = ["${google_compute_target_pool.igm-basic.self_link}"] }
base_instance_name = "igm-basic"
zone = "us-central1-c"
target_size = 2
}
resource "google_compute_instance_group_manager" "igm-no-tp" { network_interface {
description = "Terraform test instance group manager" network = "default"
name = "igm-test-%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))
var testAccInstanceGroupManager_update = fmt.Sprintf(` metadata {
resource "google_compute_instance_template" "igm-update" { foo = "bar"
name = "igm-test-%s" }
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk { service_account {
source_image = "debian-cloud/debian-7-wheezy-v20140814" scopes = ["userinfo-email", "compute-ro", "storage-ro"]
auto_delete = true }
boot = true
} }
network_interface { resource "google_compute_target_pool" "igm-update" {
network = "default" description = "Resource created for Terraform acceptance testing"
name = "%s"
session_affinity = "CLIENT_IP_PROTO"
} }
metadata { resource "google_compute_instance_group_manager" "igm-update" {
foo = "bar" description = "Terraform test instance group manager"
} name = "%s"
instance_template = "${google_compute_instance_template.igm-update.self_link}"
service_account { target_pools = ["${google_compute_target_pool.igm-update.self_link}"]
scopes = ["userinfo-email", "compute-ro", "storage-ro"] base_instance_name = "igm-update"
} zone = "us-central1-c"
target_size = 2
}`, template, target, igm)
} }
resource "google_compute_target_pool" "igm-update" {
description = "Resource created for Terraform acceptance testing"
name = "igm-test-%s"
session_affinity = "CLIENT_IP_PROTO"
}
resource "google_compute_instance_group_manager" "igm-update" {
description = "Terraform test instance group manager"
name = "igm-test-%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))
// Change IGM's instance template and target size // Change IGM's instance template and target size
var testAccInstanceGroupManager_update2 = fmt.Sprintf(` func testAccInstanceGroupManager_update2(template1, target, template2, igm string) string {
resource "google_compute_instance_template" "igm-update" { return fmt.Sprintf(`
name = "igm-test-%s" resource "google_compute_instance_template" "igm-update" {
machine_type = "n1-standard-1" name = "%s"
can_ip_forward = false machine_type = "n1-standard-1"
tags = ["foo", "bar"] can_ip_forward = false
tags = ["foo", "bar"]
disk { disk {
source_image = "debian-cloud/debian-7-wheezy-v20140814" source_image = "debian-cloud/debian-7-wheezy-v20140814"
auto_delete = true auto_delete = true
boot = true boot = true
}
network_interface {
network = "default"
}
metadata {
foo = "bar"
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
} }
network_interface { resource "google_compute_target_pool" "igm-update" {
network = "default" description = "Resource created for Terraform acceptance testing"
name = "%s"
session_affinity = "CLIENT_IP_PROTO"
} }
metadata { resource "google_compute_instance_template" "igm-update2" {
foo = "bar" name = "%s"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
source_image = "debian-cloud/debian-7-wheezy-v20140814"
auto_delete = true
boot = true
}
network_interface {
network = "default"
}
metadata {
foo = "bar"
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
} }
service_account { resource "google_compute_instance_group_manager" "igm-update" {
scopes = ["userinfo-email", "compute-ro", "storage-ro"] description = "Terraform test instance group manager"
} 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
}`, template1, target, template2, igm)
} }
resource "google_compute_target_pool" "igm-update" {
description = "Resource created for Terraform acceptance testing"
name = "igm-test-%s"
session_affinity = "CLIENT_IP_PROTO"
}
resource "google_compute_instance_template" "igm-update2" {
name = "igm-test-%s"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
source_image = "debian-cloud/debian-7-wheezy-v20140814"
auto_delete = true
boot = true
}
network_interface {
network = "default"
}
metadata {
foo = "bar"
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}
resource "google_compute_instance_group_manager" "igm-update" {
description = "Terraform test instance group manager"
name = "igm-test-%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))

View File

@ -13,6 +13,7 @@ import (
func TestAccComputeInstance_basic_deprecated_network(t *testing.T) { func TestAccComputeInstance_basic_deprecated_network(t *testing.T) {
var instance compute.Instance var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -20,13 +21,13 @@ func TestAccComputeInstance_basic_deprecated_network(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_basic_deprecated_network, Config: testAccComputeInstance_basic_deprecated_network(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceTag(&instance, "foo"), testAccCheckComputeInstanceTag(&instance, "foo"),
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"), 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) { func TestAccComputeInstance_basic1(t *testing.T) {
var instance compute.Instance var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -42,14 +44,14 @@ func TestAccComputeInstance_basic1(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_basic, Config: testAccComputeInstance_basic(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceTag(&instance, "foo"), testAccCheckComputeInstanceTag(&instance, "foo"),
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"), testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
testAccCheckComputeInstanceMetadata(&instance, "baz", "qux"), 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) { func TestAccComputeInstance_basic2(t *testing.T) {
var instance compute.Instance var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -65,13 +68,13 @@ func TestAccComputeInstance_basic2(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_basic2, Config: testAccComputeInstance_basic2(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceTag(&instance, "foo"), testAccCheckComputeInstanceTag(&instance, "foo"),
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"), 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) { func TestAccComputeInstance_basic3(t *testing.T) {
var instance compute.Instance var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -87,13 +91,13 @@ func TestAccComputeInstance_basic3(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_basic3, Config: testAccComputeInstance_basic3(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceTag(&instance, "foo"), testAccCheckComputeInstanceTag(&instance, "foo"),
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"), 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) { func TestAccComputeInstance_IP(t *testing.T) {
var instance compute.Instance 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -109,7 +115,7 @@ func TestAccComputeInstance_IP(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_ip, Config: testAccComputeInstance_ip(ipName, instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
@ -122,6 +128,8 @@ func TestAccComputeInstance_IP(t *testing.T) {
func TestAccComputeInstance_disks(t *testing.T) { func TestAccComputeInstance_disks(t *testing.T) {
var instance compute.Instance 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -129,12 +137,12 @@ func TestAccComputeInstance_disks(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_disks, Config: testAccComputeInstance_disks(diskName, instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true), testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
testAccCheckComputeInstanceDisk(&instance, "terraform-test-disk", false, false), testAccCheckComputeInstanceDisk(&instance, diskName, false, false),
), ),
}, },
}, },
@ -143,6 +151,7 @@ func TestAccComputeInstance_disks(t *testing.T) {
func TestAccComputeInstance_local_ssd(t *testing.T) { func TestAccComputeInstance_local_ssd(t *testing.T) {
var instance compute.Instance var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -150,11 +159,11 @@ func TestAccComputeInstance_local_ssd(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_local_ssd, Config: testAccComputeInstance_local_ssd(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.local-ssd", &instance), "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) { func TestAccComputeInstance_update_deprecated_network(t *testing.T) {
var instance compute.Instance var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -170,14 +180,14 @@ func TestAccComputeInstance_update_deprecated_network(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_basic_deprecated_network, Config: testAccComputeInstance_basic_deprecated_network(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_update_deprecated_network, Config: testAccComputeInstance_update_deprecated_network(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
@ -192,6 +202,7 @@ func TestAccComputeInstance_update_deprecated_network(t *testing.T) {
func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) { func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) {
var instance compute.Instance var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -199,14 +210,14 @@ func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_basic, Config: testAccComputeInstance_basic(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_forceNewAndChangeMetadata, Config: testAccComputeInstance_forceNewAndChangeMetadata(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
@ -220,6 +231,7 @@ func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) {
func TestAccComputeInstance_update(t *testing.T) { func TestAccComputeInstance_update(t *testing.T) {
var instance compute.Instance var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -227,14 +239,14 @@ func TestAccComputeInstance_update(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_basic, Config: testAccComputeInstance_basic(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_update, Config: testAccComputeInstance_update(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
@ -250,6 +262,7 @@ func TestAccComputeInstance_update(t *testing.T) {
func TestAccComputeInstance_service_account(t *testing.T) { func TestAccComputeInstance_service_account(t *testing.T) {
var instance compute.Instance var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -257,7 +270,7 @@ func TestAccComputeInstance_service_account(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_service_account, Config: testAccComputeInstance_service_account(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
@ -275,6 +288,7 @@ func TestAccComputeInstance_service_account(t *testing.T) {
func TestAccComputeInstance_scheduling(t *testing.T) { func TestAccComputeInstance_scheduling(t *testing.T) {
var instance compute.Instance var instance compute.Instance
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -282,7 +296,7 @@ func TestAccComputeInstance_scheduling(t *testing.T) {
CheckDestroy: testAccCheckComputeInstanceDestroy, CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeInstance_scheduling, Config: testAccComputeInstance_scheduling(instanceName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists( testAccCheckComputeInstanceExists(
"google_compute_instance.foobar", &instance), "google_compute_instance.foobar", &instance),
@ -437,276 +451,300 @@ func testAccCheckComputeInstanceServiceAccount(instance *compute.Instance, scope
} }
} }
var testAccComputeInstance_basic_deprecated_network = fmt.Sprintf(` func testAccComputeInstance_basic_deprecated_network(instance string) string {
resource "google_compute_instance" "foobar" { return fmt.Sprintf(`
name = "instance-test-%s" resource "google_compute_instance" "foobar" {
machine_type = "n1-standard-1" name = "%s"
zone = "us-central1-a" machine_type = "n1-standard-1"
can_ip_forward = false zone = "us-central1-a"
tags = ["foo", "bar"] can_ip_forward = false
tags = ["foo", "bar"]
disk { disk {
image = "debian-7-wheezy-v20140814" image = "debian-7-wheezy-v20140814"
} }
network { network {
source = "default" source = "default"
} }
metadata { metadata {
foo = "bar" foo = "bar"
} }
}`, acctest.RandString(10)) }`, instance)
}
var testAccComputeInstance_update_deprecated_network = fmt.Sprintf(` func testAccComputeInstance_update_deprecated_network(instance string) string {
resource "google_compute_instance" "foobar" { return fmt.Sprintf(`
name = "instance-test-%s" resource "google_compute_instance" "foobar" {
machine_type = "n1-standard-1" name = "%s"
zone = "us-central1-a" machine_type = "n1-standard-1"
tags = ["baz"] zone = "us-central1-a"
tags = ["baz"]
disk { disk {
image = "debian-7-wheezy-v20140814" image = "debian-7-wheezy-v20140814"
} }
network { network {
source = "default" source = "default"
} }
metadata { metadata {
bar = "baz" bar = "baz"
} }
}`, acctest.RandString(10)) }`, instance)
}
var testAccComputeInstance_basic = fmt.Sprintf(` func testAccComputeInstance_basic(instance string) string {
resource "google_compute_instance" "foobar" { return fmt.Sprintf(`
name = "instance-test-%s" resource "google_compute_instance" "foobar" {
machine_type = "n1-standard-1" name = "%s"
zone = "us-central1-a" machine_type = "n1-standard-1"
can_ip_forward = false zone = "us-central1-a"
tags = ["foo", "bar"] can_ip_forward = false
tags = ["foo", "bar"]
disk { disk {
image = "debian-7-wheezy-v20140814" image = "debian-7-wheezy-v20140814"
} }
network_interface { network_interface {
network = "default" network = "default"
} }
metadata { metadata {
foo = "bar" foo = "bar"
baz = "qux" baz = "qux"
} }
metadata_startup_script = "echo Hello" metadata_startup_script = "echo Hello"
}`, acctest.RandString(10)) }`, instance)
}
var testAccComputeInstance_basic2 = fmt.Sprintf(` func testAccComputeInstance_basic2(instance string) string {
resource "google_compute_instance" "foobar" { return fmt.Sprintf(`
name = "instance-test-%s" resource "google_compute_instance" "foobar" {
machine_type = "n1-standard-1" name = "%s"
zone = "us-central1-a" machine_type = "n1-standard-1"
can_ip_forward = false zone = "us-central1-a"
tags = ["foo", "bar"] can_ip_forward = false
tags = ["foo", "bar"]
disk { disk {
image = "debian-cloud/debian-7-wheezy-v20140814" image = "debian-cloud/debian-7-wheezy-v20140814"
} }
network_interface { network_interface {
network = "default" network = "default"
} }
metadata { metadata {
foo = "bar" foo = "bar"
} }
}`, acctest.RandString(10)) }`, instance)
}
var testAccComputeInstance_basic3 = fmt.Sprintf(` func testAccComputeInstance_basic3(instance string) string {
resource "google_compute_instance" "foobar" { return fmt.Sprintf(`
name = "instance-test-%s" resource "google_compute_instance" "foobar" {
machine_type = "n1-standard-1" name = "%s"
zone = "us-central1-a" machine_type = "n1-standard-1"
can_ip_forward = false zone = "us-central1-a"
tags = ["foo", "bar"] can_ip_forward = false
tags = ["foo", "bar"]
disk { disk {
image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140814" image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140814"
} }
network_interface { network_interface {
network = "default" network = "default"
} }
metadata { metadata {
foo = "bar" foo = "bar"
} }
}`, acctest.RandString(10)) }`, instance)
}
// Update zone to ForceNew, and change metadata k/v entirely // Update zone to ForceNew, and change metadata k/v entirely
// Generates diff mismatch // Generates diff mismatch
var testAccComputeInstance_forceNewAndChangeMetadata = fmt.Sprintf(` func testAccComputeInstance_forceNewAndChangeMetadata(instance string) string {
resource "google_compute_instance" "foobar" { return fmt.Sprintf(`
name = "instance-test-%s" resource "google_compute_instance" "foobar" {
machine_type = "n1-standard-1" name = "%s"
zone = "us-central1-a" machine_type = "n1-standard-1"
zone = "us-central1-b" zone = "us-central1-a"
tags = ["baz"] zone = "us-central1-b"
tags = ["baz"]
disk { disk {
image = "debian-7-wheezy-v20140814" image = "debian-7-wheezy-v20140814"
} }
network_interface { network_interface {
network = "default" network = "default"
access_config { } access_config { }
} }
metadata { metadata {
qux = "true" qux = "true"
} }
}`, acctest.RandString(10)) }`, instance)
}
// Update metadata, tags, and network_interface // Update metadata, tags, and network_interface
var testAccComputeInstance_update = fmt.Sprintf(` func testAccComputeInstance_update(instance string) string {
resource "google_compute_instance" "foobar" { return fmt.Sprintf(`
name = "instance-test-%s" resource "google_compute_instance" "foobar" {
machine_type = "n1-standard-1" name = "%s"
zone = "us-central1-a" machine_type = "n1-standard-1"
tags = ["baz"] zone = "us-central1-a"
tags = ["baz"]
disk { disk {
image = "debian-7-wheezy-v20140814" image = "debian-7-wheezy-v20140814"
}
network_interface {
network = "default"
access_config { }
}
metadata {
bar = "baz"
}
}`, acctest.RandString(10))
var testAccComputeInstance_ip = fmt.Sprintf(`
resource "google_compute_address" "foo" {
name = "instance-test-%s"
}
resource "google_compute_instance" "foobar" {
name = "instance-test-%s"
machine_type = "n1-standard-1"
zone = "us-central1-a"
tags = ["foo", "bar"]
disk {
image = "debian-7-wheezy-v20140814"
}
network_interface {
network = "default"
access_config {
nat_ip = "${google_compute_address.foo.address}"
} }
}
metadata { network_interface {
foo = "bar" network = "default"
} access_config { }
}`, acctest.RandString(10), acctest.RandString(10)) }
var testAccComputeInstance_disks = fmt.Sprintf(` metadata {
resource "google_compute_disk" "foobar" { bar = "baz"
name = "instance-test-%s" }
size = 10 }`, instance)
type = "pd-ssd"
zone = "us-central1-a"
} }
resource "google_compute_instance" "foobar" { func testAccComputeInstance_ip(ip, instance string) string {
name = "instance-test-%s" return fmt.Sprintf(`
machine_type = "n1-standard-1" resource "google_compute_address" "foo" {
zone = "us-central1-a" name = "%s"
disk {
image = "debian-7-wheezy-v20140814"
} }
disk { resource "google_compute_instance" "foobar" {
disk = "${google_compute_disk.foobar.name}" name = "%s"
auto_delete = false machine_type = "n1-standard-1"
zone = "us-central1-a"
tags = ["foo", "bar"]
disk {
image = "debian-7-wheezy-v20140814"
}
network_interface {
network = "default"
access_config {
nat_ip = "${google_compute_address.foo.address}"
}
}
metadata {
foo = "bar"
}
}`, ip, instance)
}
func testAccComputeInstance_disks(disk, instance string) string {
return fmt.Sprintf(`
resource "google_compute_disk" "foobar" {
name = "%s"
size = 10
type = "pd-ssd"
zone = "us-central1-a"
} }
network_interface { resource "google_compute_instance" "foobar" {
network = "default" name = "%s"
} machine_type = "n1-standard-1"
zone = "us-central1-a"
metadata { disk {
foo = "bar" image = "debian-7-wheezy-v20140814"
} }
}`, acctest.RandString(10), acctest.RandString(10))
var testAccComputeInstance_local_ssd = fmt.Sprintf(` disk {
resource "google_compute_instance" "local-ssd" { disk = "${google_compute_disk.foobar.name}"
name = "instance-test-%s" auto_delete = false
machine_type = "n1-standard-1" }
zone = "us-central1-a"
disk { network_interface {
image = "debian-7-wheezy-v20140814" network = "default"
} }
disk { metadata {
type = "local-ssd" foo = "bar"
scratch = true }
} }`, disk, instance)
}
network_interface { func testAccComputeInstance_local_ssd(instance string) string {
network = "default" return fmt.Sprintf(`
} resource "google_compute_instance" "local-ssd" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-central1-a"
}`, acctest.RandString(10)) disk {
image = "debian-7-wheezy-v20140814"
}
var testAccComputeInstance_service_account = fmt.Sprintf(` disk {
resource "google_compute_instance" "foobar" { type = "local-ssd"
name = "instance-test-%s" scratch = true
machine_type = "n1-standard-1" }
zone = "us-central1-a"
disk { network_interface {
image = "debian-7-wheezy-v20140814" network = "default"
} }
network_interface { }`, instance)
network = "default" }
}
service_account { func testAccComputeInstance_service_account(instance string) string {
scopes = [ return fmt.Sprintf(`
"userinfo-email", resource "google_compute_instance" "foobar" {
"compute-ro", name = "%s"
"storage-ro", machine_type = "n1-standard-1"
] zone = "us-central1-a"
}
}`, acctest.RandString(10))
var testAccComputeInstance_scheduling = fmt.Sprintf(` disk {
resource "google_compute_instance" "foobar" { image = "debian-7-wheezy-v20140814"
name = "instance-test-%s" }
machine_type = "n1-standard-1"
zone = "us-central1-a"
disk { network_interface {
image = "debian-7-wheezy-v20140814" network = "default"
} }
network_interface { service_account {
network = "default" scopes = [
} "userinfo-email",
"compute-ro",
"storage-ro",
]
}
}`, instance)
}
scheduling { func testAccComputeInstance_scheduling(instance string) string {
} return fmt.Sprintf(`
}`, acctest.RandString(10)) resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-central1-a"
disk {
image = "debian-7-wheezy-v20140814"
}
network_interface {
network = "default"
}
scheduling {
}
}`, instance)
}

View File

@ -10,6 +10,11 @@ import (
) )
func TestAccComputeTargetHttpProxy_basic(t *testing.T) { 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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -17,7 +22,7 @@ func TestAccComputeTargetHttpProxy_basic(t *testing.T) {
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy, CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeTargetHttpProxy_basic1, Config: testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetHttpProxyExists( testAccCheckComputeTargetHttpProxyExists(
"google_compute_target_http_proxy.foobar"), "google_compute_target_http_proxy.foobar"),
@ -28,6 +33,11 @@ func TestAccComputeTargetHttpProxy_basic(t *testing.T) {
} }
func TestAccComputeTargetHttpProxy_update(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{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -35,7 +45,7 @@ func TestAccComputeTargetHttpProxy_update(t *testing.T) {
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy, CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeTargetHttpProxy_basic1, Config: testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetHttpProxyExists( testAccCheckComputeTargetHttpProxyExists(
"google_compute_target_http_proxy.foobar"), "google_compute_target_http_proxy.foobar"),
@ -43,7 +53,7 @@ func TestAccComputeTargetHttpProxy_update(t *testing.T) {
}, },
resource.TestStep{ resource.TestStep{
Config: testAccComputeTargetHttpProxy_basic2, Config: testAccComputeTargetHttpProxy_basic2(target, backend, hc, urlmap1, urlmap2),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetHttpProxyExists( testAccCheckComputeTargetHttpProxyExists(
"google_compute_target_http_proxy.foobar"), "google_compute_target_http_proxy.foobar"),
@ -98,130 +108,134 @@ func testAccCheckComputeTargetHttpProxyExists(n string) resource.TestCheckFunc {
} }
} }
var testAccComputeTargetHttpProxy_basic1 = fmt.Sprintf(` func testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2 string) string {
resource "google_compute_target_http_proxy" "foobar" { return fmt.Sprintf(`
description = "Resource created for Terraform acceptance testing" resource "google_compute_target_http_proxy" "foobar" {
name = "httpproxy-test-%s" description = "Resource created for Terraform acceptance testing"
url_map = "${google_compute_url_map.foobar1.self_link}" name = "%s"
} url_map = "${google_compute_url_map.foobar1.self_link}"
resource "google_compute_backend_service" "foobar" {
name = "httpproxy-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "httpproxy-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar1" {
name = "httpproxy-test-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "boop"
} }
path_matcher {
resource "google_compute_backend_service" "foobar" {
name = "%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar1" {
name = "%s"
default_service = "${google_compute_backend_service.foobar.self_link}" default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop" host_rule {
path_rule { hosts = ["mysite.com", "myothersite.com"]
paths = ["/*"] path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}" service = "${google_compute_backend_service.foobar.self_link}"
} }
} }
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}"
}
}
resource "google_compute_url_map" "foobar2" { 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"]
path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}" default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop" host_rule {
path_rule { hosts = ["mysite.com", "myothersite.com"]
paths = ["/*"] path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}" service = "${google_compute_backend_service.foobar.self_link}"
} }
} }
test { `, target, backend, hc, urlmap1, urlmap2)
host = "mysite.com" }
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}" 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 = "%s"
url_map = "${google_compute_url_map.foobar2.self_link}"
} }
}
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
var testAccComputeTargetHttpProxy_basic2 = fmt.Sprintf(` resource "google_compute_backend_service" "foobar" {
resource "google_compute_target_http_proxy" "foobar" { name = "%s"
description = "Resource created for Terraform acceptance testing" health_checks = ["${google_compute_http_health_check.zero.self_link}"]
name = "httpproxy-test-%s"
url_map = "${google_compute_url_map.foobar2.self_link}"
}
resource "google_compute_backend_service" "foobar" {
name = "httpproxy-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "httpproxy-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar1" {
name = "httpproxy-test-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "boop"
} }
path_matcher {
resource "google_compute_http_health_check" "zero" {
name = "%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar1" {
name = "%s"
default_service = "${google_compute_backend_service.foobar.self_link}" default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop" host_rule {
path_rule { hosts = ["mysite.com", "myothersite.com"]
paths = ["/*"] path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}" service = "${google_compute_backend_service.foobar.self_link}"
} }
} }
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}"
}
}
resource "google_compute_url_map" "foobar2" { 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"]
path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}" default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop" host_rule {
path_rule { hosts = ["mysite.com", "myothersite.com"]
paths = ["/*"] path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}" service = "${google_compute_backend_service.foobar.self_link}"
} }
} }
test { `, target, backend, hc, urlmap1, urlmap2)
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}"
}
} }
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))

View File

@ -10,16 +10,17 @@ import (
) )
func TestAccDnsRecordSet_basic(t *testing.T) { func TestAccDnsRecordSet_basic(t *testing.T) {
zoneName := fmt.Sprintf("dnszone-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckDnsRecordSetDestroy, CheckDestroy: testAccCheckDnsRecordSetDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccDnsRecordSet_basic, Config: testAccDnsRecordSet_basic(zoneName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckDnsRecordSetExists( testAccCheckDnsRecordSetExists(
"google_dns_record_set.foobar"), "google_dns_record_set.foobar", zoneName),
), ),
}, },
}, },
@ -43,11 +44,11 @@ func testAccCheckDnsRecordSetDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccCheckDnsRecordSetExists(name string) resource.TestCheckFunc { func testAccCheckDnsRecordSetExists(resourceType, resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name] rs, ok := s.RootModule().Resources[resourceType]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", name) return fmt.Errorf("Not found: %s", resourceName)
} }
dnsName := rs.Primary.Attributes["name"] dnsName := rs.Primary.Attributes["name"]
@ -60,7 +61,7 @@ func testAccCheckDnsRecordSetExists(name string) resource.TestCheckFunc {
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
resp, err := config.clientDns.ResourceRecordSets.List( 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 { if err != nil {
return fmt.Errorf("Error confirming DNS RecordSet existence: %#v", err) return fmt.Errorf("Error confirming DNS RecordSet existence: %#v", err)
} }
@ -77,17 +78,19 @@ func testAccCheckDnsRecordSetExists(name string) resource.TestCheckFunc {
} }
} }
var testAccDnsRecordSet_basic = fmt.Sprintf(` func testAccDnsRecordSet_basic(zoneName string) string {
resource "google_dns_managed_zone" "parent-zone" { return fmt.Sprintf(`
name = "dnsrecord-test-%s" resource "google_dns_managed_zone" "parent-zone" {
dns_name = "terraform.test." name = "%s"
description = "Test Description" dns_name = "terraform.test."
description = "Test Description"
}
resource "google_dns_record_set" "foobar" {
managed_zone = "${google_dns_managed_zone.parent-zone.name}"
name = "test-record.terraform.test."
type = "A"
rrdatas = ["127.0.0.1", "127.0.0.10"]
ttl = 600
}
`, zoneName)
} }
resource "google_dns_record_set" "foobar" {
managed_zone = "${google_dns_managed_zone.parent-zone.name}"
name = "test-record.terraform.test."
type = "A"
rrdatas = ["127.0.0.1", "127.0.0.10"]
ttl = 600
}
`, acctest.RandString(10))

View File

@ -101,7 +101,7 @@ func testAccGoogleSqlDatabaseDestroy(s *terraform.State) error {
var testGoogleSqlDatabase_basic = fmt.Sprintf(` var testGoogleSqlDatabase_basic = fmt.Sprintf(`
resource "google_sql_database_instance" "instance" { resource "google_sql_database_instance" "instance" {
name = "sqldatabase-test-%s" name = "sqldatabasetest%s"
region = "us-central" region = "us-central"
settings { settings {
tier = "D0" tier = "D0"
@ -109,7 +109,7 @@ resource "google_sql_database_instance" "instance" {
} }
resource "google_sql_database" "database" { resource "google_sql_database" "database" {
name = "sqldatabase-test-%s" name = "sqldatabasetest%s"
instance = "${google_sql_database_instance.instance.name}" instance = "${google_sql_database_instance.instance.name}"
} }
`, acctest.RandString(10), acctest.RandString(10)) `, acctest.RandString(10), acctest.RandString(10))