mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-06 18:51:13 +00:00
Autogenerate {{Resource}}Destroy in tests. (#2317)
This commit is contained in:
parent
b321a6260b
commit
ed2fa7266d
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeAddress_addressBasicExample(t *testing.T) {
|
func TestAccComputeAddress_addressBasicExample(t *testing.T) {
|
||||||
@ -147,3 +148,25 @@ resource "google_compute_instance" "instance_with_ip" {
|
|||||||
`, val, val,
|
`, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeAddress_basic(t *testing.T) {
|
func TestAccComputeAddress_basic(t *testing.T) {
|
||||||
@ -79,26 +78,6 @@ func TestAccComputeAddress_internal(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
func testAccComputeAddress_basic(i string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_address" "foobar" {
|
resource "google_compute_address" "foobar" {
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeAutoscaler_autoscalerBasicExample(t *testing.T) {
|
func TestAccComputeAutoscaler_autoscalerBasicExample(t *testing.T) {
|
||||||
@ -104,3 +105,25 @@ data "google_compute_image" "debian_9" {
|
|||||||
`, val, val, val, val,
|
`, val, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeAutoscalerDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_autoscaler" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/autoscalers/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeAutoscaler still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -104,26 +104,6 @@ func TestAccComputeAutoscaler_multicondition(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeAutoscalerDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_autoscaler" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
idParts := strings.Split(rs.Primary.ID, "/")
|
|
||||||
zone, name := idParts[0], idParts[1]
|
|
||||||
_, err := config.clientCompute.Autoscalers.Get(
|
|
||||||
config.Project, zone, name).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Autoscaler still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeAutoscalerExists(n string, ascaler *compute.Autoscaler) resource.TestCheckFunc {
|
func testAccCheckComputeAutoscalerExists(n string, ascaler *compute.Autoscaler) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeBackendBucket_backendBucketBasicExample(t *testing.T) {
|
func TestAccComputeBackendBucket_backendBucketBasicExample(t *testing.T) {
|
||||||
@ -58,3 +59,25 @@ resource "google_storage_bucket" "image_bucket" {
|
|||||||
`, val, val,
|
`, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeBackendBucketDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_backend_bucket" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/backendBuckets/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeBackendBucket still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -78,24 +78,6 @@ func TestAccComputeBackendBucket_basicModified(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeBackendBucketDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_backend_bucket" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.BackendBuckets.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Backend bucket %s still exists", rs.Primary.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeBackendBucketExists(n string, svc *compute.BackendBucket) resource.TestCheckFunc {
|
func testAccCheckComputeBackendBucketExists(n string, svc *compute.BackendBucket) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeFirewall_firewallBasicExample(t *testing.T) {
|
func TestAccComputeFirewall_firewallBasicExample(t *testing.T) {
|
||||||
@ -66,3 +67,25 @@ resource "google_compute_network" "default" {
|
|||||||
`, val, val,
|
`, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeFirewallDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_firewall" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/firewalls/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeFirewall still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -283,24 +283,6 @@ func TestAccComputeFirewall_disabled(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeFirewallDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_firewall" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.Firewalls.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Firewall still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeFirewallExists(n string, firewall *compute.Firewall) resource.TestCheckFunc {
|
func testAccCheckComputeFirewallExists(n string, firewall *compute.Firewall) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeForwardingRule_forwardingRuleBasicExample(t *testing.T) {
|
func TestAccComputeForwardingRule_forwardingRuleBasicExample(t *testing.T) {
|
||||||
@ -56,3 +57,25 @@ resource "google_compute_target_pool" "default" {
|
|||||||
`, val, val,
|
`, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeForwardingRuleDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_forwarding_rule" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeForwardingRule still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeForwardingRule_update(t *testing.T) {
|
func TestAccComputeForwardingRule_update(t *testing.T) {
|
||||||
@ -142,24 +141,6 @@ func TestAccComputeForwardingRule_networkTier(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeForwardingRuleDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_forwarding_rule" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.ForwardingRules.Get(
|
|
||||||
config.Project, config.Region, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("ForwardingRule still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccComputeForwardingRule_basic(poolName, ruleName string) string {
|
func testAccComputeForwardingRule_basic(poolName, ruleName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_target_pool" "foo-tp" {
|
resource "google_compute_target_pool" "foo-tp" {
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeGlobalAddress_globalAddressBasicExample(t *testing.T) {
|
func TestAccComputeGlobalAddress_globalAddressBasicExample(t *testing.T) {
|
||||||
@ -50,3 +51,25 @@ resource "google_compute_global_address" "default" {
|
|||||||
`, val,
|
`, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeGlobalAddressDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_global_address" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/addresses/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeGlobalAddress still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -87,24 +87,6 @@ func TestAccComputeGlobalAddress_internal(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeGlobalAddressDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_global_address" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.GlobalAddresses.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Address still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeGlobalAddressExists(n string, addr *compute.Address) resource.TestCheckFunc {
|
func testAccCheckComputeGlobalAddressExists(n string, addr *compute.Address) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeHealthCheck_healthCheckBasicExample(t *testing.T) {
|
func TestAccComputeHealthCheck_healthCheckBasicExample(t *testing.T) {
|
||||||
@ -57,3 +58,25 @@ resource "google_compute_health_check" "internal-health-check" {
|
|||||||
`, val,
|
`, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeHealthCheckDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_health_check" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/healthChecks/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeHealthCheck still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -215,24 +215,6 @@ func TestAccComputeHealthCheck_tcpAndSsl_shouldFail(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeHealthCheckDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_health_check" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.HealthChecks.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("HealthCheck %s still exists", rs.Primary.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeHealthCheckExists(n string, healthCheck *compute.HealthCheck) resource.TestCheckFunc {
|
func testAccCheckComputeHealthCheckExists(n string, healthCheck *compute.HealthCheck) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeHttpHealthCheck_httpHealthCheckBasicExample(t *testing.T) {
|
func TestAccComputeHttpHealthCheck_httpHealthCheckBasicExample(t *testing.T) {
|
||||||
@ -54,3 +55,25 @@ resource "google_compute_http_health_check" "default" {
|
|||||||
`, val,
|
`, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeHttpHealthCheckDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_http_health_check" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpHealthChecks/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeHttpHealthCheck still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -80,24 +80,6 @@ func TestAccComputeHttpHealthCheck_update(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeHttpHealthCheckDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_http_health_check" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.HttpHealthChecks.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("HttpHealthCheck still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeHttpHealthCheckExists(n string, healthCheck *compute.HttpHealthCheck) resource.TestCheckFunc {
|
func testAccCheckComputeHttpHealthCheckExists(n string, healthCheck *compute.HttpHealthCheck) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeHttpsHealthCheck_httpsHealthCheckBasicExample(t *testing.T) {
|
func TestAccComputeHttpsHealthCheck_httpsHealthCheckBasicExample(t *testing.T) {
|
||||||
@ -54,3 +55,25 @@ resource "google_compute_https_health_check" "default" {
|
|||||||
`, val,
|
`, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeHttpsHealthCheckDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_https_health_check" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpsHealthChecks/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeHttpsHealthCheck still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -80,24 +80,6 @@ func TestAccComputeHttpsHealthCheck_update(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeHttpsHealthCheckDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_https_health_check" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.HttpsHealthChecks.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("HttpsHealthCheck still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeHttpsHealthCheckExists(n string, healthCheck *compute.HttpsHealthCheck) resource.TestCheckFunc {
|
func testAccCheckComputeHttpsHealthCheckExists(n string, healthCheck *compute.HttpsHealthCheck) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeRegionAutoscaler_regionAutoscalerBasicExample(t *testing.T) {
|
func TestAccComputeRegionAutoscaler_regionAutoscalerBasicExample(t *testing.T) {
|
||||||
@ -104,3 +105,25 @@ data "google_compute_image" "debian_9" {
|
|||||||
`, val, val, val, val,
|
`, val, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeRegionAutoscalerDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_region_autoscaler" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/autoscalers/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeRegionAutoscaler still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -73,25 +73,6 @@ func TestAccComputeRegionAutoscaler_update(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeRegionAutoscalerDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_region_autoscaler" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
idParts := strings.Split(rs.Primary.ID, "/")
|
|
||||||
region, name := idParts[0], idParts[1]
|
|
||||||
_, err := config.clientCompute.RegionAutoscalers.Get(config.Project, region, name).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Autoscaler still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeRegionAutoscalerExists(n string, ascaler *compute.Autoscaler) resource.TestCheckFunc {
|
func testAccCheckComputeRegionAutoscalerExists(n string, ascaler *compute.Autoscaler) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeRegionDisk_regionDiskBasicExample(t *testing.T) {
|
func TestAccComputeRegionDisk_regionDiskBasicExample(t *testing.T) {
|
||||||
@ -69,3 +70,25 @@ resource "google_compute_snapshot" "snapdisk" {
|
|||||||
`, val, val, val,
|
`, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeRegionDiskDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_region_disk" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/disks/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeRegionDisk still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -175,24 +175,6 @@ func TestAccComputeRegionDisk_deleteDetach(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeRegionDiskDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_region_disk" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientComputeBeta.RegionDisks.Get(
|
|
||||||
config.Project, rs.Primary.Attributes["region"], rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("RegionDisk still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeRegionDiskExists(n string, disk *computeBeta.Disk) resource.TestCheckFunc {
|
func testAccCheckComputeRegionDiskExists(n string, disk *computeBeta.Disk) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
p := getTestProjectFromEnv()
|
p := getTestProjectFromEnv()
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeRoute_routeBasicExample(t *testing.T) {
|
func TestAccComputeRoute_routeBasicExample(t *testing.T) {
|
||||||
@ -58,3 +59,25 @@ resource "google_compute_network" "default" {
|
|||||||
`, val, val,
|
`, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeRouteDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_route" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/routes/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeRoute still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -95,24 +95,6 @@ func TestAccComputeRoute_hopInstance(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeRouteDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_route" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.Routes.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Route still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeRouteExists(n string, route *compute.Route) resource.TestCheckFunc {
|
func testAccCheckComputeRouteExists(n string, route *compute.Route) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeRouter_routerBasicExample(t *testing.T) {
|
func TestAccComputeRouter_routerBasicExample(t *testing.T) {
|
||||||
@ -67,3 +68,25 @@ resource "google_compute_network" "foobar" {
|
|||||||
`, val, val,
|
`, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeRouterDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_router" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/routers/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeRouter still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeRouter_basic(t *testing.T) {
|
func TestAccComputeRouter_basic(t *testing.T) {
|
||||||
@ -112,39 +111,6 @@ func TestAccComputeRouter_update(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeRouterDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
routersService := config.clientCompute.Routers
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_router" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
project, err := getTestProject(rs.Primary, config)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
region, err := getTestRegion(rs.Primary, config)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
name := rs.Primary.Attributes["name"]
|
|
||||||
|
|
||||||
_, err = routersService.Get(project, region, name).Do()
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Error, Router %s in region %s still exists",
|
|
||||||
name, region)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccComputeRouterBasic(testId, resourceRegion string) string {
|
func testAccComputeRouterBasic(testId, resourceRegion string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_network" "foobar" {
|
resource "google_compute_network" "foobar" {
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeSslCertificate_sslCertificateBasicExample(t *testing.T) {
|
func TestAccComputeSslCertificate_sslCertificateBasicExample(t *testing.T) {
|
||||||
@ -198,3 +199,25 @@ resource "google_compute_http_health_check" "default" {
|
|||||||
`, val, val, val, val,
|
`, val, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeSslCertificateDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_ssl_certificate" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/sslCertificates/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeSslCertificate still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -84,24 +84,6 @@ func TestAccComputeSslCertificate_name_prefix(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeSslCertificateDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_ssl_certificate" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.SslCertificates.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("SslCertificate still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeSslCertificateExists(n string) resource.TestCheckFunc {
|
func testAccCheckComputeSslCertificateExists(n string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeSslPolicy_sslPolicyBasicExample(t *testing.T) {
|
func TestAccComputeSslPolicy_sslPolicyBasicExample(t *testing.T) {
|
||||||
@ -64,3 +65,25 @@ resource "google_compute_ssl_policy" "custom-ssl-policy" {
|
|||||||
`, val, val, val,
|
`, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeSslPolicyDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_ssl_policy" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/sslPolicies/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeSslPolicy still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -308,24 +308,6 @@ func testAccCheckComputeSslPolicyExists(n string, sslPolicy *compute.SslPolicy)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeSslPolicyDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_ssl_policy" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.SslPolicies.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("SSL Policy still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccComputeSslPolicyBasic(resourceName string) string {
|
func testAccComputeSslPolicyBasic(resourceName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_ssl_policy" "basic" {
|
resource "google_compute_ssl_policy" "basic" {
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeSubnetwork_subnetworkBasicExample(t *testing.T) {
|
func TestAccComputeSubnetwork_subnetworkBasicExample(t *testing.T) {
|
||||||
@ -62,3 +63,25 @@ resource "google_compute_network" "custom-test" {
|
|||||||
`, val, val,
|
`, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeSubnetworkDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_subnetwork" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/subnetworks/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeSubnetwork still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -216,25 +216,6 @@ func TestAccComputeSubnetwork_flowLogs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeSubnetworkDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_subnetwork" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
region, subnet_name := splitSubnetID(rs.Primary.ID)
|
|
||||||
_, err := config.clientCompute.Subnetworks.Get(
|
|
||||||
config.Project, region, subnet_name).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Network still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeSubnetworkExists(n string, subnetwork *compute.Subnetwork) resource.TestCheckFunc {
|
func testAccCheckComputeSubnetworkExists(n string, subnetwork *compute.Subnetwork) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeTargetHttpProxy_targetHttpProxyBasicExample(t *testing.T) {
|
func TestAccComputeTargetHttpProxy_targetHttpProxyBasicExample(t *testing.T) {
|
||||||
@ -87,3 +88,25 @@ resource "google_compute_http_health_check" "default" {
|
|||||||
`, val, val, val, val,
|
`, val, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeTargetHttpProxyDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_target_http_proxy" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpProxies/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeTargetHttpProxy still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -72,24 +72,6 @@ func TestAccComputeTargetHttpProxy_update(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeTargetHttpProxyDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_target_http_proxy" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.TargetHttpProxies.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("TargetHttpProxy still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeTargetHttpProxyExists(n string) resource.TestCheckFunc {
|
func testAccCheckComputeTargetHttpProxyExists(n string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeTargetHttpsProxy_targetHttpsProxyBasicExample(t *testing.T) {
|
func TestAccComputeTargetHttpsProxy_targetHttpsProxyBasicExample(t *testing.T) {
|
||||||
@ -96,3 +97,25 @@ resource "google_compute_http_health_check" "default" {
|
|||||||
`, val, val, val, val, val,
|
`, val, val, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeTargetHttpsProxyDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_target_https_proxy" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeTargetHttpsProxy still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -78,24 +78,6 @@ func TestAccComputeTargetHttpsProxy_update(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeTargetHttpsProxyDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_target_https_proxy" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.TargetHttpsProxies.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("TargetHttpsProxy still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeTargetHttpsProxyExists(n string, proxy *compute.TargetHttpsProxy) resource.TestCheckFunc {
|
func testAccCheckComputeTargetHttpsProxyExists(n string, proxy *compute.TargetHttpsProxy) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeTargetSslProxy_targetSslProxyBasicExample(t *testing.T) {
|
func TestAccComputeTargetSslProxy_targetSslProxyBasicExample(t *testing.T) {
|
||||||
@ -73,3 +74,25 @@ resource "google_compute_health_check" "default" {
|
|||||||
`, val, val, val, val,
|
`, val, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeTargetSslProxyDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_target_ssl_proxy" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetSslProxies/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeTargetSslProxy still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -69,24 +69,6 @@ func TestAccComputeTargetSslProxy_update(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeTargetSslProxyDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_target_ssl_proxy" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.TargetSslProxies.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("TargetSslProxy still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeTargetSslProxy(n, proxyHeader, sslCert string) resource.TestCheckFunc {
|
func testAccCheckComputeTargetSslProxy(n, proxyHeader, sslCert string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeTargetTcpProxy_targetTcpProxyBasicExample(t *testing.T) {
|
func TestAccComputeTargetTcpProxy_targetTcpProxyBasicExample(t *testing.T) {
|
||||||
@ -69,3 +70,25 @@ resource "google_compute_health_check" "default" {
|
|||||||
`, val, val, val,
|
`, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeTargetTcpProxyDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_target_tcp_proxy" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetTcpProxies/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeTargetTcpProxy still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -67,24 +67,6 @@ func TestAccComputeTargetTcpProxy_update(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeTargetTcpProxyDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_target_tcp_proxy" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := config.clientCompute.TargetTcpProxies.Get(
|
|
||||||
config.Project, rs.Primary.ID).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("TargetTcpProxy still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeTargetTcpProxyExists(n string) resource.TestCheckFunc {
|
func testAccCheckComputeTargetTcpProxyExists(n string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeVpnGateway_targetVpnGatewayBasicExample(t *testing.T) {
|
func TestAccComputeVpnGateway_targetVpnGatewayBasicExample(t *testing.T) {
|
||||||
@ -105,3 +106,25 @@ resource "google_compute_route" "route1" {
|
|||||||
`, val, val, val, val, val, val, val, val,
|
`, val, val, val, val, val, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeVpnGatewayDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_vpn_gateway" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/targetVpnGateways/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeVpnGateway still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -32,31 +32,6 @@ func TestAccComputeVpnGateway_basic(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeVpnGatewayDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
project := config.Project
|
|
||||||
|
|
||||||
vpnGatewaysService := compute.NewTargetVpnGatewaysService(config.clientCompute)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_network" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
region := rs.Primary.Attributes["region"]
|
|
||||||
name := rs.Primary.Attributes["name"]
|
|
||||||
|
|
||||||
_, err := vpnGatewaysService.Get(project, region, name).Do()
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Error, VPN Gateway %s in region %s still exists",
|
|
||||||
name, region)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckComputeVpnGatewayExists(n string) resource.TestCheckFunc {
|
func testAccCheckComputeVpnGatewayExists(n string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeVpnTunnel_vpnTunnelBasicExample(t *testing.T) {
|
func TestAccComputeVpnTunnel_vpnTunnelBasicExample(t *testing.T) {
|
||||||
@ -106,3 +107,25 @@ resource "google_compute_route" "route1" {
|
|||||||
`, val, val, val, val, val, val, val, val,
|
`, val, val, val, val, val, val, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeVpnTunnelDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_compute_vpn_tunnel" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/vpnTunnels/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("ComputeVpnTunnel still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -6,9 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
|
|
||||||
"google.golang.org/api/compute/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeVpnTunnel_basic(t *testing.T) {
|
func TestAccComputeVpnTunnel_basic(t *testing.T) {
|
||||||
@ -75,31 +72,6 @@ func TestAccComputeVpnTunnel_defaultTrafficSelectors(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeVpnTunnelDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
project := config.Project
|
|
||||||
|
|
||||||
vpnTunnelsService := compute.NewVpnTunnelsService(config.clientCompute)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_compute_network" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
region := rs.Primary.Attributes["region"]
|
|
||||||
name := rs.Primary.Attributes["name"]
|
|
||||||
|
|
||||||
_, err := vpnTunnelsService.Get(project, region, name).Do()
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Error, VPN Tunnel %s in region %s still exists",
|
|
||||||
name, region)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccComputeVpnTunnel_basic() string {
|
func testAccComputeVpnTunnel_basic() string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_network" "foobar" {
|
resource "google_compute_network" "foobar" {
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccRedisInstance_redisInstanceBasicExample(t *testing.T) {
|
func TestAccRedisInstance_redisInstanceBasicExample(t *testing.T) {
|
||||||
@ -102,3 +103,25 @@ resource "google_compute_network" "auto-network" {
|
|||||||
`, val, val,
|
`, val, val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckRedisInstanceDestroy(s *terraform.State) error {
|
||||||
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
if rs.Type != "google_redis_instance" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
url, err := replaceVarsForTest(rs, "https://redis.googleapis.com/v1/projects/{{project}}/locations/{{region}}/instances/{{name}}")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = sendRequest(config, "GET", url, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("RedisInstance still exists at %s", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -2,12 +2,10 @@ package google
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccRedisInstance_basic(t *testing.T) {
|
func TestAccRedisInstance_basic(t *testing.T) {
|
||||||
@ -85,31 +83,6 @@ func TestAccRedisInstance_full(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckRedisInstanceDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_redis_instance" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
redisIdParts := strings.Split(rs.Primary.ID, "/")
|
|
||||||
if len(redisIdParts) != 3 {
|
|
||||||
return fmt.Errorf("Unexpected resource ID %s, expected {project}/{region}/{name}", rs.Primary.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
project, region, inst := redisIdParts[0], redisIdParts[1], redisIdParts[2]
|
|
||||||
|
|
||||||
name := fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, region, inst)
|
|
||||||
_, err := config.clientRedis.Projects.Locations.Get(name).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Redis instance still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccRedisInstance_basic(name string) string {
|
func testAccRedisInstance_basic(name string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_redis_instance" "test" {
|
resource "google_redis_instance" "test" {
|
||||||
|
@ -1,9 +1,53 @@
|
|||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// This function isn't a test of transport.go; instead, it is used as an alternative
|
||||||
|
// to replaceVars inside tests.
|
||||||
|
func replaceVarsForTest(rs *terraform.ResourceState, linkTmpl string) (string, error) {
|
||||||
|
re := regexp.MustCompile("{{([[:word:]]+)}}")
|
||||||
|
var project, region, zone string
|
||||||
|
|
||||||
|
if strings.Contains(linkTmpl, "{{project}}") {
|
||||||
|
project = rs.Primary.Attributes["project"]
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(linkTmpl, "{{region}}") {
|
||||||
|
region = rs.Primary.Attributes["region"]
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(linkTmpl, "{{zone}}") {
|
||||||
|
zone = rs.Primary.Attributes["zone"]
|
||||||
|
}
|
||||||
|
|
||||||
|
replaceFunc := func(s string) string {
|
||||||
|
m := re.FindStringSubmatch(s)[1]
|
||||||
|
if m == "project" {
|
||||||
|
return project
|
||||||
|
}
|
||||||
|
if m == "region" {
|
||||||
|
return region
|
||||||
|
}
|
||||||
|
if m == "zone" {
|
||||||
|
return zone
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := rs.Primary.Attributes[m]; ok {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return re.ReplaceAllStringFunc(linkTmpl, replaceFunc), nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestReplaceVars(t *testing.T) {
|
func TestReplaceVars(t *testing.T) {
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
Template string
|
Template string
|
||||||
|
Loading…
Reference in New Issue
Block a user