2014-11-20 17:40:17 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2016-01-05 18:26:44 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2014-11-20 17:40:17 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
)
|
|
|
|
|
2018-05-14 17:07:59 +00:00
|
|
|
func TestAccComputeForwardingRule_update(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-01-05 18:26:44 +00:00
|
|
|
poolName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
|
|
|
ruleName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
2014-11-20 17:40:17 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2016-01-05 18:26:44 +00:00
|
|
|
Config: testAccComputeForwardingRule_basic(poolName, ruleName),
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2018-05-14 17:07:59 +00:00
|
|
|
ResourceName: "google_compute_forwarding_rule.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2018-05-14 17:07:59 +00:00
|
|
|
Config: testAccComputeForwardingRule_update(poolName, ruleName),
|
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2017-12-19 20:43:30 +00:00
|
|
|
ResourceName: "google_compute_forwarding_rule.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeForwardingRule_ip(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-01-05 18:26:44 +00:00
|
|
|
addrName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
|
|
|
poolName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
|
|
|
ruleName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
2014-11-20 17:40:17 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2016-01-05 18:26:44 +00:00
|
|
|
Config: testAccComputeForwardingRule_ip(addrName, poolName, ruleName),
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2017-12-19 20:43:30 +00:00
|
|
|
ResourceName: "google_compute_forwarding_rule.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-06-05 19:35:44 +00:00
|
|
|
func TestAccComputeForwardingRule_networkTier(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
poolName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
|
|
|
ruleName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2018-06-05 19:35:44 +00:00
|
|
|
Config: testAccComputeForwardingRule_networkTier(poolName, ruleName),
|
|
|
|
},
|
|
|
|
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2018-06-05 19:35:44 +00:00
|
|
|
ResourceName: "google_compute_forwarding_rule.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-01-05 18:26:44 +00:00
|
|
|
func testAccComputeForwardingRule_basic(poolName, ruleName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2018-05-14 17:07:59 +00:00
|
|
|
resource "google_compute_target_pool" "foo-tp" {
|
2016-01-05 18:26:44 +00:00
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
instances = ["us-central1-a/foo", "us-central1-b/bar"]
|
2018-05-14 17:07:59 +00:00
|
|
|
name = "foo-%s"
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
resource "google_compute_forwarding_rule" "foobar" {
|
2016-01-05 18:26:44 +00:00
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
ip_protocol = "UDP"
|
|
|
|
name = "%s"
|
|
|
|
port_range = "80-81"
|
2018-05-14 17:07:59 +00:00
|
|
|
target = "${google_compute_target_pool.foo-tp.self_link}"
|
2016-01-05 18:26:44 +00:00
|
|
|
}
|
|
|
|
`, poolName, ruleName)
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 17:07:59 +00:00
|
|
|
func testAccComputeForwardingRule_update(poolName, ruleName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_target_pool" "foo-tp" {
|
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
instances = ["us-central1-a/foo", "us-central1-b/bar"]
|
|
|
|
name = "foo-%s"
|
|
|
|
}
|
|
|
|
resource "google_compute_target_pool" "bar-tp" {
|
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
instances = ["us-central1-a/foo", "us-central1-b/bar"]
|
|
|
|
name = "bar-%s"
|
|
|
|
}
|
|
|
|
resource "google_compute_forwarding_rule" "foobar" {
|
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
ip_protocol = "UDP"
|
|
|
|
name = "%s"
|
|
|
|
port_range = "80-81"
|
|
|
|
target = "${google_compute_target_pool.bar-tp.self_link}"
|
|
|
|
}
|
|
|
|
`, poolName, poolName, ruleName)
|
|
|
|
}
|
|
|
|
|
2016-01-05 18:26:44 +00:00
|
|
|
func testAccComputeForwardingRule_ip(addrName, poolName, ruleName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2014-11-20 17:40:17 +00:00
|
|
|
resource "google_compute_address" "foo" {
|
2016-01-05 18:26:44 +00:00
|
|
|
name = "%s"
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
resource "google_compute_target_pool" "foobar-tp" {
|
2016-01-05 18:26:44 +00:00
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
instances = ["us-central1-a/foo", "us-central1-b/bar"]
|
|
|
|
name = "%s"
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
resource "google_compute_forwarding_rule" "foobar" {
|
2016-01-05 18:26:44 +00:00
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
ip_address = "${google_compute_address.foo.address}"
|
|
|
|
ip_protocol = "TCP"
|
|
|
|
name = "%s"
|
|
|
|
port_range = "80-81"
|
|
|
|
target = "${google_compute_target_pool.foobar-tp.self_link}"
|
|
|
|
}
|
|
|
|
`, addrName, poolName, ruleName)
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
2016-11-18 16:08:26 +00:00
|
|
|
|
2018-06-05 19:35:44 +00:00
|
|
|
func testAccComputeForwardingRule_networkTier(poolName, ruleName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_target_pool" "foobar-tp" {
|
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
instances = ["us-central1-a/foo", "us-central1-b/bar"]
|
|
|
|
name = "%s"
|
|
|
|
}
|
|
|
|
resource "google_compute_forwarding_rule" "foobar" {
|
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
ip_protocol = "UDP"
|
|
|
|
name = "%s"
|
|
|
|
port_range = "80-81"
|
|
|
|
target = "${google_compute_target_pool.foobar-tp.self_link}"
|
|
|
|
|
|
|
|
network_tier = "STANDARD"
|
|
|
|
}
|
|
|
|
`, poolName, ruleName)
|
|
|
|
}
|