2018-09-17 19:31:57 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This file is automatically generated by Magic Modules and manual
|
|
|
|
// changes will be clobbered when the file is regenerated.
|
|
|
|
//
|
|
|
|
// Please read more about how to change this file in
|
|
|
|
// .github/CONTRIBUTING.md.
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
2018-10-26 18:03:43 +00:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2018-09-17 19:31:57 +00:00
|
|
|
)
|
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func TestAccComputeAddress_addressBasicExample(t *testing.T) {
|
2018-09-17 19:31:57 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeAddressDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2018-11-09 21:02:03 +00:00
|
|
|
Config: testAccComputeAddress_addressBasicExample(acctest.RandString(10)),
|
2018-09-17 19:31:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_compute_address.ip_address",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func testAccComputeAddress_addressBasicExample(val string) string {
|
2018-09-17 19:31:57 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_address" "ip_address" {
|
|
|
|
name = "my-address-%s"
|
|
|
|
}
|
|
|
|
`, val,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func TestAccComputeAddress_addressWithSubnetworkExample(t *testing.T) {
|
2018-09-17 19:31:57 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeAddressDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2018-11-09 21:02:03 +00:00
|
|
|
Config: testAccComputeAddress_addressWithSubnetworkExample(acctest.RandString(10)),
|
2018-09-17 19:31:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_compute_address.internal_with_subnet_and_address",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func testAccComputeAddress_addressWithSubnetworkExample(val string) string {
|
2018-09-17 19:31:57 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "default" {
|
|
|
|
name = "my-network-%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "default" {
|
|
|
|
name = "my-subnet-%s"
|
|
|
|
ip_cidr_range = "10.0.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.default.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_address" "internal_with_subnet_and_address" {
|
|
|
|
name = "my-internal-address-%s"
|
|
|
|
subnetwork = "${google_compute_subnetwork.default.self_link}"
|
|
|
|
address_type = "INTERNAL"
|
|
|
|
address = "10.0.42.42"
|
|
|
|
region = "us-central1"
|
|
|
|
}
|
|
|
|
`, val, val, val,
|
|
|
|
)
|
|
|
|
}
|
2018-10-05 20:05:58 +00:00
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func TestAccComputeAddress_instanceWithIpExample(t *testing.T) {
|
2018-10-05 20:05:58 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeAddressDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2018-11-09 21:02:03 +00:00
|
|
|
Config: testAccComputeAddress_instanceWithIpExample(acctest.RandString(10)),
|
2018-10-05 20:05:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_compute_address.static",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func testAccComputeAddress_instanceWithIpExample(val string) string {
|
2018-10-05 20:05:58 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_address" "static" {
|
|
|
|
name = "ipv4-address-%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
data "google_compute_image" "debian_image" {
|
|
|
|
family = "debian-9"
|
|
|
|
project = "debian-cloud"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "instance_with_ip" {
|
|
|
|
name = "vm-instance-%s"
|
|
|
|
machine_type = "f1-micro"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "${data.google_compute_image.debian_image.self_link}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config {
|
|
|
|
nat_ip = "${google_compute_address.static.address}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, val, val,
|
|
|
|
)
|
|
|
|
}
|
2018-10-26 18:03:43 +00:00
|
|
|
|
|
|
|
func testAccCheckComputeAddressDestroy(s *terraform.State) error {
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "google_compute_address" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/addresses/{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = sendRequest(config, "GET", url, nil)
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("ComputeAddress still exists at %s", url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|