github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/azure/resource_azure_hosted_service_test.go (about) 1 package azure 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 TestAccAzureHostedServiceBasic(t *testing.T) { 12 name := "azure_hosted_service.foo" 13 14 resource.Test(t, resource.TestCase{ 15 PreCheck: func() { testAccPreCheck(t) }, 16 Providers: testAccProviders, 17 CheckDestroy: testAccCheckAzureHostedServiceDestroyed, 18 Steps: []resource.TestStep{ 19 resource.TestStep{ 20 Config: testAccAzureHostedServiceBasic, 21 Check: resource.ComposeTestCheckFunc( 22 testAccCheckAzureHostedServiceExists(name), 23 resource.TestCheckResourceAttr(name, "name", "terraform-testing-service"), 24 resource.TestCheckResourceAttr(name, "location", "North Europe"), 25 resource.TestCheckResourceAttr(name, "ephemeral_contents", "false"), 26 resource.TestCheckResourceAttr(name, "description", "very discriptive"), 27 resource.TestCheckResourceAttr(name, "label", "very identifiable"), 28 ), 29 }, 30 }, 31 }) 32 } 33 34 func TestAccAzureHostedServiceUpdate(t *testing.T) { 35 name := "azure_hosted_service.foo" 36 37 resource.Test(t, resource.TestCase{ 38 PreCheck: func() { testAccPreCheck(t) }, 39 Providers: testAccProviders, 40 CheckDestroy: testAccCheckAzureHostedServiceDestroyed, 41 Steps: []resource.TestStep{ 42 resource.TestStep{ 43 Config: testAccAzureHostedServiceBasic, 44 Check: resource.ComposeTestCheckFunc( 45 testAccCheckAzureHostedServiceExists(name), 46 resource.TestCheckResourceAttr(name, "name", "terraform-testing-service"), 47 resource.TestCheckResourceAttr(name, "location", "North Europe"), 48 resource.TestCheckResourceAttr(name, "ephemeral_contents", "false"), 49 resource.TestCheckResourceAttr(name, "description", "very discriptive"), 50 resource.TestCheckResourceAttr(name, "label", "very identifiable"), 51 ), 52 }, 53 54 resource.TestStep{ 55 Config: testAccAzureHostedServiceUpdate, 56 Check: resource.ComposeTestCheckFunc( 57 testAccCheckAzureHostedServiceExists(name), 58 resource.TestCheckResourceAttr(name, "name", "terraform-testing-service"), 59 resource.TestCheckResourceAttr(name, "location", "North Europe"), 60 resource.TestCheckResourceAttr(name, "ephemeral_contents", "true"), 61 resource.TestCheckResourceAttr(name, "description", "very discriptive"), 62 resource.TestCheckResourceAttr(name, "label", "very identifiable"), 63 ), 64 }, 65 }, 66 }) 67 } 68 69 func testAccCheckAzureHostedServiceExists(name string) resource.TestCheckFunc { 70 return func(s *terraform.State) error { 71 resource, ok := s.RootModule().Resources[name] 72 if !ok { 73 return fmt.Errorf("Hosted Service resource not found.") 74 } 75 76 if resource.Primary.ID == "" { 77 return fmt.Errorf("Resource's ID is not set.") 78 } 79 80 hostedServiceClient := testAccProvider.Meta().(*Client).hostedServiceClient 81 _, err := hostedServiceClient.GetHostedService(resource.Primary.ID) 82 return err 83 } 84 } 85 86 func testAccCheckAzureHostedServiceDestroyed(s *terraform.State) error { 87 hostedServiceClient := testAccProvider.Meta().(*Client).hostedServiceClient 88 89 for _, resource := range s.RootModule().Resources { 90 if resource.Type != "azure_hosted_service" { 91 continue 92 } 93 94 if resource.Primary.ID == "" { 95 return fmt.Errorf("No Azure Hosted Service Resource found.") 96 } 97 98 _, err := hostedServiceClient.GetHostedService(resource.Primary.ID) 99 100 return testAccResourceDestroyedErrorFilter("Hosted Service", err) 101 } 102 103 return nil 104 } 105 106 const testAccAzureHostedServiceBasic = ` 107 resource "azure_hosted_service" "foo" { 108 name = "terraform-testing-service" 109 location = "North Europe" 110 ephemeral_contents = false 111 description = "very discriptive" 112 label = "very identifiable" 113 } 114 ` 115 const testAccAzureHostedServiceUpdate = ` 116 resource "azure_hosted_service" "foo" { 117 name = "terraform-testing-service" 118 location = "North Europe" 119 ephemeral_contents = true 120 description = "very discriptive" 121 label = "very identifiable" 122 } 123 `