mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-15 01:53:51 -06:00
provider/google: Some more collision avoidance test tweaks
This commit is contained in:
parent
65fb52a38e
commit
c4aff4a585
@ -4,12 +4,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"google.golang.org/api/compute/v1"
|
"google.golang.org/api/compute/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeDisk_basic(t *testing.T) {
|
func TestAccComputeDisk_basic(t *testing.T) {
|
||||||
|
diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
||||||
var disk compute.Disk
|
var disk compute.Disk
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
@ -18,7 +20,7 @@ func TestAccComputeDisk_basic(t *testing.T) {
|
|||||||
CheckDestroy: testAccCheckComputeDiskDestroy,
|
CheckDestroy: testAccCheckComputeDiskDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeDisk_basic,
|
Config: testAccComputeDisk_basic(diskName),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckComputeDiskExists(
|
testAccCheckComputeDiskExists(
|
||||||
"google_compute_disk.foobar", &disk),
|
"google_compute_disk.foobar", &disk),
|
||||||
@ -75,11 +77,13 @@ func testAccCheckComputeDiskExists(n string, disk *compute.Disk) resource.TestCh
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccComputeDisk_basic = `
|
func testAccComputeDisk_basic(diskName string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_disk" "foobar" {
|
resource "google_compute_disk" "foobar" {
|
||||||
name = "terraform-test"
|
name = "%s"
|
||||||
image = "debian-7-wheezy-v20140814"
|
image = "debian-7-wheezy-v20140814"
|
||||||
size = 50
|
size = 50
|
||||||
type = "pd-ssd"
|
type = "pd-ssd"
|
||||||
zone = "us-central1-a"
|
zone = "us-central1-a"
|
||||||
}`
|
}`, diskName)
|
||||||
|
}
|
||||||
|
@ -4,11 +4,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeForwardingRule_basic(t *testing.T) {
|
func TestAccComputeForwardingRule_basic(t *testing.T) {
|
||||||
|
poolName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
||||||
|
ruleName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
@ -16,7 +19,7 @@ func TestAccComputeForwardingRule_basic(t *testing.T) {
|
|||||||
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
|
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeForwardingRule_basic,
|
Config: testAccComputeForwardingRule_basic(poolName, ruleName),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckComputeForwardingRuleExists(
|
testAccCheckComputeForwardingRuleExists(
|
||||||
"google_compute_forwarding_rule.foobar"),
|
"google_compute_forwarding_rule.foobar"),
|
||||||
@ -27,6 +30,9 @@ func TestAccComputeForwardingRule_basic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccComputeForwardingRule_ip(t *testing.T) {
|
func TestAccComputeForwardingRule_ip(t *testing.T) {
|
||||||
|
addrName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
||||||
|
poolName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
||||||
|
ruleName := fmt.Sprintf("tf-%s", acctest.RandString(10))
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
@ -34,7 +40,7 @@ func TestAccComputeForwardingRule_ip(t *testing.T) {
|
|||||||
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
|
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeForwardingRule_ip,
|
Config: testAccComputeForwardingRule_ip(addrName, poolName, ruleName),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckComputeForwardingRuleExists(
|
testAccCheckComputeForwardingRuleExists(
|
||||||
"google_compute_forwarding_rule.foobar"),
|
"google_compute_forwarding_rule.foobar"),
|
||||||
@ -89,36 +95,40 @@ func testAccCheckComputeForwardingRuleExists(n string) resource.TestCheckFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccComputeForwardingRule_basic = `
|
func testAccComputeForwardingRule_basic(poolName, ruleName string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_target_pool" "foobar-tp" {
|
resource "google_compute_target_pool" "foobar-tp" {
|
||||||
description = "Resource created for Terraform acceptance testing"
|
description = "Resource created for Terraform acceptance testing"
|
||||||
instances = ["us-central1-a/foo", "us-central1-b/bar"]
|
instances = ["us-central1-a/foo", "us-central1-b/bar"]
|
||||||
name = "terraform-test"
|
name = "%s"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar" {
|
resource "google_compute_forwarding_rule" "foobar" {
|
||||||
description = "Resource created for Terraform acceptance testing"
|
description = "Resource created for Terraform acceptance testing"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
name = "terraform-test"
|
name = "%s"
|
||||||
port_range = "80-81"
|
port_range = "80-81"
|
||||||
target = "${google_compute_target_pool.foobar-tp.self_link}"
|
target = "${google_compute_target_pool.foobar-tp.self_link}"
|
||||||
}
|
}
|
||||||
`
|
`, poolName, ruleName)
|
||||||
|
}
|
||||||
|
|
||||||
const testAccComputeForwardingRule_ip = `
|
func testAccComputeForwardingRule_ip(addrName, poolName, ruleName string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_address" "foo" {
|
resource "google_compute_address" "foo" {
|
||||||
name = "foo"
|
name = "%s"
|
||||||
}
|
}
|
||||||
resource "google_compute_target_pool" "foobar-tp" {
|
resource "google_compute_target_pool" "foobar-tp" {
|
||||||
description = "Resource created for Terraform acceptance testing"
|
description = "Resource created for Terraform acceptance testing"
|
||||||
instances = ["us-central1-a/foo", "us-central1-b/bar"]
|
instances = ["us-central1-a/foo", "us-central1-b/bar"]
|
||||||
name = "terraform-test"
|
name = "%s"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar" {
|
resource "google_compute_forwarding_rule" "foobar" {
|
||||||
description = "Resource created for Terraform acceptance testing"
|
description = "Resource created for Terraform acceptance testing"
|
||||||
ip_address = "${google_compute_address.foo.address}"
|
ip_address = "${google_compute_address.foo.address}"
|
||||||
ip_protocol = "TCP"
|
ip_protocol = "TCP"
|
||||||
name = "terraform-test"
|
name = "%s"
|
||||||
port_range = "80-81"
|
port_range = "80-81"
|
||||||
target = "${google_compute_target_pool.foobar-tp.self_link}"
|
target = "${google_compute_target_pool.foobar-tp.self_link}"
|
||||||
}
|
}
|
||||||
`
|
`, addrName, poolName, ruleName)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user