mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
105 lines
2.7 KiB
Go
105 lines
2.7 KiB
Go
![]() |
// ----------------------------------------------------------------------------
|
||
|
//
|
||
|
// *** 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"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||
|
"github.com/hashicorp/terraform/helper/resource"
|
||
|
"github.com/hashicorp/terraform/terraform"
|
||
|
)
|
||
|
|
||
|
func TestAccComputeTargetInstance_targetInstanceBasicExample(t *testing.T) {
|
||
|
t.Parallel()
|
||
|
|
||
|
context := map[string]interface{}{
|
||
|
"random_suffix": acctest.RandString(10),
|
||
|
}
|
||
|
|
||
|
resource.Test(t, resource.TestCase{
|
||
|
PreCheck: func() { testAccPreCheck(t) },
|
||
|
Providers: testAccProviders,
|
||
|
CheckDestroy: testAccCheckComputeTargetInstanceDestroy,
|
||
|
Steps: []resource.TestStep{
|
||
|
{
|
||
|
Config: testAccComputeTargetInstance_targetInstanceBasicExample(context),
|
||
|
},
|
||
|
{
|
||
|
ResourceName: "google_compute_target_instance.default",
|
||
|
ImportState: true,
|
||
|
ImportStateVerify: true,
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func testAccComputeTargetInstance_targetInstanceBasicExample(context map[string]interface{}) string {
|
||
|
return Nprintf(`
|
||
|
resource "google_compute_target_instance" "default" {
|
||
|
name = "target-%{random_suffix}"
|
||
|
instance = "${google_compute_instance.target-vm.self_link}"
|
||
|
}
|
||
|
|
||
|
data "google_compute_image" "vmimage" {
|
||
|
family = "debian-9"
|
||
|
project = "debian-cloud"
|
||
|
}
|
||
|
|
||
|
resource "google_compute_instance" "target-vm" {
|
||
|
name = "target-vm-%{random_suffix}"
|
||
|
machine_type = "n1-standard-1"
|
||
|
zone = "us-central1-a"
|
||
|
|
||
|
boot_disk {
|
||
|
initialize_params{
|
||
|
image = "${data.google_compute_image.vmimage.self_link}"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
network_interface {
|
||
|
network = "default"
|
||
|
}
|
||
|
}
|
||
|
`, context)
|
||
|
}
|
||
|
|
||
|
func testAccCheckComputeTargetInstanceDestroy(s *terraform.State) error {
|
||
|
for name, rs := range s.RootModule().Resources {
|
||
|
if rs.Type != "google_compute_target_instance" {
|
||
|
continue
|
||
|
}
|
||
|
if strings.HasPrefix(name, "data.") {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
config := testAccProvider.Meta().(*Config)
|
||
|
|
||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/targetInstances/{{name}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
_, err = sendRequest(config, "GET", url, nil)
|
||
|
if err == nil {
|
||
|
return fmt.Errorf("ComputeTargetInstance still exists at %s", url)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|