clean up RegionBackendService and tests
This commit is contained in:
parent
39809fca76
commit
adafa722e7
|
@ -61,7 +61,7 @@ func TestAccComputeForwardingRule_internalLoadBalancing(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
|
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeForwardingRule_internalLoadBalancing(serviceName, "us-central1", checkName, ruleName),
|
Config: testAccComputeForwardingRule_internalLoadBalancing(serviceName, checkName, ruleName),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckComputeForwardingRuleExists(
|
testAccCheckComputeForwardingRuleExists(
|
||||||
"google_compute_forwarding_rule.foobar"),
|
"google_compute_forwarding_rule.foobar"),
|
||||||
|
@ -154,14 +154,14 @@ resource "google_compute_forwarding_rule" "foobar" {
|
||||||
`, addrName, poolName, ruleName)
|
`, addrName, poolName, ruleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccComputeForwardingRule_internalLoadBalancing(serviceName, region, checkName, ruleName string) string {
|
func testAccComputeForwardingRule_internalLoadBalancing(serviceName, checkName, ruleName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_region_backend_service" "foobar-bs" {
|
resource "google_compute_region_backend_service" "foobar-bs" {
|
||||||
name = "%s"
|
name = "%s"
|
||||||
description = "Resource created for Terraform acceptance testing"
|
description = "Resource created for Terraform acceptance testing"
|
||||||
health_checks = ["${google_compute_health_check.zero.self_link}"]
|
health_checks = ["${google_compute_health_check.zero.self_link}"]
|
||||||
load_balancing_scheme = "INTERNAL"
|
load_balancing_scheme = "INTERNAL"
|
||||||
region = "%s"
|
region = "us-central1"
|
||||||
}
|
}
|
||||||
resource "google_compute_health_check" "zero" {
|
resource "google_compute_health_check" "zero" {
|
||||||
name = "%s"
|
name = "%s"
|
||||||
|
@ -180,5 +180,5 @@ resource "google_compute_forwarding_rule" "foobar" {
|
||||||
backend_service = "${google_compute_region_backend_service.foobar-bs.self_link}"
|
backend_service = "${google_compute_region_backend_service.foobar-bs.self_link}"
|
||||||
ports = ["80"]
|
ports = ["80"]
|
||||||
}
|
}
|
||||||
`, serviceName, region, checkName, ruleName)
|
`, serviceName, checkName, ruleName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ func resourceComputeHealthCheck() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: "TCP",
|
Default: "TCP",
|
||||||
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"tcp_health_check": &schema.Schema{
|
"tcp_health_check": &schema.Schema{
|
||||||
|
|
|
@ -50,33 +50,10 @@ func resourceComputeRegionBackendService() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
"balancing_mode": &schema.Schema{
|
|
||||||
Type: schema.TypeString,
|
|
||||||
Optional: true,
|
|
||||||
Default: "UTILIZATION",
|
|
||||||
},
|
|
||||||
"capacity_scaler": &schema.Schema{
|
|
||||||
Type: schema.TypeFloat,
|
|
||||||
Optional: true,
|
|
||||||
Default: 1,
|
|
||||||
},
|
|
||||||
"description": &schema.Schema{
|
"description": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
"max_rate": &schema.Schema{
|
|
||||||
Type: schema.TypeInt,
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"max_rate_per_instance": &schema.Schema{
|
|
||||||
Type: schema.TypeFloat,
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"max_utilization": &schema.Schema{
|
|
||||||
Type: schema.TypeFloat,
|
|
||||||
Optional: true,
|
|
||||||
Default: 0.8,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
@ -88,12 +65,6 @@ func resourceComputeRegionBackendService() *schema.Resource {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"enable_cdn": &schema.Schema{
|
|
||||||
Type: schema.TypeBool,
|
|
||||||
Optional: true,
|
|
||||||
Default: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
"fingerprint": &schema.Schema{
|
"fingerprint": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
|
@ -105,12 +76,6 @@ func resourceComputeRegionBackendService() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"port_name": &schema.Schema{
|
|
||||||
Type: schema.TypeString,
|
|
||||||
Optional: true,
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
"project": &schema.Schema{
|
"project": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
@ -165,10 +130,6 @@ func resourceComputeRegionBackendServiceCreate(d *schema.ResourceData, meta inte
|
||||||
service.Description = v.(string)
|
service.Description = v.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("port_name"); ok {
|
|
||||||
service.PortName = v.(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
if v, ok := d.GetOk("protocol"); ok {
|
if v, ok := d.GetOk("protocol"); ok {
|
||||||
service.Protocol = v.(string)
|
service.Protocol = v.(string)
|
||||||
}
|
}
|
||||||
|
@ -177,10 +138,6 @@ func resourceComputeRegionBackendServiceCreate(d *schema.ResourceData, meta inte
|
||||||
service.TimeoutSec = int64(v.(int))
|
service.TimeoutSec = int64(v.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("enable_cdn"); ok {
|
|
||||||
service.EnableCDN = v.(bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
if v, ok := d.GetOk("load_balancing_scheme"); ok {
|
if v, ok := d.GetOk("load_balancing_scheme"); ok {
|
||||||
service.LoadBalancingScheme = v.(string)
|
service.LoadBalancingScheme = v.(string)
|
||||||
}
|
}
|
||||||
|
@ -243,8 +200,6 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("description", service.Description)
|
d.Set("description", service.Description)
|
||||||
d.Set("enable_cdn", service.EnableCDN)
|
|
||||||
d.Set("port_name", service.PortName)
|
|
||||||
d.Set("protocol", service.Protocol)
|
d.Set("protocol", service.Protocol)
|
||||||
d.Set("timeout_sec", service.TimeoutSec)
|
d.Set("timeout_sec", service.TimeoutSec)
|
||||||
d.Set("fingerprint", service.Fingerprint)
|
d.Set("fingerprint", service.Fingerprint)
|
||||||
|
@ -289,9 +244,6 @@ func resourceComputeRegionBackendServiceUpdate(d *schema.ResourceData, meta inte
|
||||||
if v, ok := d.GetOk("description"); ok {
|
if v, ok := d.GetOk("description"); ok {
|
||||||
service.Description = v.(string)
|
service.Description = v.(string)
|
||||||
}
|
}
|
||||||
if v, ok := d.GetOk("port_name"); ok {
|
|
||||||
service.PortName = v.(string)
|
|
||||||
}
|
|
||||||
if v, ok := d.GetOk("protocol"); ok {
|
if v, ok := d.GetOk("protocol"); ok {
|
||||||
service.Protocol = v.(string)
|
service.Protocol = v.(string)
|
||||||
}
|
}
|
||||||
|
@ -303,10 +255,6 @@ func resourceComputeRegionBackendServiceUpdate(d *schema.ResourceData, meta inte
|
||||||
service.LoadBalancingScheme = v.(string)
|
service.LoadBalancingScheme = v.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("enable_cdn") {
|
|
||||||
service.EnableCDN = d.Get("enable_cdn").(bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("[DEBUG] Updating existing Backend Service %q: %#v", d.Id(), service)
|
log.Printf("[DEBUG] Updating existing Backend Service %q: %#v", d.Id(), service)
|
||||||
op, err := config.clientCompute.RegionBackendServices.Update(
|
op, err := config.clientCompute.RegionBackendServices.Update(
|
||||||
project, region, d.Id(), &service).Do()
|
project, region, d.Id(), &service).Do()
|
||||||
|
@ -363,24 +311,9 @@ func resourceGoogleComputeRegionBackendServiceBackendHash(v interface{}) int {
|
||||||
|
|
||||||
buf.WriteString(fmt.Sprintf("%s-", m["group"].(string)))
|
buf.WriteString(fmt.Sprintf("%s-", m["group"].(string)))
|
||||||
|
|
||||||
if v, ok := m["balancing_mode"]; ok {
|
|
||||||
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
|
|
||||||
}
|
|
||||||
if v, ok := m["capacity_scaler"]; ok {
|
|
||||||
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
|
|
||||||
}
|
|
||||||
if v, ok := m["description"]; ok {
|
if v, ok := m["description"]; ok {
|
||||||
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
|
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
|
||||||
}
|
}
|
||||||
if v, ok := m["max_rate"]; ok {
|
|
||||||
buf.WriteString(fmt.Sprintf("%d-", int64(v.(int))))
|
|
||||||
}
|
|
||||||
if v, ok := m["max_rate_per_instance"]; ok {
|
|
||||||
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
|
|
||||||
}
|
|
||||||
if v, ok := m["max_rate_per_instance"]; ok {
|
|
||||||
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return hashcode.String(buf.String())
|
return hashcode.String(buf.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,8 @@ func TestAccComputeRegionBackendService_withBackend(t *testing.T) {
|
||||||
if svc.TimeoutSec != 10 {
|
if svc.TimeoutSec != 10 {
|
||||||
t.Errorf("Expected TimeoutSec == 10, got %d", svc.TimeoutSec)
|
t.Errorf("Expected TimeoutSec == 10, got %d", svc.TimeoutSec)
|
||||||
}
|
}
|
||||||
if svc.Protocol != "HTTP" {
|
if svc.Protocol != "TCP" {
|
||||||
t.Errorf("Expected Protocol to be HTTP, got %q", svc.Protocol)
|
t.Errorf("Expected Protocol to be TCP, got %q", svc.Protocol)
|
||||||
}
|
}
|
||||||
if len(svc.Backends) != 1 {
|
if len(svc.Backends) != 1 {
|
||||||
t.Errorf("Expected 1 backend, got %d", len(svc.Backends))
|
t.Errorf("Expected 1 backend, got %d", len(svc.Backends))
|
||||||
|
@ -106,8 +106,8 @@ func TestAccComputeRegionBackendService_withBackendAndUpdate(t *testing.T) {
|
||||||
if svc.TimeoutSec != 20 {
|
if svc.TimeoutSec != 20 {
|
||||||
t.Errorf("Expected TimeoutSec == 20, got %d", svc.TimeoutSec)
|
t.Errorf("Expected TimeoutSec == 20, got %d", svc.TimeoutSec)
|
||||||
}
|
}
|
||||||
if svc.Protocol != "HTTP" {
|
if svc.Protocol != "TCP" {
|
||||||
t.Errorf("Expected Protocol to be HTTP, got %q", svc.Protocol)
|
t.Errorf("Expected Protocol to be TCP, got %q", svc.Protocol)
|
||||||
}
|
}
|
||||||
if len(svc.Backends) != 1 {
|
if len(svc.Backends) != 1 {
|
||||||
t.Errorf("Expected 1 backend, got %d", len(svc.Backends))
|
t.Errorf("Expected 1 backend, got %d", len(svc.Backends))
|
||||||
|
@ -161,105 +161,13 @@ func testAccCheckComputeRegionBackendServiceExists(n string, svc *compute.Backen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccComputeRegionBackendService_withCDNEnabled(t *testing.T) {
|
|
||||||
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
||||||
checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
||||||
var svc compute.BackendService
|
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckComputeRegionBackendServiceDestroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
resource.TestStep{
|
|
||||||
Config: testAccComputeRegionBackendService_withCDNEnabled(
|
|
||||||
serviceName, checkName),
|
|
||||||
Check: resource.ComposeTestCheckFunc(
|
|
||||||
testAccCheckComputeRegionBackendServiceExists(
|
|
||||||
"google_compute_region_backend_service.foobar", &svc),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if svc.EnableCDN != true {
|
|
||||||
t.Errorf("Expected EnableCDN == true, got %t", svc.EnableCDN)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAccComputeRegionBackendService_withInternalLoadBalancing(t *testing.T) {
|
|
||||||
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
||||||
checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
||||||
var svc compute.BackendService
|
|
||||||
|
|
||||||
// config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckComputeRegionBackendServiceDestroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
resource.TestStep{
|
|
||||||
Config: testAccComputeRegionBackendService_withInternalLoadBalancing(
|
|
||||||
serviceName, checkName, "us-central1"),
|
|
||||||
Check: resource.ComposeTestCheckFunc(
|
|
||||||
testAccCheckComputeRegionBackendServiceExists(
|
|
||||||
"google_compute_region_backend_service.foobar", &svc),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if svc.LoadBalancingScheme != "INTERNAL" {
|
|
||||||
t.Errorf("Expected LoadBalancingScheme == INTERNAL, got %q", svc.EnableCDN)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccComputeRegionBackendService_basic(serviceName, checkName string) string {
|
func testAccComputeRegionBackendService_basic(serviceName, checkName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_region_backend_service" "foobar" {
|
resource "google_compute_region_backend_service" "foobar" {
|
||||||
name = "%s"
|
|
||||||
health_checks = ["${google_compute_health_check.zero.self_link}"]
|
|
||||||
load_balancing_scheme = "INTERNAL"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_compute_health_check" "zero" {
|
|
||||||
name = "%s"
|
|
||||||
check_interval_sec = 1
|
|
||||||
timeout_sec = 1
|
|
||||||
|
|
||||||
tcp_health_check {
|
|
||||||
port = "80"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`, serviceName, checkName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccComputeRegionBackendService_withCDNEnabled(serviceName, checkName string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "google_compute_region_backend_service" "foobar" {
|
|
||||||
name = "%s"
|
|
||||||
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
|
|
||||||
enable_cdn = true
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_compute_http_health_check" "zero" {
|
|
||||||
name = "%s"
|
|
||||||
request_path = "/"
|
|
||||||
check_interval_sec = 1
|
|
||||||
timeout_sec = 1
|
|
||||||
}
|
|
||||||
`, serviceName, checkName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccComputeRegionBackendService_withInternalLoadBalancing(serviceName, checkName, region string) string {
|
|
||||||
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "google_compute_region_backend_service" "foobar" {
|
|
||||||
name = "%s"
|
name = "%s"
|
||||||
health_checks = ["${google_compute_health_check.zero.self_link}"]
|
health_checks = ["${google_compute_health_check.zero.self_link}"]
|
||||||
load_balancing_scheme = "INTERNAL"
|
load_balancing_scheme = "INTERNAL"
|
||||||
region = "%s"
|
region = "us-central1"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_health_check" "zero" {
|
resource "google_compute_health_check" "zero" {
|
||||||
|
@ -271,28 +179,34 @@ resource "google_compute_health_check" "zero" {
|
||||||
port = "80"
|
port = "80"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, serviceName, region, checkName)
|
`, serviceName, checkName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccComputeRegionBackendService_basicModified(serviceName, checkOne, checkTwo string) string {
|
func testAccComputeRegionBackendService_basicModified(serviceName, checkOne, checkTwo string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_region_backend_service" "foobar" {
|
resource "google_compute_region_backend_service" "foobar" {
|
||||||
name = "%s"
|
name = "%s"
|
||||||
health_checks = ["${google_compute_http_health_check.one.self_link}"]
|
health_checks = ["${google_compute_health_check.one.self_link}"]
|
||||||
|
load_balancing_scheme = "INTERNAL"
|
||||||
|
region = "us-central1"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_http_health_check" "zero" {
|
resource "google_compute_health_check" "zero" {
|
||||||
name = "%s"
|
name = "%s"
|
||||||
request_path = "/"
|
|
||||||
check_interval_sec = 1
|
check_interval_sec = 1
|
||||||
timeout_sec = 1
|
timeout_sec = 1
|
||||||
|
|
||||||
|
tcp_health_check {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_http_health_check" "one" {
|
resource "google_compute_health_check" "one" {
|
||||||
name = "%s"
|
name = "%s"
|
||||||
request_path = "/one"
|
|
||||||
check_interval_sec = 30
|
check_interval_sec = 30
|
||||||
timeout_sec = 30
|
timeout_sec = 30
|
||||||
|
|
||||||
|
tcp_health_check {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`, serviceName, checkOne, checkTwo)
|
`, serviceName, checkOne, checkTwo)
|
||||||
}
|
}
|
||||||
|
@ -303,15 +217,16 @@ func testAccComputeRegionBackendService_withBackend(
|
||||||
resource "google_compute_region_backend_service" "lipsum" {
|
resource "google_compute_region_backend_service" "lipsum" {
|
||||||
name = "%s"
|
name = "%s"
|
||||||
description = "Hello World 1234"
|
description = "Hello World 1234"
|
||||||
port_name = "http"
|
protocol = "TCP"
|
||||||
protocol = "HTTP"
|
region = "us-central1"
|
||||||
timeout_sec = %v
|
timeout_sec = %v
|
||||||
|
load_balancing_scheme = "INTERNAL"
|
||||||
|
|
||||||
backend {
|
backend {
|
||||||
group = "${google_compute_instance_group_manager.foobar.instance_group}"
|
group = "${google_compute_instance_group_manager.foobar.instance_group}"
|
||||||
}
|
}
|
||||||
|
|
||||||
health_checks = ["${google_compute_http_health_check.default.self_link}"]
|
health_checks = ["${google_compute_health_check.default.self_link}"]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_instance_group_manager" "foobar" {
|
resource "google_compute_instance_group_manager" "foobar" {
|
||||||
|
@ -337,11 +252,14 @@ resource "google_compute_instance_template" "foobar" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_http_health_check" "default" {
|
resource "google_compute_health_check" "default" {
|
||||||
name = "%s"
|
name = "%s"
|
||||||
request_path = "/"
|
|
||||||
check_interval_sec = 1
|
check_interval_sec = 1
|
||||||
timeout_sec = 1
|
timeout_sec = 1
|
||||||
|
type = "TCP"
|
||||||
|
tcp_health_check {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`, serviceName, timeout, igName, itName, checkName)
|
`, serviceName, timeout, igName, itName, checkName)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue