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 <magic-modules@google.com>
  • Loading branch information
Ty Larrabee authored and modular-magician committed Jan 13, 2020
1 parent bcc7e11 commit 652b227
Show file tree
Hide file tree
Showing 6 changed files with 624 additions and 12 deletions.
10 changes: 3 additions & 7 deletions google-beta/resource_compute_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,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 @@ -794,10 +793,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 flattenComputeForwardingRuleAllowGlobalAccess(v interface{}, d *schema.ResourceData) interface{} {
Expand Down
212 changes: 212 additions & 0 deletions google-beta/resource_compute_forwarding_rule_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,218 @@ resource "google_compute_subnetwork" "default" {
`, context)
}

func TestAccComputeForwardingRule_forwardingRuleHttpLbExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(10),
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccComputeForwardingRule_forwardingRuleHttpLbExample(context),
},
},
})
}

func testAccComputeForwardingRule_forwardingRuleHttpLbExample(context map[string]interface{}) string {
return Nprintf(`
// 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%{random_suffix}"
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%{random_suffix}"
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%{random_suffix}"
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%{random_suffix}"
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%{random_suffix}"
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%{random_suffix}"
http_health_check {
port_specification = "USE_SERVING_PORT"
}
}
resource "google_compute_firewall" "fw1" {
provider = google-beta
name = "website-fw%{random_suffix}-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%{random_suffix}-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%{random_suffix}-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%{random_suffix}-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%{random_suffix}"
auto_create_subnetworks = false
routing_mode = "REGIONAL"
}
resource "google_compute_subnetwork" "default" {
provider = google-beta
name = "website-net%{random_suffix}-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%{random_suffix}-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"
}
`, context)
}

func testAccCheckComputeForwardingRuleDestroy(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_forwarding_rule" {
Expand Down
7 changes: 5 additions & 2 deletions google-beta/resource_compute_region_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,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 All @@ -657,6 +659,7 @@ Provide this property when you create the resource.`,
},
"failover": {
Type: schema.TypeBool,
Computed: true,
Optional: true,
Description: `This field designates whether this is a failover backend. More
than one failover backend can be configured for a given RegionBackendService.`,
Expand Down Expand Up @@ -1850,7 +1853,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
108 changes: 108 additions & 0 deletions google-beta/resource_compute_region_backend_service_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,114 @@ resource "google_compute_health_check" "health_check" {
`, context)
}

func TestAccComputeRegionBackendService_regionBackendServiceBalancingModeExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(10),
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckComputeRegionBackendServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccComputeRegionBackendService_regionBackendServiceBalancingModeExample(context),
},
},
})
}

func testAccComputeRegionBackendService_regionBackendServiceBalancingModeExample(context map[string]interface{}) string {
return Nprintf(`
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%{random_suffix}"
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%{random_suffix}"
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%{random_suffix}"
http_health_check {
port_specification = "USE_SERVING_PORT"
}
}
resource "google_compute_network" "default" {
provider = google-beta
name = "net%{random_suffix}"
auto_create_subnetworks = false
routing_mode = "REGIONAL"
}
resource "google_compute_subnetwork" "default" {
provider = google-beta
name = "net%{random_suffix}-default"
ip_cidr_range = "10.1.2.0/24"
region = "us-central1"
network = google_compute_network.default.self_link
}
`, context)
}

func testAccCheckComputeRegionBackendServiceDestroy(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_region_backend_service" {
Expand Down
Loading

0 comments on commit 652b227

Please sign in to comment.