Merge pull request #11228 from cblecker/rbs-sessionaffinity

provider/google: Add support for session_affinity to google_compute_region_backend_service
This commit is contained in:
Dana Hoffman 2017-01-18 10:06:02 -08:00 committed by GitHub
commit 006e9b1b3c
9 changed files with 389 additions and 22 deletions

View File

@ -82,6 +82,12 @@ func resourceComputeRegionBackendService() *schema.Resource {
Computed: true,
},
"session_affinity": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"region": &schema.Schema{
Type: schema.TypeString,
Optional: true,
@ -129,6 +135,10 @@ func resourceComputeRegionBackendServiceCreate(d *schema.ResourceData, meta inte
service.Protocol = v.(string)
}
if v, ok := d.GetOk("session_affinity"); ok {
service.SessionAffinity = v.(string)
}
if v, ok := d.GetOk("timeout_sec"); ok {
service.TimeoutSec = int64(v.(int))
}
@ -192,6 +202,7 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf
d.Set("description", service.Description)
d.Set("protocol", service.Protocol)
d.Set("session_affinity", service.SessionAffinity)
d.Set("timeout_sec", service.TimeoutSec)
d.Set("fingerprint", service.Fingerprint)
d.Set("self_link", service.SelfLink)
@ -238,6 +249,9 @@ func resourceComputeRegionBackendServiceUpdate(d *schema.ResourceData, meta inte
if v, ok := d.GetOk("protocol"); ok {
service.Protocol = v.(string)
}
if v, ok := d.GetOk("session_affinity"); ok {
service.SessionAffinity = v.(string)
}
if v, ok := d.GetOk("timeout_sec"); ok {
service.TimeoutSec = int64(v.(int))
}

View File

@ -114,6 +114,32 @@ func TestAccComputeRegionBackendService_withBackendAndUpdate(t *testing.T) {
}
}
func TestAccComputeRegionBackendService_withSessionAffinity(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_withSessionAffinity(
serviceName, checkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeRegionBackendServiceExists(
"google_compute_region_backend_service.foobar", &svc),
),
},
},
})
if svc.SessionAffinity != "CLIENT_IP" {
t.Errorf("Expected Protocol to be CLIENT_IP, got %q", svc.SessionAffinity)
}
}
func testAccCheckComputeRegionBackendServiceDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
@ -253,10 +279,32 @@ resource "google_compute_health_check" "default" {
name = "%s"
check_interval_sec = 1
timeout_sec = 1
tcp_health_check {
}
}
`, serviceName, timeout, igName, itName, checkName)
}
func testAccComputeRegionBackendService_withSessionAffinity(serviceName, checkName string) string {
return fmt.Sprintf(`
resource "google_compute_region_backend_service" "foobar" {
name = "%s"
health_checks = ["${google_compute_health_check.zero.self_link}"]
region = "us-central1"
session_affinity = "CLIENT_IP"
}
resource "google_compute_health_check" "zero" {
name = "%s"
check_interval_sec = 1
timeout_sec = 1
tcp_health_check {
port = "80"
}
}
`, serviceName, checkName)
}

View File

@ -1,11 +1,11 @@
{
"kind": "discovery#restDescription",
"etag": "\"tbys6C40o18GZwyMen5GMkdK-3s/AtRtoI2wqhCu6Twyv23FyGvWiUE\"",
"etag": "\"tbys6C40o18GZwyMen5GMkdK-3s/BIPueDp4_YHmOXWnzCh7vT7JOHQ\"",
"discoveryVersion": "v1",
"id": "compute:v1",
"name": "compute",
"version": "v1",
"revision": "20161115",
"revision": "20161123",
"title": "Compute Engine API",
"description": "Creates and runs virtual machines on Google Cloud Platform.",
"ownerDomain": "google.com",
@ -1090,6 +1090,10 @@
"id": "CacheInvalidationRule",
"type": "object",
"properties": {
"host": {
"type": "string",
"description": "If set, this invalidation rule will only apply to requests with a Host header matching host."
},
"path": {
"type": "string"
}
@ -2166,7 +2170,7 @@
},
"type": {
"type": "string",
"description": "Specifies the type of the healthCheck, either TCP, UDP, SSL, HTTP, HTTPS or HTTP2. If not specified, the default is TCP. Exactly one of the protocol-specific health check field must be specified, which must match type field.",
"description": "Specifies the type of the healthCheck, either TCP, SSL, HTTP or HTTPS. If not specified, the default is TCP. Exactly one of the protocol-specific health check field must be specified, which must match type field.",
"enum": [
"HTTP",
"HTTPS",
@ -4838,6 +4842,7 @@
"TARGET_POOLS",
"TARGET_SSL_PROXIES",
"TARGET_VPN_GATEWAYS",
"TOTAL_CPUS",
"URL_MAPS",
"VPN_TUNNELS"
],
@ -4874,6 +4879,7 @@
"",
"",
"",
"",
""
]
},
@ -6087,7 +6093,7 @@
},
"privateKey": {
"type": "string",
"description": "A write-only private key in PEM format. Only insert RPCs will include this field."
"description": "A write-only private key in PEM format. Only insert requests will include this field."
},
"selfLink": {
"type": "string",
@ -11470,12 +11476,32 @@
"httpMethod": "POST",
"description": "Lists all of the instances in the managed instance group. Each instance in the list has a currentAction, which indicates the action that the managed instance group is performing on the instance. For example, if the group is still creating an instance, the currentAction is CREATING. If a previous action failed, the list displays the errors for that failed action.",
"parameters": {
"filter": {
"type": "string",
"location": "query"
},
"instanceGroupManager": {
"type": "string",
"description": "The name of the managed instance group.",
"required": true,
"location": "path"
},
"maxResults": {
"type": "integer",
"default": "500",
"format": "uint32",
"minimum": "0",
"maximum": "500",
"location": "query"
},
"order_by": {
"type": "string",
"location": "query"
},
"pageToken": {
"type": "string",
"location": "query"
},
"project": {
"type": "string",
"description": "Project ID for this request.",
@ -14493,12 +14519,32 @@
"httpMethod": "POST",
"description": "Lists the instances in the managed instance group and instances that are scheduled to be created. The list includes any current actions that the group has scheduled for its instances.",
"parameters": {
"filter": {
"type": "string",
"location": "query"
},
"instanceGroupManager": {
"type": "string",
"description": "The name of the managed instance group.",
"required": true,
"location": "path"
},
"maxResults": {
"type": "integer",
"default": "500",
"format": "uint32",
"minimum": "0",
"maximum": "500",
"location": "query"
},
"order_by": {
"type": "string",
"location": "query"
},
"pageToken": {
"type": "string",
"location": "query"
},
"project": {
"type": "string",
"description": "Project ID for this request.",

View File

@ -1598,6 +1598,20 @@ func (s *AutoscalingPolicyCpuUtilization) MarshalJSON() ([]byte, error) {
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}
func (s *AutoscalingPolicyCpuUtilization) UnmarshalJSON(data []byte) error {
type noMethod AutoscalingPolicyCpuUtilization
var s1 struct {
UtilizationTarget gensupport.JSONFloat64 `json:"utilizationTarget"`
*noMethod
}
s1.noMethod = (*noMethod)(s)
if err := json.Unmarshal(data, &s1); err != nil {
return err
}
s.UtilizationTarget = float64(s1.UtilizationTarget)
return nil
}
// AutoscalingPolicyCustomMetricUtilization: Custom utilization metric
// policy.
type AutoscalingPolicyCustomMetricUtilization struct {
@ -1658,6 +1672,20 @@ func (s *AutoscalingPolicyCustomMetricUtilization) MarshalJSON() ([]byte, error)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}
func (s *AutoscalingPolicyCustomMetricUtilization) UnmarshalJSON(data []byte) error {
type noMethod AutoscalingPolicyCustomMetricUtilization
var s1 struct {
UtilizationTarget gensupport.JSONFloat64 `json:"utilizationTarget"`
*noMethod
}
s1.noMethod = (*noMethod)(s)
if err := json.Unmarshal(data, &s1); err != nil {
return err
}
s.UtilizationTarget = float64(s1.UtilizationTarget)
return nil
}
// AutoscalingPolicyLoadBalancingUtilization: Configuration parameters
// of autoscaling based on load balancing.
type AutoscalingPolicyLoadBalancingUtilization struct {
@ -1691,6 +1719,20 @@ func (s *AutoscalingPolicyLoadBalancingUtilization) MarshalJSON() ([]byte, error
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}
func (s *AutoscalingPolicyLoadBalancingUtilization) UnmarshalJSON(data []byte) error {
type noMethod AutoscalingPolicyLoadBalancingUtilization
var s1 struct {
UtilizationTarget gensupport.JSONFloat64 `json:"utilizationTarget"`
*noMethod
}
s1.noMethod = (*noMethod)(s)
if err := json.Unmarshal(data, &s1); err != nil {
return err
}
s.UtilizationTarget = float64(s1.UtilizationTarget)
return nil
}
// Backend: Message containing information of one individual backend.
type Backend struct {
// BalancingMode: Specifies the balancing mode for this backend. For
@ -1798,6 +1840,24 @@ func (s *Backend) MarshalJSON() ([]byte, error) {
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}
func (s *Backend) UnmarshalJSON(data []byte) error {
type noMethod Backend
var s1 struct {
CapacityScaler gensupport.JSONFloat64 `json:"capacityScaler"`
MaxRatePerInstance gensupport.JSONFloat64 `json:"maxRatePerInstance"`
MaxUtilization gensupport.JSONFloat64 `json:"maxUtilization"`
*noMethod
}
s1.noMethod = (*noMethod)(s)
if err := json.Unmarshal(data, &s1); err != nil {
return err
}
s.CapacityScaler = float64(s1.CapacityScaler)
s.MaxRatePerInstance = float64(s1.MaxRatePerInstance)
s.MaxUtilization = float64(s1.MaxUtilization)
return nil
}
// BackendService: A BackendService resource. This resource defines a
// group of backend virtual machines and their serving capacity.
type BackendService struct {
@ -2211,9 +2271,13 @@ func (s *BackendServicesScopedListWarningData) MarshalJSON() ([]byte, error) {
}
type CacheInvalidationRule struct {
// Host: If set, this invalidation rule will only apply to requests with
// a Host header matching host.
Host string `json:"host,omitempty"`
Path string `json:"path,omitempty"`
// ForceSendFields is a list of field names (e.g. "Path") to
// ForceSendFields is a list of field names (e.g. "Host") to
// unconditionally include in API requests. By default, fields with
// empty values are omitted from API requests. However, any non-pointer,
// non-interface field appearing in ForceSendFields will be sent to the
@ -2221,7 +2285,7 @@ type CacheInvalidationRule struct {
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`
// NullFields is a list of field names (e.g. "Path") to include in API
// NullFields is a list of field names (e.g. "Host") to include in API
// requests with the JSON null value. By default, fields with empty
// values are omitted from API requests. However, any field with an
// empty value appearing in NullFields will be sent to the server as
@ -3938,10 +4002,10 @@ type HealthCheck struct {
// greater value than checkIntervalSec.
TimeoutSec int64 `json:"timeoutSec,omitempty"`
// Type: Specifies the type of the healthCheck, either TCP, UDP, SSL,
// HTTP, HTTPS or HTTP2. If not specified, the default is TCP. Exactly
// one of the protocol-specific health check field must be specified,
// which must match type field.
// Type: Specifies the type of the healthCheck, either TCP, SSL, HTTP or
// HTTPS. If not specified, the default is TCP. Exactly one of the
// protocol-specific health check field must be specified, which must
// match type field.
//
// Possible values:
// "HTTP"
@ -8085,6 +8149,7 @@ type Quota struct {
// "TARGET_POOLS"
// "TARGET_SSL_PROXIES"
// "TARGET_VPN_GATEWAYS"
// "TOTAL_CPUS"
// "URL_MAPS"
// "VPN_TUNNELS"
Metric string `json:"metric,omitempty"`
@ -8115,6 +8180,22 @@ func (s *Quota) MarshalJSON() ([]byte, error) {
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}
func (s *Quota) UnmarshalJSON(data []byte) error {
type noMethod Quota
var s1 struct {
Limit gensupport.JSONFloat64 `json:"limit"`
Usage gensupport.JSONFloat64 `json:"usage"`
*noMethod
}
s1.noMethod = (*noMethod)(s)
if err := json.Unmarshal(data, &s1); err != nil {
return err
}
s.Limit = float64(s1.Limit)
s.Usage = float64(s1.Usage)
return nil
}
// Region: Region resource.
type Region struct {
// CreationTimestamp: [Output Only] Creation timestamp in RFC3339 text
@ -9943,8 +10024,8 @@ type SslCertificate struct {
// last character, which cannot be a dash.
Name string `json:"name,omitempty"`
// PrivateKey: A write-only private key in PEM format. Only insert RPCs
// will include this field.
// PrivateKey: A write-only private key in PEM format. Only insert
// requests will include this field.
PrivateKey string `json:"privateKey,omitempty"`
// SelfLink: [Output only] Server-defined URL for the resource.
@ -11154,6 +11235,20 @@ func (s *TargetPool) MarshalJSON() ([]byte, error) {
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}
func (s *TargetPool) UnmarshalJSON(data []byte) error {
type noMethod TargetPool
var s1 struct {
FailoverRatio gensupport.JSONFloat64 `json:"failoverRatio"`
*noMethod
}
s1.noMethod = (*noMethod)(s)
if err := json.Unmarshal(data, &s1); err != nil {
return err
}
s.FailoverRatio = float64(s1.FailoverRatio)
return nil
}
type TargetPoolAggregatedList struct {
// Id: [Output Only] Unique identifier for the resource. Defined by the
// server.
@ -28191,6 +28286,30 @@ func (r *InstanceGroupManagersService) ListManagedInstances(project string, zone
return c
}
// Filter sets the optional parameter "filter":
func (c *InstanceGroupManagersListManagedInstancesCall) Filter(filter string) *InstanceGroupManagersListManagedInstancesCall {
c.urlParams_.Set("filter", filter)
return c
}
// MaxResults sets the optional parameter "maxResults":
func (c *InstanceGroupManagersListManagedInstancesCall) MaxResults(maxResults int64) *InstanceGroupManagersListManagedInstancesCall {
c.urlParams_.Set("maxResults", fmt.Sprint(maxResults))
return c
}
// OrderBy sets the optional parameter "order_by":
func (c *InstanceGroupManagersListManagedInstancesCall) OrderBy(orderBy string) *InstanceGroupManagersListManagedInstancesCall {
c.urlParams_.Set("order_by", orderBy)
return c
}
// PageToken sets the optional parameter "pageToken":
func (c *InstanceGroupManagersListManagedInstancesCall) PageToken(pageToken string) *InstanceGroupManagersListManagedInstancesCall {
c.urlParams_.Set("pageToken", pageToken)
return c
}
// Fields allows partial responses to be retrieved. See
// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
// for more information.
@ -28285,12 +28404,32 @@ func (c *InstanceGroupManagersListManagedInstancesCall) Do(opts ...googleapi.Cal
// "instanceGroupManager"
// ],
// "parameters": {
// "filter": {
// "location": "query",
// "type": "string"
// },
// "instanceGroupManager": {
// "description": "The name of the managed instance group.",
// "location": "path",
// "required": true,
// "type": "string"
// },
// "maxResults": {
// "default": "500",
// "format": "uint32",
// "location": "query",
// "maximum": "500",
// "minimum": "0",
// "type": "integer"
// },
// "order_by": {
// "location": "query",
// "type": "string"
// },
// "pageToken": {
// "location": "query",
// "type": "string"
// },
// "project": {
// "description": "Project ID for this request.",
// "location": "path",
@ -40213,6 +40352,30 @@ func (r *RegionInstanceGroupManagersService) ListManagedInstances(project string
return c
}
// Filter sets the optional parameter "filter":
func (c *RegionInstanceGroupManagersListManagedInstancesCall) Filter(filter string) *RegionInstanceGroupManagersListManagedInstancesCall {
c.urlParams_.Set("filter", filter)
return c
}
// MaxResults sets the optional parameter "maxResults":
func (c *RegionInstanceGroupManagersListManagedInstancesCall) MaxResults(maxResults int64) *RegionInstanceGroupManagersListManagedInstancesCall {
c.urlParams_.Set("maxResults", fmt.Sprint(maxResults))
return c
}
// OrderBy sets the optional parameter "order_by":
func (c *RegionInstanceGroupManagersListManagedInstancesCall) OrderBy(orderBy string) *RegionInstanceGroupManagersListManagedInstancesCall {
c.urlParams_.Set("order_by", orderBy)
return c
}
// PageToken sets the optional parameter "pageToken":
func (c *RegionInstanceGroupManagersListManagedInstancesCall) PageToken(pageToken string) *RegionInstanceGroupManagersListManagedInstancesCall {
c.urlParams_.Set("pageToken", pageToken)
return c
}
// Fields allows partial responses to be retrieved. See
// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
// for more information.
@ -40307,12 +40470,32 @@ func (c *RegionInstanceGroupManagersListManagedInstancesCall) Do(opts ...googlea
// "instanceGroupManager"
// ],
// "parameters": {
// "filter": {
// "location": "query",
// "type": "string"
// },
// "instanceGroupManager": {
// "description": "The name of the managed instance group.",
// "location": "path",
// "required": true,
// "type": "string"
// },
// "maxResults": {
// "default": "500",
// "format": "uint32",
// "location": "query",
// "maximum": "500",
// "minimum": "0",
// "type": "integer"
// },
// "order_by": {
// "location": "query",
// "type": "string"
// },
// "pageToken": {
// "location": "query",
// "type": "string"
// },
// "project": {
// "description": "Project ID for this request.",
// "location": "path",

57
vendor/google.golang.org/api/gensupport/jsonfloat.go generated vendored Normal file
View File

@ -0,0 +1,57 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gensupport
import (
"encoding/json"
"errors"
"fmt"
"math"
)
// JSONFloat64 is a float64 that supports proper unmarshaling of special float
// values in JSON, according to
// https://developers.google.com/protocol-buffers/docs/proto3#json. Although
// that is a proto-to-JSON spec, it applies to all Google APIs.
//
// The jsonpb package
// (https://github.com/golang/protobuf/blob/master/jsonpb/jsonpb.go) has
// similar functionality, but only for direct translation from proto messages
// to JSON.
type JSONFloat64 float64
func (f *JSONFloat64) UnmarshalJSON(data []byte) error {
var ff float64
if err := json.Unmarshal(data, &ff); err == nil {
*f = JSONFloat64(ff)
return nil
}
var s string
if err := json.Unmarshal(data, &s); err == nil {
switch s {
case "NaN":
ff = math.NaN()
case "Infinity":
ff = math.Inf(1)
case "-Infinity":
ff = math.Inf(-1)
default:
return fmt.Errorf("google.golang.org/api/internal: bad float string %q", s)
}
*f = JSONFloat64(ff)
return nil
}
return errors.New("google.golang.org/api/internal: data not float or string")
}

View File

@ -1,3 +1,17 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gensupport
import (

12
vendor/vendor.json vendored
View File

@ -2781,10 +2781,10 @@
"revisionTime": "2016-11-27T23:54:21Z"
},
{
"checksumSHA1": "wIomSQkpEQ6U71+hZStbt7+ttOQ=",
"checksumSHA1": "a3xBCGUHttHW7+VrTk8bqxU6pOY=",
"path": "google.golang.org/api/compute/v1",
"revision": "3cc2e591b550923a2c5f0ab5a803feda924d5823",
"revisionTime": "2016-11-27T23:54:21Z"
"revision": "8840436417f044055c16fc7e4018f08484f52839",
"revisionTime": "2017-01-13T00:03:17Z"
},
{
"checksumSHA1": "qt8Mg1hYm0ApdGODreQxBh30FDU=",
@ -2799,10 +2799,10 @@
"revisionTime": "2016-11-27T23:54:21Z"
},
{
"checksumSHA1": "I1JSeU5OMapl+4s2VrnBkMon3Bw=",
"checksumSHA1": "a1NkriuA/uk+Wv6yCFzxz4LIaDg=",
"path": "google.golang.org/api/gensupport",
"revision": "3cc2e591b550923a2c5f0ab5a803feda924d5823",
"revisionTime": "2016-11-27T23:54:21Z"
"revision": "8840436417f044055c16fc7e4018f08484f52839",
"revisionTime": "2017-01-13T00:03:17Z"
},
{
"checksumSHA1": "yQREK/OWrz9PLljbr127+xFk6J0=",

View File

@ -89,9 +89,9 @@ The following arguments are supported:
* `region` - (Optional) The Region in which the created address should reside.
If it is not provided, the provider region is used.
* `session_affinity` - (Optional) How to distribute load. Options are "NONE" (no
affinity), "CLIENT\_IP" (hash of the source/dest addresses / ports), and
"GENERATED\_COOKIE" (distribute load using a generated session cookie).
* `session_affinity` - (Optional) How to distribute load. Options are `NONE` (no
affinity), `CLIENT_IP` (hash of the source/dest addresses / ports), and
`GENERATED_COOKIE` (distribute load using a generated session cookie).
* `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`.

View File

@ -20,6 +20,7 @@ resource "google_compute_region_backend_service" "foobar" {
description = "Hello World 1234"
protocol = "TCP"
timeout_sec = 10
session_affinity = "CLIENT_IP"
backend {
group = "${google_compute_instance_group_manager.foo.instance_group}"
@ -84,6 +85,10 @@ The following arguments are supported:
* `protocol` - (Optional) The protocol for incoming requests. Defaults to
`HTTP`.
* `session_affinity` - (Optional) How to distribute load. Options are `NONE` (no
affinity), `CLIENT_IP`, `CLIENT_IP_PROTO`, or `CLIENT_IP_PORT_PROTO`.
Defaults to `NONE`.
* `region` - (Optional) The Region in which the created address should reside.
If it is not provided, the provider region is used.