mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 09:06:44 +00:00
159 lines
4.2 KiB
Go
159 lines
4.2 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccComputeAddress_basic(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckComputeAddressDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccComputeAddress_basic(acctest.RandString(10)),
|
|
},
|
|
resource.TestStep{
|
|
ResourceName: "google_compute_address.foobar",
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccComputeAddress_networkTier(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckComputeAddressDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccComputeAddress_networkTier(acctest.RandString(10)),
|
|
},
|
|
resource.TestStep{
|
|
ResourceName: "google_compute_address.foobar",
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccComputeAddress_internal(t *testing.T) {
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckComputeAddressDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccComputeAddress_internal(acctest.RandString(10)),
|
|
},
|
|
resource.TestStep{
|
|
ResourceName: "google_compute_address.internal",
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
},
|
|
|
|
resource.TestStep{
|
|
ResourceName: "google_compute_address.internal_with_subnet",
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
},
|
|
|
|
resource.TestStep{
|
|
ResourceName: "google_compute_address.internal_with_subnet_and_address",
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckComputeAddressDestroy(s *terraform.State) error {
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "google_compute_address" {
|
|
continue
|
|
}
|
|
|
|
addressId, err := parseComputeAddressId(rs.Primary.ID, config)
|
|
|
|
_, err = config.clientCompute.Addresses.Get(
|
|
config.Project, addressId.Region, addressId.Name).Do()
|
|
if err == nil {
|
|
return fmt.Errorf("Address still exists")
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccComputeAddress_basic(i string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_compute_address" "foobar" {
|
|
name = "address-test-%s"
|
|
}`, i)
|
|
}
|
|
|
|
func testAccComputeAddress_internal(i string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_compute_address" "internal" {
|
|
name = "address-test-internal-%s"
|
|
address_type = "INTERNAL"
|
|
region = "us-east1"
|
|
}
|
|
|
|
resource "google_compute_network" "default" {
|
|
name = "network-test-%s"
|
|
}
|
|
|
|
resource "google_compute_subnetwork" "foo" {
|
|
name = "subnetwork-test-%s"
|
|
ip_cidr_range = "10.0.0.0/16"
|
|
region = "us-east1"
|
|
network = "${google_compute_network.default.self_link}"
|
|
}
|
|
|
|
resource "google_compute_address" "internal_with_subnet" {
|
|
name = "address-test-internal-with-subnet-%s"
|
|
subnetwork = "${google_compute_subnetwork.foo.self_link}"
|
|
address_type = "INTERNAL"
|
|
region = "us-east1"
|
|
}
|
|
|
|
// We can't test the address alone, because we don't know what IP range the
|
|
// default subnetwork uses.
|
|
resource "google_compute_address" "internal_with_subnet_and_address" {
|
|
name = "address-test-internal-with-subnet-and-address-%s"
|
|
subnetwork = "${google_compute_subnetwork.foo.self_link}"
|
|
address_type = "INTERNAL"
|
|
address = "10.0.42.42"
|
|
region = "us-east1"
|
|
}`,
|
|
i, // google_compute_address.internal name
|
|
i, // google_compute_network.default name
|
|
i, // google_compute_subnetwork.foo name
|
|
i, // google_compute_address.internal_with_subnet_name
|
|
i, // google_compute_address.internal_with_subnet_and_address name
|
|
)
|
|
}
|
|
|
|
func testAccComputeAddress_networkTier(i string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_compute_address" "foobar" {
|
|
name = "address-test-%s"
|
|
network_tier = "STANDARD"
|
|
}`, i)
|
|
}
|