Skip to content

Commit

Permalink
Allow target to accept other resource types
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
Ty Larrabee authored and modular-magician committed Jan 13, 2020
1 parent c7f8985 commit 2b22e06
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 12 deletions.
10 changes: 3 additions & 7 deletions google/resource_compute_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,8 @@ subnetwork must be specified.`,
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: compareSelfLinkRelativePaths,
Description: `This field is only used for EXTERNAL load balancing.
A reference to a TargetPool resource to receive the matched traffic.
This target must live in the same region as the forwarding rule.
Description: `The URL of the target resource to receive the matched traffic.
The target must live in the same region as the forwarding rule.
The forwarded traffic must be of a type appropriate to the target
object.`,
},
Expand Down Expand Up @@ -650,10 +649,7 @@ func flattenComputeForwardingRuleSubnetwork(v interface{}, d *schema.ResourceDat
}

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

func flattenComputeForwardingRuleAllPorts(v interface{}, d *schema.ResourceData) interface{} {
Expand Down
6 changes: 4 additions & 2 deletions google/resource_compute_region_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,15 @@ partial URL.`,
},
"capacity_scaler": {
Type: schema.TypeFloat,
Computed: true,
Optional: true,
Description: `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].`,
Default: 1.0,
},
"description": {
Type: schema.TypeString,
Expand Down Expand Up @@ -811,7 +813,7 @@ func expandComputeRegionBackendServiceBackend(v interface{}, d TerraformResource
transformedCapacityScaler, err := expandComputeRegionBackendServiceBackendCapacityScaler(original["capacity_scaler"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedCapacityScaler); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["capacityScaler"] = transformedCapacityScaler
}

Expand Down
203 changes: 200 additions & 3 deletions website/docs/r/compute_forwarding_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,204 @@ resource "google_compute_subnetwork" "default" {
network = google_compute_network.default.self_link
}
```
<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=forwarding_rule_http_lb&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 - Forwarding Rule Http Lb


```hcl
// Forwarding rule for Internal Load Balancing
resource "google_compute_forwarding_rule" "default" {
provider = google-beta
depends_on = [google_compute_subnetwork.proxy]
name = "website-forwarding-rule"
region = "us-central1"
ip_protocol = "TCP"
load_balancing_scheme = "INTERNAL_MANAGED"
port_range = "80"
target = google_compute_region_target_http_proxy.default.self_link
network = google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.default.self_link
network_tier = "PREMIUM"
}
resource "google_compute_region_target_http_proxy" "default" {
provider = google-beta
region = "us-central1"
name = "website-proxy"
url_map = google_compute_region_url_map.default.self_link
}
resource "google_compute_region_url_map" "default" {
provider = google-beta
region = "us-central1"
name = "website-map"
default_service = google_compute_region_backend_service.default.self_link
}
resource "google_compute_region_backend_service" "default" {
provider = google-beta
load_balancing_scheme = "INTERNAL_MANAGED"
backend {
group = google_compute_region_instance_group_manager.rigm.instance_group
balancing_mode = "UTILIZATION"
}
region = "us-central1"
name = "website-backend"
protocol = "HTTP"
timeout_sec = 10
health_checks = [google_compute_region_health_check.default.self_link]
}
data "google_compute_image" "debian_image" {
provider = google-beta
family = "debian-9"
project = "debian-cloud"
}
resource "google_compute_region_instance_group_manager" "rigm" {
provider = google-beta
region = "us-central1"
name = "rigm-internal"
version {
instance_template = google_compute_instance_template.instance_template.self_link
name = "primary"
}
base_instance_name = "internal-glb"
target_size = 1
}
resource "google_compute_instance_template" "instance_template" {
provider = google-beta
name = "template-website-backend"
machine_type = "n1-standard-1"
network_interface {
network = google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.default.self_link
}
disk {
source_image = data.google_compute_image.debian_image.self_link
auto_delete = true
boot = true
}
tags = ["allow-ssh", "load-balanced-backend"]
}
resource "google_compute_region_health_check" "default" {
depends_on = [google_compute_firewall.fw4]
provider = google-beta
region = "us-central1"
name = "website-hc"
http_health_check {
port_specification = "USE_SERVING_PORT"
}
}
resource "google_compute_firewall" "fw1" {
provider = google-beta
name = "website-fw-1"
network = google_compute_network.default.self_link
source_ranges = ["10.1.2.0/24"]
allow {
protocol = "tcp"
}
allow {
protocol = "udp"
}
allow {
protocol = "icmp"
}
direction = "INGRESS"
}
resource "google_compute_firewall" "fw2" {
depends_on = [google_compute_firewall.fw1]
provider = google-beta
name = "website-fw-2"
network = google_compute_network.default.self_link
source_ranges = ["0.0.0.0/0"]
allow {
protocol = "tcp"
ports = ["22"]
}
target_tags = ["allow-ssh"]
direction = "INGRESS"
}
resource "google_compute_firewall" "fw3" {
depends_on = [google_compute_firewall.fw2]
provider = google-beta
name = "website-fw-3"
network = google_compute_network.default.self_link
source_ranges = ["130.211.0.0/22", "35.191.0.0/16"]
allow {
protocol = "tcp"
}
target_tags = ["load-balanced-backend"]
direction = "INGRESS"
}
resource "google_compute_firewall" "fw4" {
depends_on = [google_compute_firewall.fw3]
provider = google-beta
name = "website-fw-4"
network = google_compute_network.default.self_link
source_ranges = ["10.129.0.0/26"]
target_tags = ["load-balanced-backend"]
allow {
protocol = "tcp"
ports = ["80"]
}
allow {
protocol = "tcp"
ports = ["443"]
}
allow {
protocol = "tcp"
ports = ["8000"]
}
direction = "INGRESS"
}
resource "google_compute_network" "default" {
provider = google-beta
name = "website-net"
auto_create_subnetworks = false
routing_mode = "REGIONAL"
}
resource "google_compute_subnetwork" "default" {
provider = google-beta
name = "website-net-default"
ip_cidr_range = "10.1.2.0/24"
region = "us-central1"
network = google_compute_network.default.self_link
}
resource "google_compute_subnetwork" "proxy" {
provider = google-beta
name = "website-net-proxy"
ip_cidr_range = "10.129.0.0/26"
region = "us-central1"
network = google_compute_network.default.self_link
purpose = "INTERNAL_HTTPS_LOAD_BALANCER"
role = "ACTIVE"
}
```

## Argument Reference

Expand Down Expand Up @@ -266,9 +464,8 @@ The following arguments are supported:

* `target` -
(Optional)
This field is only used for EXTERNAL load balancing.
A reference to a TargetPool resource to receive the matched traffic.
This target must live in the same region as the forwarding rule.
The URL of the target resource to receive the matched traffic.
The target must live in the same region as the forwarding rule.
The forwarded traffic must be of a type appropriate to the target
object.

Expand Down
96 changes: 96 additions & 0 deletions website/docs/r/compute_region_backend_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,100 @@ resource "google_compute_health_check" "health_check" {
}
}
```
<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=region_backend_service_balancing_mode&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 - Region Backend Service Balancing Mode


```hcl
resource "google_compute_region_backend_service" "default" {
provider = google-beta
load_balancing_scheme = "INTERNAL_MANAGED"
backend {
group = google_compute_region_instance_group_manager.rigm.instance_group
balancing_mode = "UTILIZATION"
}
region = "us-central1"
name = "region-backend-service"
protocol = "HTTP"
timeout_sec = 10
health_checks = [google_compute_region_health_check.default.self_link]
}
data "google_compute_image" "debian_image" {
provider = google-beta
family = "debian-9"
project = "debian-cloud"
}
resource "google_compute_region_instance_group_manager" "rigm" {
provider = google-beta
region = "us-central1"
name = "rigm-internal"
version {
instance_template = google_compute_instance_template.instance_template.self_link
name = "primary"
}
base_instance_name = "internal-glb"
target_size = 1
}
resource "google_compute_instance_template" "instance_template" {
provider = google-beta
name = "template-region-backend-service"
machine_type = "n1-standard-1"
network_interface {
network = google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.default.self_link
}
disk {
source_image = data.google_compute_image.debian_image.self_link
auto_delete = true
boot = true
}
tags = ["allow-ssh", "load-balanced-backend"]
}
resource "google_compute_region_health_check" "default" {
provider = google-beta
region = "us-central1"
name = "health-check"
http_health_check {
port_specification = "USE_SERVING_PORT"
}
}
resource "google_compute_network" "default" {
provider = google-beta
name = "net"
auto_create_subnetworks = false
routing_mode = "REGIONAL"
}
resource "google_compute_subnetwork" "default" {
provider = google-beta
name = "net-default"
ip_cidr_range = "10.1.2.0/24"
region = "us-central1"
network = google_compute_network.default.self_link
}
```

## Argument Reference

Expand Down Expand Up @@ -216,6 +310,8 @@ The `backend` block supports:
(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].

Expand Down

0 comments on commit 2b22e06

Please sign in to comment.