github.com/acm1/terraform@v0.6.2-0.20150729164239-1f314444f45c/builtin/providers/google/resource_container_cluster_test.go (about) 1 package google 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func TestAccContainerCluster_basic(t *testing.T) { 12 resource.Test(t, resource.TestCase{ 13 PreCheck: func() { testAccPreCheck(t) }, 14 Providers: testAccProviders, 15 CheckDestroy: testAccCheckContainerClusterDestroy, 16 Steps: []resource.TestStep{ 17 resource.TestStep{ 18 Config: testAccContainerCluster_basic, 19 Check: resource.ComposeTestCheckFunc( 20 testAccCheckContainerClusterExists( 21 "google_container_cluster.primary"), 22 ), 23 }, 24 }, 25 }) 26 } 27 28 func testAccCheckContainerClusterDestroy(s *terraform.State) error { 29 config := testAccProvider.Meta().(*Config) 30 31 for _, rs := range s.RootModule().Resources { 32 if rs.Type != "google_container_cluster" { 33 continue 34 } 35 36 attributes := rs.Primary.Attributes 37 _, err := config.clientContainer.Projects.Zones.Clusters.Get( 38 config.Project, attributes["zone"], attributes["name"]).Do() 39 if err == nil { 40 return fmt.Errorf("Cluster still exists") 41 } 42 } 43 44 return nil 45 } 46 47 func testAccCheckContainerClusterExists(n string) resource.TestCheckFunc { 48 return func(s *terraform.State) error { 49 rs, ok := s.RootModule().Resources[n] 50 if !ok { 51 return fmt.Errorf("Not found: %s", n) 52 } 53 54 if rs.Primary.ID == "" { 55 return fmt.Errorf("No ID is set") 56 } 57 58 config := testAccProvider.Meta().(*Config) 59 60 attributes := rs.Primary.Attributes 61 found, err := config.clientContainer.Projects.Zones.Clusters.Get( 62 config.Project, attributes["zone"], attributes["name"]).Do() 63 if err != nil { 64 return err 65 } 66 67 if found.Name != attributes["name"] { 68 return fmt.Errorf("Cluster not found") 69 } 70 71 return nil 72 } 73 } 74 75 const testAccContainerCluster_basic = ` 76 resource "google_container_cluster" "primary" { 77 name = "terraform-foo-bar-test" 78 zone = "us-central1-a" 79 initial_node_count = 3 80 81 master_auth { 82 username = "mr.yoda" 83 password = "adoy.rm" 84 } 85 }`