github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/builtin/providers/azurerm/resource_arm_sql_firewall_rule_test.go (about) 1 package azurerm 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/acctest" 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 "github.com/jen20/riviera/sql" 11 ) 12 13 func TestAccAzureRMSqlFirewallRule_basic(t *testing.T) { 14 ri := acctest.RandInt() 15 preConfig := fmt.Sprintf(testAccAzureRMSqlFirewallRule_basic, ri, ri, ri) 16 postConfig := fmt.Sprintf(testAccAzureRMSqlFirewallRule_withUpdates, ri, ri, ri) 17 18 resource.Test(t, resource.TestCase{ 19 PreCheck: func() { testAccPreCheck(t) }, 20 Providers: testAccProviders, 21 CheckDestroy: testCheckAzureRMSqlFirewallRuleDestroy, 22 Steps: []resource.TestStep{ 23 resource.TestStep{ 24 Config: preConfig, 25 Check: resource.ComposeTestCheckFunc( 26 testCheckAzureRMSqlFirewallRuleExists("azurerm_sql_firewall_rule.test"), 27 resource.TestCheckResourceAttr("azurerm_sql_firewall_rule.test", "start_ip_address", "0.0.0.0"), 28 resource.TestCheckResourceAttr("azurerm_sql_firewall_rule.test", "end_ip_address", "255.255.255.255"), 29 ), 30 }, 31 32 resource.TestStep{ 33 Config: postConfig, 34 Check: resource.ComposeTestCheckFunc( 35 testCheckAzureRMSqlFirewallRuleExists("azurerm_sql_firewall_rule.test"), 36 resource.TestCheckResourceAttr("azurerm_sql_firewall_rule.test", "start_ip_address", "10.0.17.62"), 37 resource.TestCheckResourceAttr("azurerm_sql_firewall_rule.test", "end_ip_address", "10.0.17.62"), 38 ), 39 }, 40 }, 41 }) 42 } 43 44 func testCheckAzureRMSqlFirewallRuleExists(name string) resource.TestCheckFunc { 45 return func(s *terraform.State) error { 46 47 rs, ok := s.RootModule().Resources[name] 48 if !ok { 49 return fmt.Errorf("Not found: %s", name) 50 } 51 52 conn := testAccProvider.Meta().(*ArmClient).rivieraClient 53 54 readRequest := conn.NewRequestForURI(rs.Primary.ID) 55 readRequest.Command = &sql.GetFirewallRule{} 56 57 readResponse, err := readRequest.Execute() 58 if err != nil { 59 return fmt.Errorf("Bad: GetFirewallRule: %s", err) 60 } 61 if !readResponse.IsSuccessful() { 62 return fmt.Errorf("Bad: GetFirewallRule: %s", readResponse.Error) 63 } 64 65 return nil 66 } 67 } 68 69 func testCheckAzureRMSqlFirewallRuleDestroy(s *terraform.State) error { 70 conn := testAccProvider.Meta().(*ArmClient).rivieraClient 71 72 for _, rs := range s.RootModule().Resources { 73 if rs.Type != "azurerm_sql_firewall_rule" { 74 continue 75 } 76 77 readRequest := conn.NewRequestForURI(rs.Primary.ID) 78 readRequest.Command = &sql.GetFirewallRule{} 79 80 readResponse, err := readRequest.Execute() 81 if err != nil { 82 return fmt.Errorf("Bad: GetFirewallRule: %s", err) 83 } 84 85 if readResponse.IsSuccessful() { 86 return fmt.Errorf("Bad: SQL Server Firewall Rule still exists: %s", readResponse.Error) 87 } 88 } 89 90 return nil 91 } 92 93 var testAccAzureRMSqlFirewallRule_basic = ` 94 resource "azurerm_resource_group" "test" { 95 name = "acctest_rg_%d" 96 location = "West US" 97 } 98 resource "azurerm_sql_server" "test" { 99 name = "acctestsqlserver%d" 100 resource_group_name = "${azurerm_resource_group.test.name}" 101 location = "West US" 102 version = "12.0" 103 administrator_login = "mradministrator" 104 administrator_login_password = "thisIsDog11" 105 } 106 107 resource "azurerm_sql_firewall_rule" "test" { 108 name = "acctestsqlserver%d" 109 resource_group_name = "${azurerm_resource_group.test.name}" 110 server_name = "${azurerm_sql_server.test.name}" 111 start_ip_address = "0.0.0.0" 112 end_ip_address = "255.255.255.255" 113 } 114 ` 115 116 var testAccAzureRMSqlFirewallRule_withUpdates = ` 117 resource "azurerm_resource_group" "test" { 118 name = "acctest_rg_%d" 119 location = "West US" 120 } 121 resource "azurerm_sql_server" "test" { 122 name = "acctestsqlserver%d" 123 resource_group_name = "${azurerm_resource_group.test.name}" 124 location = "West US" 125 version = "12.0" 126 administrator_login = "mradministrator" 127 administrator_login_password = "thisIsDog11" 128 } 129 130 resource "azurerm_sql_firewall_rule" "test" { 131 name = "acctestsqlserver%d" 132 resource_group_name = "${azurerm_resource_group.test.name}" 133 server_name = "${azurerm_sql_server.test.name}" 134 start_ip_address = "10.0.17.62" 135 end_ip_address = "10.0.17.62" 136 } 137 `