mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 07:42:40 +00:00
Generate BackendService in Terraform (#3345)
<!-- This change is generated by MagicModules. --> /cc @rileykarson
This commit is contained in:
parent
f0941f7138
commit
7d66019993
|
@ -165,7 +165,6 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
|
||||||
"google_cloudiot_registry": resourceCloudIoTRegistry(),
|
"google_cloudiot_registry": resourceCloudIoTRegistry(),
|
||||||
"google_composer_environment": resourceComposerEnvironment(),
|
"google_composer_environment": resourceComposerEnvironment(),
|
||||||
"google_compute_attached_disk": resourceComputeAttachedDisk(),
|
"google_compute_attached_disk": resourceComputeAttachedDisk(),
|
||||||
"google_compute_backend_service": resourceComputeBackendService(),
|
|
||||||
"google_compute_global_forwarding_rule": resourceComputeGlobalForwardingRule(),
|
"google_compute_global_forwarding_rule": resourceComputeGlobalForwardingRule(),
|
||||||
"google_compute_instance": resourceComputeInstance(),
|
"google_compute_instance": resourceComputeInstance(),
|
||||||
"google_compute_instance_from_template": resourceComputeInstanceFromTemplate(),
|
"google_compute_instance_from_template": resourceComputeInstanceFromTemplate(),
|
||||||
|
|
|
@ -21,6 +21,7 @@ var GeneratedComputeResourcesMap = map[string]*schema.Resource{
|
||||||
"google_compute_autoscaler": resourceComputeAutoscaler(),
|
"google_compute_autoscaler": resourceComputeAutoscaler(),
|
||||||
"google_compute_backend_bucket": resourceComputeBackendBucket(),
|
"google_compute_backend_bucket": resourceComputeBackendBucket(),
|
||||||
"google_compute_backend_bucket_signed_url_key": resourceComputeBackendBucketSignedUrlKey(),
|
"google_compute_backend_bucket_signed_url_key": resourceComputeBackendBucketSignedUrlKey(),
|
||||||
|
"google_compute_backend_service": resourceComputeBackendService(),
|
||||||
"google_compute_disk": resourceComputeDisk(),
|
"google_compute_disk": resourceComputeDisk(),
|
||||||
"google_compute_firewall": resourceComputeFirewall(),
|
"google_compute_firewall": resourceComputeFirewall(),
|
||||||
"google_compute_forwarding_rule": resourceComputeForwardingRule(),
|
"google_compute_forwarding_rule": resourceComputeForwardingRule(),
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
90
google/resource_compute_backend_service_generated_test.go
Normal file
90
google/resource_compute_backend_service_generated_test.go
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This file is automatically generated by Magic Modules and manual
|
||||||
|
// changes will be clobbered when the file is regenerated.
|
||||||
|
//
|
||||||
|
// Please read more about how to change this file in
|
||||||
|
// .github/CONTRIBUTING.md.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
package google
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccComputeBackendService_backendServiceBasicExample(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
context := map[string]interface{}{
|
||||||
|
"random_suffix": acctest.RandString(10),
|
||||||
|
}
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeBackendServiceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccComputeBackendService_backendServiceBasicExample(context),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ResourceName: "google_compute_backend_service.default",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccComputeBackendService_backendServiceBasicExample(context map[string]interface{}) string {
|
||||||
|
return Nprintf(`
|
||||||
|
resource "google_compute_backend_service" "default" {
|
||||||
|
name = "backend-service-%{random_suffix}"
|
||||||
|
health_checks = ["${google_compute_http_health_check.default.self_link}"]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_http_health_check" "default" {
|
||||||
|
name = "health-check-%{random_suffix}"
|
||||||
|
request_path = "/"
|
||||||
|
check_interval_sec = 1
|
||||||
|
timeout_sec = 1
|
||||||
|
}
|
||||||
|
`, context)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeBackendServiceDestroy(s *terraform.State) error {
|
||||||
|
for name, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_backend_service" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(name, "data.") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/backendServices/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeBackendService still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -98,6 +98,7 @@ func resourceGoogleComputeBackendServiceBackendHash(v interface{}) int {
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
m := v.(map[string]interface{})
|
m := v.(map[string]interface{})
|
||||||
|
log.Printf("[DEBUG] hashing %v", m)
|
||||||
|
|
||||||
if group, err := getRelativePath(m["group"].(string)); err != nil {
|
if group, err := getRelativePath(m["group"].(string)); err != nil {
|
||||||
log.Printf("[WARN] Error on retrieving relative path of instance group: %s", err)
|
log.Printf("[WARN] Error on retrieving relative path of instance group: %s", err)
|
||||||
|
@ -107,29 +108,115 @@ func resourceGoogleComputeBackendServiceBackendHash(v interface{}) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := m["balancing_mode"]; ok {
|
if v, ok := m["balancing_mode"]; ok {
|
||||||
|
if v == nil {
|
||||||
|
v = ""
|
||||||
|
}
|
||||||
|
|
||||||
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
|
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
|
||||||
}
|
}
|
||||||
if v, ok := m["capacity_scaler"]; ok {
|
if v, ok := m["capacity_scaler"]; ok {
|
||||||
|
if v == nil {
|
||||||
|
v = 0.0
|
||||||
|
}
|
||||||
|
|
||||||
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
|
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
|
||||||
}
|
}
|
||||||
if v, ok := m["description"]; ok {
|
if v, ok := m["description"]; ok {
|
||||||
|
if v == nil {
|
||||||
|
v = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] writing description %s", v)
|
||||||
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
|
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
|
||||||
}
|
}
|
||||||
if v, ok := m["max_rate"]; ok {
|
if v, ok := m["max_rate"]; ok {
|
||||||
|
if v == nil {
|
||||||
|
v = 0
|
||||||
|
}
|
||||||
|
|
||||||
buf.WriteString(fmt.Sprintf("%d-", int64(v.(int))))
|
buf.WriteString(fmt.Sprintf("%d-", int64(v.(int))))
|
||||||
}
|
}
|
||||||
if v, ok := m["max_rate_per_instance"]; ok {
|
if v, ok := m["max_rate_per_instance"]; ok {
|
||||||
|
if v == nil {
|
||||||
|
v = 0.0
|
||||||
|
}
|
||||||
|
|
||||||
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
|
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
|
||||||
}
|
}
|
||||||
if v, ok := m["max_connections"]; ok {
|
if v, ok := m["max_connections"]; ok {
|
||||||
buf.WriteString(fmt.Sprintf("%d-", int64(v.(int))))
|
if v == nil {
|
||||||
|
v = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
switch v := v.(type) {
|
||||||
|
case float64:
|
||||||
|
// The Golang JSON library can't tell int values apart from floats,
|
||||||
|
// because MM doesn't give fields strong types. Since another value
|
||||||
|
// in this block was a real float, it assumed this was a float too.
|
||||||
|
// It's not.
|
||||||
|
// Note that math.Round in Go is from float64 -> float64, so it will
|
||||||
|
// be a noop. int(floatVal) truncates extra parts, so if the float64
|
||||||
|
// representation of an int falls below the real value we'll have
|
||||||
|
// the wrong value. eg if 3 was represented as 2.999999, that would
|
||||||
|
// convert to 2. So we add 0.5, ensuring that we'll truncate to the
|
||||||
|
// correct value. This wouldn't remain true if we were far enough
|
||||||
|
// from 0 that we were off by > 0.5, but no float conversion *could*
|
||||||
|
// work correctly in that case. 53-bit floating types as the only
|
||||||
|
// numeric type was not a good idea, thanks Javascript.
|
||||||
|
var vInt int
|
||||||
|
if v < 0 {
|
||||||
|
vInt = int(v - 0.5)
|
||||||
|
} else {
|
||||||
|
vInt = int(v + 0.5)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] writing float value %f as integer value %v", v, vInt)
|
||||||
|
buf.WriteString(fmt.Sprintf("%d-", vInt))
|
||||||
|
default:
|
||||||
|
buf.WriteString(fmt.Sprintf("%d-", int64(v.(int))))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if v, ok := m["max_connections_per_instance"]; ok {
|
if v, ok := m["max_connections_per_instance"]; ok {
|
||||||
buf.WriteString(fmt.Sprintf("%d-", int64(v.(int))))
|
if v == nil {
|
||||||
|
v = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
switch v := v.(type) {
|
||||||
|
case float64:
|
||||||
|
// The Golang JSON library can't tell int values apart from floats,
|
||||||
|
// because MM doesn't give fields strong types. Since another value
|
||||||
|
// in this block was a real float, it assumed this was a float too.
|
||||||
|
// It's not.
|
||||||
|
// Note that math.Round in Go is from float64 -> float64, so it will
|
||||||
|
// be a noop. int(floatVal) truncates extra parts, so if the float64
|
||||||
|
// representation of an int falls below the real value we'll have
|
||||||
|
// the wrong value. eg if 3 was represented as 2.999999, that would
|
||||||
|
// convert to 2. So we add 0.5, ensuring that we'll truncate to the
|
||||||
|
// correct value. This wouldn't remain true if we were far enough
|
||||||
|
// from 0 that we were off by > 0.5, but no float conversion *could*
|
||||||
|
// work correctly in that case. 53-bit floating types as the only
|
||||||
|
// numeric type was not a good idea, thanks Javascript.
|
||||||
|
var vInt int
|
||||||
|
if v < 0 {
|
||||||
|
vInt = int(v - 0.5)
|
||||||
|
} else {
|
||||||
|
vInt = int(v + 0.5)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] writing float value %f as integer value %v", v, vInt)
|
||||||
|
buf.WriteString(fmt.Sprintf("%d-", vInt))
|
||||||
|
default:
|
||||||
|
buf.WriteString(fmt.Sprintf("%d-", int64(v.(int))))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if v, ok := m["max_rate_per_instance"]; ok {
|
if v, ok := m["max_rate_per_instance"]; ok {
|
||||||
|
if v == nil {
|
||||||
|
v = 0.0
|
||||||
|
}
|
||||||
|
|
||||||
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
|
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] computed hash value of %v from %v", hashcode.String(buf.String()), buf.String())
|
||||||
return hashcode.String(buf.String())
|
return hashcode.String(buf.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,24 +327,6 @@ func TestAccComputeBackendService_withSecurityPolicy(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeBackendServiceDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_backend_service" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.BackendServices.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Backend service %s still exists", rs.Primary.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeBackendServiceExists(n string, svc *compute.BackendService) resource.TestCheckFunc {
|
func testAccCheckComputeBackendServiceExists(n string, svc *compute.BackendService) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -398,7 +380,7 @@ func testAccCheckComputeBackendServiceExistsWithIAP(n string, svc *compute.Backe
|
||||||
}
|
}
|
||||||
|
|
||||||
if found.Iap == nil || found.Iap.Enabled == false {
|
if found.Iap == nil || found.Iap.Enabled == false {
|
||||||
return fmt.Errorf("IAP not found or not enabled.")
|
return fmt.Errorf("IAP not found or not enabled. Saw %v", found.Iap)
|
||||||
}
|
}
|
||||||
|
|
||||||
*svc = *found
|
*svc = *found
|
||||||
|
|
|
@ -2,6 +2,7 @@ package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
@ -359,3 +360,63 @@ func flattenRegionBackends(backends []*compute.Backend) []map[string]interface{}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func expandBackends(configured []interface{}) ([]*computeBeta.Backend, error) {
|
||||||
|
backends := make([]*computeBeta.Backend, 0, len(configured))
|
||||||
|
|
||||||
|
for _, raw := range configured {
|
||||||
|
data := raw.(map[string]interface{})
|
||||||
|
|
||||||
|
g, ok := data["group"]
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("google_compute_backend_service.backend.group must be set")
|
||||||
|
}
|
||||||
|
|
||||||
|
b := computeBeta.Backend{
|
||||||
|
Group: g.(string),
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := data["balancing_mode"]; ok {
|
||||||
|
b.BalancingMode = v.(string)
|
||||||
|
}
|
||||||
|
if v, ok := data["capacity_scaler"]; ok {
|
||||||
|
b.CapacityScaler = v.(float64)
|
||||||
|
b.ForceSendFields = append(b.ForceSendFields, "CapacityScaler")
|
||||||
|
}
|
||||||
|
if v, ok := data["description"]; ok {
|
||||||
|
b.Description = v.(string)
|
||||||
|
}
|
||||||
|
if v, ok := data["max_rate"]; ok {
|
||||||
|
b.MaxRate = int64(v.(int))
|
||||||
|
if b.MaxRate == 0 {
|
||||||
|
b.NullFields = append(b.NullFields, "MaxRate")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := data["max_rate_per_instance"]; ok {
|
||||||
|
b.MaxRatePerInstance = v.(float64)
|
||||||
|
if b.MaxRatePerInstance == 0 {
|
||||||
|
b.NullFields = append(b.NullFields, "MaxRatePerInstance")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := data["max_connections"]; ok {
|
||||||
|
b.MaxConnections = int64(v.(int))
|
||||||
|
if b.MaxConnections == 0 {
|
||||||
|
b.NullFields = append(b.NullFields, "MaxConnections")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := data["max_connections_per_instance"]; ok {
|
||||||
|
b.MaxConnectionsPerInstance = int64(v.(int))
|
||||||
|
if b.MaxConnectionsPerInstance == 0 {
|
||||||
|
b.NullFields = append(b.NullFields, "MaxConnectionsPerInstance")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := data["max_utilization"]; ok {
|
||||||
|
b.MaxUtilization = v.(float64)
|
||||||
|
b.ForceSendFields = append(b.ForceSendFields, "MaxUtilization")
|
||||||
|
}
|
||||||
|
|
||||||
|
backends = append(backends, &b)
|
||||||
|
}
|
||||||
|
|
||||||
|
return backends, nil
|
||||||
|
}
|
||||||
|
|
|
@ -1,62 +1,48 @@
|
||||||
---
|
---
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file in
|
||||||
|
# .github/CONTRIBUTING.md.
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
layout: "google"
|
layout: "google"
|
||||||
page_title: "Google: google_compute_backend_service"
|
page_title: "Google: google_compute_backend_service"
|
||||||
sidebar_current: "docs-google-compute-backend-service"
|
sidebar_current: "docs-google-compute-backend-service"
|
||||||
description: |-
|
description: |-
|
||||||
Creates a Backend Service resource for Google Compute Engine.
|
Creates a BackendService resource in the specified project using the data
|
||||||
|
included in the request.
|
||||||
---
|
---
|
||||||
|
|
||||||
# google\_compute\_backend\_service
|
# google\_compute\_backend\_service
|
||||||
|
|
||||||
A Backend Service defines a group of virtual machines that will serve traffic for load balancing. For more information
|
Creates a BackendService resource in the specified project using the data
|
||||||
see [the official documentation](https://cloud.google.com/compute/docs/load-balancing/http/backend-service)
|
included in the request.
|
||||||
and the [API](https://cloud.google.com/compute/docs/reference/latest/backendServices).
|
|
||||||
|
|
||||||
For internal load balancing, use a [google_compute_region_backend_service](/docs/providers/google/r/compute_region_backend_service.html).
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
|
||||||
|
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=backend_service_basic&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
|
||||||
|
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
## Example Usage - Backend Service Basic
|
||||||
|
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
resource "google_compute_backend_service" "website" {
|
resource "google_compute_backend_service" "default" {
|
||||||
name = "my-backend"
|
name = "backend-service"
|
||||||
description = "Our company website"
|
|
||||||
port_name = "http"
|
|
||||||
protocol = "HTTP"
|
|
||||||
timeout_sec = 10
|
|
||||||
enable_cdn = false
|
|
||||||
|
|
||||||
backend {
|
|
||||||
group = "${google_compute_instance_group_manager.webservers.instance_group}"
|
|
||||||
}
|
|
||||||
|
|
||||||
health_checks = ["${google_compute_http_health_check.default.self_link}"]
|
health_checks = ["${google_compute_http_health_check.default.self_link}"]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_instance_group_manager" "webservers" {
|
|
||||||
name = "my-webservers"
|
|
||||||
instance_template = "${google_compute_instance_template.webserver.self_link}"
|
|
||||||
base_instance_name = "webserver"
|
|
||||||
zone = "us-central1-f"
|
|
||||||
target_size = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_compute_instance_template" "webserver" {
|
|
||||||
name = "standard-webserver"
|
|
||||||
machine_type = "n1-standard-1"
|
|
||||||
|
|
||||||
network_interface {
|
|
||||||
network = "default"
|
|
||||||
}
|
|
||||||
|
|
||||||
disk {
|
|
||||||
source_image = "debian-cloud/debian-9"
|
|
||||||
auto_delete = true
|
|
||||||
boot = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_compute_http_health_check" "default" {
|
resource "google_compute_http_health_check" "default" {
|
||||||
name = "test"
|
name = "health-check"
|
||||||
request_path = "/"
|
request_path = "/"
|
||||||
check_interval_sec = 1
|
check_interval_sec = 1
|
||||||
timeout_sec = 1
|
timeout_sec = 1
|
||||||
|
@ -67,136 +53,262 @@ resource "google_compute_http_health_check" "default" {
|
||||||
|
|
||||||
The following arguments are supported:
|
The following arguments are supported:
|
||||||
|
|
||||||
* `name` - (Required) The name of the backend service.
|
|
||||||
|
|
||||||
* `health_checks` - (Required) Specifies a list of HTTP/HTTPS health checks
|
* `health_checks` -
|
||||||
for checking the health of the backend service. Currently at most one health
|
(Required)
|
||||||
check can be specified, and a health check is required.
|
The list of URLs to the HttpHealthCheck or HttpsHealthCheck resource
|
||||||
|
for health checking this BackendService. Currently at most one health
|
||||||
|
check can be specified, and a health check is required.
|
||||||
|
For internal load balancing, a URL to a HealthCheck resource must be
|
||||||
|
specified instead.
|
||||||
|
|
||||||
|
* `name` -
|
||||||
|
(Required)
|
||||||
|
Name of the resource. Provided by the client when the resource is
|
||||||
|
created. The name must be 1-63 characters long, and comply with
|
||||||
|
RFC1035. Specifically, the name must be 1-63 characters long and match
|
||||||
|
the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the
|
||||||
|
first character must be a lowercase letter, and all following
|
||||||
|
characters must be a dash, lowercase letter, or digit, except the last
|
||||||
|
character, which cannot be a dash.
|
||||||
|
|
||||||
|
|
||||||
- - -
|
- - -
|
||||||
|
|
||||||
* `backend` - (Optional) The list of backends that serve this BackendService. Structure is documented below.
|
|
||||||
|
|
||||||
* `iap` - (Optional) Specification for the Identity-Aware proxy. Disabled if not specified. Structure is documented below.
|
* `affinity_cookie_ttl_sec` -
|
||||||
|
(Optional)
|
||||||
|
Lifetime of cookies in seconds if session_affinity is
|
||||||
|
GENERATED_COOKIE. If set to 0, the cookie is non-persistent and lasts
|
||||||
|
only until the end of the browser session (or equivalent). The
|
||||||
|
maximum allowed value for TTL is one day.
|
||||||
|
When the load balancing scheme is INTERNAL, this field is not used.
|
||||||
|
|
||||||
* `cdn_policy` - (Optional) Cloud CDN configuration for this BackendService. Structure is documented below.
|
* `backend` -
|
||||||
|
(Optional)
|
||||||
|
The list of backends that serve this BackendService. Structure is documented below.
|
||||||
|
|
||||||
* `connection_draining_timeout_sec` - (Optional) Time for which instance will be drained (not accept new connections,
|
* `cdn_policy` -
|
||||||
but still work to finish started ones). Defaults to `300`.
|
(Optional)
|
||||||
|
Cloud CDN configuration for this BackendService. Structure is documented below.
|
||||||
|
|
||||||
* `custom_request_headers` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) Headers that the
|
* `connection_draining_timeout_sec` -
|
||||||
HTTP/S load balancer should add to proxied requests. See [guide](https://cloud.google.com/compute/docs/load-balancing/http/backend-service#user-defined-request-headers) for details.
|
(Optional)
|
||||||
|
Time for which instance will be drained (not accept new
|
||||||
|
connections, but still work to finish started).
|
||||||
|
|
||||||
* `description` - (Optional) The textual description for the backend service.
|
* `description` -
|
||||||
|
(Optional)
|
||||||
|
An optional description of this resource.
|
||||||
|
|
||||||
* `enable_cdn` - (Optional) Whether or not to enable the Cloud CDN on the backend service.
|
* `enable_cdn` -
|
||||||
|
(Optional)
|
||||||
|
If true, enable Cloud CDN for this BackendService.
|
||||||
|
When the load balancing scheme is INTERNAL, this field is not used.
|
||||||
|
|
||||||
* `port_name` - (Optional) The name of a service that has been added to an
|
* `iap` -
|
||||||
instance group in this backend. See [related docs](https://cloud.google.com/compute/docs/instance-groups/#specifying_service_endpoints) for details. Defaults to http.
|
(Optional)
|
||||||
|
Settings for enabling Cloud Identity Aware Proxy Structure is documented below.
|
||||||
|
|
||||||
* `project` - (Optional) The ID of the project in which the resource belongs. If it
|
* `port_name` -
|
||||||
is not provided, the provider project is used.
|
(Optional)
|
||||||
|
Name of backend port. The same name should appear in the instance
|
||||||
|
groups referenced by this service. Required when the load balancing
|
||||||
|
scheme is EXTERNAL.
|
||||||
|
When the load balancing scheme is INTERNAL, this field is not used.
|
||||||
|
|
||||||
* `protocol` - (Optional) The protocol for incoming requests. Defaults to
|
* `protocol` -
|
||||||
`HTTP`.
|
(Optional)
|
||||||
|
The protocol this BackendService uses to communicate with backends.
|
||||||
|
Possible values are HTTP, HTTPS, TCP, and SSL. The default is HTTP.
|
||||||
|
For internal load balancing, the possible values are TCP and UDP, and
|
||||||
|
the default is TCP.
|
||||||
|
|
||||||
* `security_policy` - (Optional) Name or URI of a
|
* `security_policy` -
|
||||||
[security policy](https://cloud.google.com/armor/docs/security-policy-concepts) to add to the backend service.
|
(Optional)
|
||||||
|
The security policy associated with this backend service.
|
||||||
|
|
||||||
* `session_affinity` - (Optional) How to distribute load. Options are `NONE` (no
|
* `session_affinity` -
|
||||||
affinity), `CLIENT_IP` (hash of the source/dest addresses / ports), and
|
(Optional)
|
||||||
`GENERATED_COOKIE` (distribute load using a generated session cookie).
|
Type of session affinity to use. The default is NONE.
|
||||||
|
When the load balancing scheme is EXTERNAL, can be NONE, CLIENT_IP, or
|
||||||
|
GENERATED_COOKIE.
|
||||||
|
When the load balancing scheme is INTERNAL, can be NONE, CLIENT_IP,
|
||||||
|
CLIENT_IP_PROTO, or CLIENT_IP_PORT_PROTO.
|
||||||
|
When the protocol is UDP, this field is not used.
|
||||||
|
|
||||||
* `affinity_cookie_ttl_sec` - (Optional) Lifetime of cookies in seconds if session_affinity is
|
* `timeout_sec` -
|
||||||
`GENERATED_COOKIE`. If set to 0, the cookie is non-persistent and lasts only until the end of
|
(Optional)
|
||||||
the browser session (or equivalent). The maximum allowed value for TTL is one day.
|
How many seconds to wait for the backend before considering it a
|
||||||
|
failed request. Default is 30 seconds. Valid range is [1, 86400].
|
||||||
|
* `project` - (Optional) The ID of the project in which the resource belongs.
|
||||||
|
If it is not provided, the provider project is used.
|
||||||
|
|
||||||
* `timeout_sec` - (Optional) The number of secs to wait for a backend to respond
|
|
||||||
to a request before considering the request failed. Defaults to `30`.
|
|
||||||
|
|
||||||
The `backend` block supports:
|
The `backend` block supports:
|
||||||
|
|
||||||
* `group` - (Required) The name or URI of a Compute Engine instance group
|
* `balancing_mode` -
|
||||||
(`google_compute_instance_group_manager.xyz.instance_group`) that can
|
(Optional)
|
||||||
receive traffic.
|
Specifies the balancing mode for this backend.
|
||||||
|
For global HTTP(S) or TCP/SSL load balancing, the default is
|
||||||
|
UTILIZATION. Valid values are UTILIZATION, RATE (for HTTP(S))
|
||||||
|
and CONNECTION (for TCP/SSL).
|
||||||
|
This cannot be used for internal load balancing.
|
||||||
|
|
||||||
* `balancing_mode` - (Optional) Defines the strategy for balancing load.
|
* `capacity_scaler` -
|
||||||
Defaults to `UTILIZATION`
|
(Optional)
|
||||||
|
A multiplier applied to the group's maximum servicing capacity
|
||||||
|
(based on UTILIZATION, RATE or CONNECTION).
|
||||||
|
Default value is 1, which means the group will serve up to 100%
|
||||||
|
of its configured capacity (depending on balancingMode). A
|
||||||
|
setting of 0 means the group is completely drained, offering
|
||||||
|
0% of its available Capacity. Valid range is [0.0,1.0].
|
||||||
|
This cannot be used for internal load balancing.
|
||||||
|
|
||||||
* `capacity_scaler` - (Optional) A float in the range [0, 1.0] that scales the
|
* `description` -
|
||||||
maximum parameters for the group (e.g., max rate). A value of 0.0 will cause
|
(Optional)
|
||||||
no requests to be sent to the group (i.e., it adds the group in a drained
|
An optional description of this resource.
|
||||||
state). The default is 1.0.
|
Provide this property when you create the resource.
|
||||||
|
|
||||||
* `description` - (Optional) Textual description for the backend.
|
* `group` -
|
||||||
|
(Optional)
|
||||||
|
This instance group defines the list of instances that serve
|
||||||
|
traffic. Member virtual machine instances from each instance
|
||||||
|
group must live in the same zone as the instance group itself.
|
||||||
|
No two backends in a backend service are allowed to use same
|
||||||
|
Instance Group resource.
|
||||||
|
When the BackendService has load balancing scheme INTERNAL, the
|
||||||
|
instance group must be in a zone within the same region as the
|
||||||
|
BackendService.
|
||||||
|
|
||||||
* `max_rate` - (Optional) Maximum requests per second (RPS) that the group can
|
* `max_connections` -
|
||||||
handle.
|
(Optional)
|
||||||
|
The max number of simultaneous connections for the group. Can
|
||||||
|
be used with either CONNECTION or UTILIZATION balancing modes.
|
||||||
|
For CONNECTION mode, either maxConnections or
|
||||||
|
maxConnectionsPerInstance must be set.
|
||||||
|
This cannot be used for internal load balancing.
|
||||||
|
|
||||||
* `max_rate_per_instance` - (Optional) The maximum per-instance requests per
|
* `max_connections_per_instance` -
|
||||||
second (RPS).
|
(Optional)
|
||||||
|
The max number of simultaneous connections that a single
|
||||||
|
backend instance can handle. This is used to calculate the
|
||||||
|
capacity of the group. Can be used in either CONNECTION or
|
||||||
|
UTILIZATION balancing modes.
|
||||||
|
For CONNECTION mode, either maxConnections or
|
||||||
|
maxConnectionsPerInstance must be set.
|
||||||
|
This cannot be used for internal load balancing.
|
||||||
|
|
||||||
* `max_connections` - (Optional) The max number of simultaneous connections for the
|
* `max_rate` -
|
||||||
group. Can be used with either CONNECTION or UTILIZATION balancing
|
(Optional)
|
||||||
modes. For CONNECTION mode, either maxConnections or
|
The max requests per second (RPS) of the group.
|
||||||
maxConnectionsPerInstance must be set.
|
Can be used with either RATE or UTILIZATION balancing modes,
|
||||||
|
but required if RATE mode. For RATE mode, either maxRate or
|
||||||
|
maxRatePerInstance must be set.
|
||||||
|
This cannot be used for internal load balancing.
|
||||||
|
|
||||||
* `max_connections_per_instance` - (Optional) The max number of simultaneous connections
|
* `max_rate_per_instance` -
|
||||||
that a single backend instance can handle. This is used to calculate
|
(Optional)
|
||||||
the capacity of the group. Can be used in either CONNECTION or
|
The max requests per second (RPS) that a single backend
|
||||||
UTILIZATION balancing modes. For CONNECTION mode, either
|
instance can handle. This is used to calculate the capacity of
|
||||||
maxConnections or maxConnectionsPerInstance must be set.
|
the group. Can be used in either balancing mode. For RATE mode,
|
||||||
|
either maxRate or maxRatePerInstance must be set.
|
||||||
|
This cannot be used for internal load balancing.
|
||||||
|
|
||||||
* `max_utilization` - (Optional) The target CPU utilization for the group as a
|
* `max_utilization` -
|
||||||
float in the range [0.0, 1.0]. This flag can only be provided when the
|
(Optional)
|
||||||
balancing mode is `UTILIZATION`. Defaults to `0.8`.
|
Used when balancingMode is UTILIZATION. This ratio defines the
|
||||||
|
CPU utilization target for the group. The default is 0.8. Valid
|
||||||
|
range is [0.0, 1.0].
|
||||||
|
This cannot be used for internal load balancing.
|
||||||
|
|
||||||
The `cdn_policy` block supports:
|
The `cdn_policy` block supports:
|
||||||
|
|
||||||
* `cache_key_policy` - (Optional) The CacheKeyPolicy for this CdnPolicy.
|
* `cache_key_policy` -
|
||||||
Structure is documented below.
|
(Optional)
|
||||||
|
The CacheKeyPolicy for this CdnPolicy. Structure is documented below.
|
||||||
|
|
||||||
|
|
||||||
The `cache_key_policy` block supports:
|
The `cache_key_policy` block supports:
|
||||||
|
|
||||||
* `include_host` - (Optional) If true, requests to different hosts will be cached separately.
|
* `include_host` -
|
||||||
|
(Optional)
|
||||||
|
If true requests to different hosts will be cached separately.
|
||||||
|
|
||||||
* `include_protocol` - (Optional) If true, http and https requests will be cached separately.
|
* `include_protocol` -
|
||||||
|
(Optional)
|
||||||
|
If true, http and https requests will be cached separately.
|
||||||
|
|
||||||
* `include_query_string` - (Optional) If true, include query string parameters in the cache key
|
* `include_query_string` -
|
||||||
according to `query_string_whitelist` and `query_string_blacklist`. If neither is set, the entire
|
(Optional)
|
||||||
query string will be included. If false, the query string will be excluded from the cache key entirely.
|
If true, include query string parameters in the cache key
|
||||||
|
according to query_string_whitelist and
|
||||||
|
query_string_blacklist. If neither is set, the entire query
|
||||||
|
string will be included.
|
||||||
|
If false, the query string will be excluded from the cache
|
||||||
|
key entirely.
|
||||||
|
|
||||||
* `query_string_blacklist` - (Optional) Names of query string parameters to exclude in cache keys.
|
* `query_string_blacklist` -
|
||||||
All other parameters will be included. Either specify `query_string_whitelist` or
|
(Optional)
|
||||||
`query_string_blacklist`, not both. '&' and '=' will be percent encoded and not treated as delimiters.
|
Names of query string parameters to exclude in cache keys.
|
||||||
|
All other parameters will be included. Either specify
|
||||||
|
query_string_whitelist or query_string_blacklist, not both.
|
||||||
|
'&' and '=' will be percent encoded and not treated as
|
||||||
|
delimiters.
|
||||||
|
|
||||||
* `query_string_whitelist` - (Optional) Names of query string parameters to include in cache keys.
|
* `query_string_whitelist` -
|
||||||
All other parameters will be excluded. Either specify `query_string_whitelist` or
|
(Optional)
|
||||||
`query_string_blacklist`, not both. '&' and '=' will be percent encoded and not treated as delimiters.
|
Names of query string parameters to include in cache keys.
|
||||||
|
All other parameters will be excluded. Either specify
|
||||||
|
query_string_whitelist or query_string_blacklist, not both.
|
||||||
|
'&' and '=' will be percent encoded and not treated as
|
||||||
|
delimiters.
|
||||||
|
|
||||||
The `iap` block supports:
|
The `iap` block supports:
|
||||||
|
|
||||||
* `oauth2_client_id` - (Required) The client ID for use with OAuth 2.0.
|
* `oauth2_client_id` -
|
||||||
|
(Required)
|
||||||
|
OAuth2 Client ID for IAP
|
||||||
|
|
||||||
* `oauth2_client_secret` - (Required) The client secret for use with OAuth 2.0.
|
* `oauth2_client_secret` -
|
||||||
Out of band changes to this field will not be detected by Terraform, and it may
|
(Required)
|
||||||
perform spurious no-op updates when imported, or upgraded from pre-`2.0.0`.
|
OAuth2 Client Secret for IAP
|
||||||
|
|
||||||
|
* `oauth2_client_secret_sha256` -
|
||||||
|
OAuth2 Client Secret SHA-256 for IAP
|
||||||
|
|
||||||
## Attributes Reference
|
## Attributes Reference
|
||||||
|
|
||||||
In addition to the arguments listed above, the following computed attributes are
|
In addition to the arguments listed above, the following computed attributes are exported:
|
||||||
exported:
|
|
||||||
|
|
||||||
* `iap.0.oauth2_client_secret_sha256` - The SHA256 hash of the OAuth 2.0 client secret value.
|
|
||||||
|
|
||||||
* `fingerprint` - The fingerprint of the backend service.
|
* `creation_timestamp` -
|
||||||
|
Creation timestamp in RFC3339 text format.
|
||||||
|
|
||||||
|
* `fingerprint` -
|
||||||
|
Fingerprint of this resource. A hash of the contents stored in this
|
||||||
|
object. This field is used in optimistic locking.
|
||||||
* `self_link` - The URI of the created resource.
|
* `self_link` - The URI of the created resource.
|
||||||
|
|
||||||
|
|
||||||
|
## Timeouts
|
||||||
|
|
||||||
|
This resource provides the following
|
||||||
|
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:
|
||||||
|
|
||||||
|
- `create` - Default is 4 minutes.
|
||||||
|
- `update` - Default is 4 minutes.
|
||||||
|
- `delete` - Default is 4 minutes.
|
||||||
|
|
||||||
## Import
|
## Import
|
||||||
|
|
||||||
Backend services can be imported using the `name`, e.g.
|
BackendService can be imported using any of these accepted formats:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ terraform import google_compute_backend_service.website my-backend
|
$ terraform import google_compute_backend_service.default projects/{{project}}/global/backendServices/{{name}}
|
||||||
|
$ terraform import google_compute_backend_service.default {{project}}/{{name}}
|
||||||
|
$ terraform import google_compute_backend_service.default {{name}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
-> If you're importing a resource with beta features, make sure to include `-provider=google-beta`
|
||||||
|
as an argument so that Terraform uses the correct provider to import your resource.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user