github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/azure/resource_azure_affinity_group_test.go (about) 1 package azure 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/Azure/azure-sdk-for-go/management" 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func TestAccAzureAffinityGroupBasic(t *testing.T) { 13 name := "azure_affinity_group.foo" 14 15 resource.Test(t, resource.TestCase{ 16 PreCheck: func() { testAccPreCheck(t) }, 17 Providers: testAccProviders, 18 CheckDestroy: testAccCheckAzureAffinityGroupDestroyed, 19 Steps: []resource.TestStep{ 20 resource.TestStep{ 21 Config: testAccAzureAffinityGroupConfig, 22 Check: resource.ComposeTestCheckFunc( 23 testAccCheckAzureAffinityGroupExists(name), 24 resource.TestCheckResourceAttr(name, "name", "terraform-testing-group"), 25 resource.TestCheckResourceAttr(name, "location", "West US"), 26 resource.TestCheckResourceAttr(name, "label", "A nice label."), 27 resource.TestCheckResourceAttr(name, "description", "A nice description."), 28 ), 29 }, 30 }, 31 }) 32 } 33 34 func TestAccAzureAffinityGroupUpdate(t *testing.T) { 35 name := "azure_affinity_group.foo" 36 37 resource.Test(t, resource.TestCase{ 38 PreCheck: func() { testAccPreCheck(t) }, 39 Providers: testAccProviders, 40 CheckDestroy: testAccCheckAzureAffinityGroupDestroyed, 41 Steps: []resource.TestStep{ 42 resource.TestStep{ 43 Config: testAccAzureAffinityGroupConfig, 44 Check: resource.ComposeTestCheckFunc( 45 testAccCheckAzureAffinityGroupExists(name), 46 resource.TestCheckResourceAttr(name, "name", "terraform-testing-group"), 47 resource.TestCheckResourceAttr(name, "location", "West US"), 48 resource.TestCheckResourceAttr(name, "label", "A nice label."), 49 resource.TestCheckResourceAttr(name, "description", "A nice description."), 50 ), 51 }, 52 resource.TestStep{ 53 Config: testAccAzureAffinityGroupUpdateConfig, 54 Check: resource.ComposeTestCheckFunc( 55 testAccCheckAzureAffinityGroupExists(name), 56 resource.TestCheckResourceAttr(name, "name", "terraform-testing-group"), 57 resource.TestCheckResourceAttr(name, "location", "West US"), 58 resource.TestCheckResourceAttr(name, "label", "An even nicer label."), 59 resource.TestCheckResourceAttr(name, "description", "An even nicer description."), 60 ), 61 }, 62 }, 63 }) 64 } 65 66 func testAccCheckAzureAffinityGroupExists(name string) resource.TestCheckFunc { 67 return func(s *terraform.State) error { 68 resource, ok := s.RootModule().Resources[name] 69 if !ok { 70 return fmt.Errorf("Affinity Group resource %q doesn't exist.", name) 71 } 72 73 if resource.Primary.ID == "" { 74 return fmt.Errorf("Affinity Group resource %q ID not set.", name) 75 } 76 77 affinityGroupClient := testAccProvider.Meta().(*Client).affinityGroupClient 78 _, err := affinityGroupClient.GetAffinityGroup(resource.Primary.ID) 79 return err 80 } 81 } 82 83 func testAccCheckAzureAffinityGroupDestroyed(s *terraform.State) error { 84 var err error 85 affinityGroupClient := testAccProvider.Meta().(*Client).affinityGroupClient 86 87 for _, resource := range s.RootModule().Resources { 88 if resource.Type != "azure_affinity_group" { 89 continue 90 } 91 92 if resource.Primary.ID == "" { 93 return fmt.Errorf("Affinity Group resource ID not set.") 94 } 95 96 _, err = affinityGroupClient.GetAffinityGroup(resource.Primary.ID) 97 if !management.IsResourceNotFoundError(err) { 98 return err 99 } 100 } 101 102 return nil 103 } 104 105 const testAccAzureAffinityGroupConfig = ` 106 resource "azure_affinity_group" "foo" { 107 name = "terraform-testing-group" 108 location = "West US" 109 label = "A nice label." 110 description = "A nice description." 111 } 112 ` 113 114 const testAccAzureAffinityGroupUpdateConfig = ` 115 resource "azure_affinity_group" "foo" { 116 name = "terraform-testing-group" 117 location = "West US" 118 label = "An even nicer label." 119 description = "An even nicer description." 120 } 121 `