Skip to content

Commit

Permalink
Add support for INTERNAL_SELF_MANAGED backend service
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
slevenick authored and modular-magician committed May 24, 2019
1 parent 216cd16 commit dd3ee2c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion google/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func resourceComputeBackendService() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"EXTERNAL", ""}, false),
ValidateFunc: validation.StringInSlice([]string{"EXTERNAL", "INTERNAL_SELF_MANAGED", ""}, false),
Default: "EXTERNAL",
},
"port_name": {
Expand Down
55 changes: 55 additions & 0 deletions google/resource_compute_global_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ func resourceComputeGlobalForwardingRule() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"IPV4", "IPV6", ""}, false),
},
"load_balancing_scheme": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"INTERNAL_SELF_MANAGED", "EXTERNAL", ""}, false),
Default: "EXTERNAL",
},
"network": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"port_range": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -126,12 +140,24 @@ func resourceComputeGlobalForwardingRuleCreate(d *schema.ResourceData, meta inte
} else if v, ok := d.GetOkExists("ip_version"); !isEmptyValue(reflect.ValueOf(ipVersionProp)) && (ok || !reflect.DeepEqual(v, ipVersionProp)) {
obj["ipVersion"] = ipVersionProp
}
loadBalancingSchemeProp, err := expandComputeGlobalForwardingRuleLoadBalancingScheme(d.Get("load_balancing_scheme"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("load_balancing_scheme"); !isEmptyValue(reflect.ValueOf(loadBalancingSchemeProp)) && (ok || !reflect.DeepEqual(v, loadBalancingSchemeProp)) {
obj["loadBalancingScheme"] = loadBalancingSchemeProp
}
nameProp, err := expandComputeGlobalForwardingRuleName(d.Get("name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
networkProp, err := expandComputeGlobalForwardingRuleNetwork(d.Get("network"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("network"); !isEmptyValue(reflect.ValueOf(networkProp)) && (ok || !reflect.DeepEqual(v, networkProp)) {
obj["network"] = networkProp
}
portRangeProp, err := expandComputeGlobalForwardingRulePortRange(d.Get("port_range"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -221,9 +247,15 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf
if err := d.Set("ip_version", flattenComputeGlobalForwardingRuleIpVersion(res["ipVersion"], d)); err != nil {
return fmt.Errorf("Error reading GlobalForwardingRule: %s", err)
}
if err := d.Set("load_balancing_scheme", flattenComputeGlobalForwardingRuleLoadBalancingScheme(res["loadBalancingScheme"], d)); err != nil {
return fmt.Errorf("Error reading GlobalForwardingRule: %s", err)
}
if err := d.Set("name", flattenComputeGlobalForwardingRuleName(res["name"], d)); err != nil {
return fmt.Errorf("Error reading GlobalForwardingRule: %s", err)
}
if err := d.Set("network", flattenComputeGlobalForwardingRuleNetwork(res["network"], d)); err != nil {
return fmt.Errorf("Error reading GlobalForwardingRule: %s", err)
}
if err := d.Set("port_range", flattenComputeGlobalForwardingRulePortRange(res["portRange"], d)); err != nil {
return fmt.Errorf("Error reading GlobalForwardingRule: %s", err)
}
Expand Down Expand Up @@ -355,10 +387,21 @@ func flattenComputeGlobalForwardingRuleIpVersion(v interface{}, d *schema.Resour
return v
}

func flattenComputeGlobalForwardingRuleLoadBalancingScheme(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenComputeGlobalForwardingRuleName(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenComputeGlobalForwardingRuleNetwork(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return v
}
return ConvertSelfLinkToV1(v.(string))
}

func flattenComputeGlobalForwardingRulePortRange(v interface{}, d *schema.ResourceData) interface{} {
return v
}
Expand All @@ -383,10 +426,22 @@ func expandComputeGlobalForwardingRuleIpVersion(v interface{}, d TerraformResour
return v, nil
}

func expandComputeGlobalForwardingRuleLoadBalancingScheme(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeGlobalForwardingRuleName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeGlobalForwardingRuleNetwork(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("networks", v.(string), "project", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for network: %s", err)
}
return f.RelativeLink(), nil
}

func expandComputeGlobalForwardingRulePortRange(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/compute_backend_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The following arguments are supported:
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)
Expand Down Expand Up @@ -118,8 +119,8 @@ The following arguments are supported:
(Optional)
Indicates whether the backend service will be used with internal or
external load balancing. A backend service created for one type of
load balancing cannot be used with the other. Must be `EXTERNAL` for
a global backend service. Defaults to `EXTERNAL`.
load balancing cannot be used with the other. Must be `EXTERNAL` or
`INTERNAL_SELF_MANAGED` for a global backend service. Defaults to `EXTERNAL`.

* `port_name` -
(Optional)
Expand Down

0 comments on commit dd3ee2c

Please sign in to comment.