terraform-provider-google/google/resource_compute_firewall_generated_test.go
The Magician 9a683a65e9 Fix generated test name formatting (#2439)
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
2018-12-20 17:22:22 -08:00

92 lines
2.2 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"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccComputeFirewall_firewallBasicExample(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeFirewallDestroy,
Steps: []resource.TestStep{
{
Config: testAccComputeFirewall_firewallBasicExample(acctest.RandString(10)),
},
{
ResourceName: "google_compute_firewall.default",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func testAccComputeFirewall_firewallBasicExample(val string) string {
return fmt.Sprintf(`
resource "google_compute_firewall" "default" {
name = "test-firewall-%s"
network = "${google_compute_network.default.name}"
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
ports = ["80", "8080", "1000-2000"]
}
source_tags = ["web"]
}
resource "google_compute_network" "default" {
name = "test-network-%s"
}
`, 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
}