provider/azurerm: Fix azurerm_route

```
HTTP_PROXY=http://localhost:8888 make testacc TEST=./builtin/providers/azurerm TESTARGS="-run TestAccAzureRMRoute_"
==> Checking that code complies with gofmt requirements...
/Users/James/Code/go/bin/stringer
go generate $(go list ./... | grep -v /vendor/)
2016/06/01 18:28:38 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMRoute_ -timeout 120m
=== RUN   TestAccAzureRMRoute_basic
--- PASS: TestAccAzureRMRoute_basic (98.80s)
=== RUN   TestAccAzureRMRoute_multipleRoutes
--- PASS: TestAccAzureRMRoute_multipleRoutes (130.77s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/azurerm    229.584s
```
This commit is contained in:
James Nugent 2016-06-01 18:34:25 -05:00
parent 9b9ec7bb6c
commit a9b9986e76
3 changed files with 301 additions and 318 deletions

View File

@ -52,8 +52,8 @@ func Provider() terraform.ResourceProvider {
//"azurerm_network_interface": resourceArmNetworkInterface(), //"azurerm_network_interface": resourceArmNetworkInterface(),
//"azurerm_network_security_group": resourceArmNetworkSecurityGroup(), //"azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
//"azurerm_network_security_rule": resourceArmNetworkSecurityRule(), //"azurerm_network_security_rule": resourceArmNetworkSecurityRule(),
"azurerm_public_ip": resourceArmPublicIp(), "azurerm_public_ip": resourceArmPublicIp(),
//"azurerm_route": resourceArmRoute(), "azurerm_route": resourceArmRoute(),
"azurerm_route_table": resourceArmRouteTable(), "azurerm_route_table": resourceArmRouteTable(),
"azurerm_storage_account": resourceArmStorageAccount(), "azurerm_storage_account": resourceArmStorageAccount(),
"azurerm_storage_blob": resourceArmStorageBlob(), "azurerm_storage_blob": resourceArmStorageBlob(),

View File

@ -1,161 +1,144 @@
package azurerm package azurerm
//import ( import (
// "fmt" "fmt"
// "log" "net/http"
// "net/http"
// "time" "github.com/Azure/azure-sdk-for-go/arm/network"
// "github.com/hashicorp/terraform/helper/schema"
// "github.com/Azure/azure-sdk-for-go/arm/network" )
// "github.com/hashicorp/terraform/helper/resource"
// "github.com/hashicorp/terraform/helper/schema" func resourceArmRoute() *schema.Resource {
//) return &schema.Resource{
// Create: resourceArmRouteCreate,
//func resourceArmRoute() *schema.Resource { Read: resourceArmRouteRead,
// return &schema.Resource{ Update: resourceArmRouteCreate,
// Create: resourceArmRouteCreate, Delete: resourceArmRouteDelete,
// Read: resourceArmRouteRead,
// Update: resourceArmRouteCreate, Schema: map[string]*schema.Schema{
// Delete: resourceArmRouteDelete, "name": {
// Type: schema.TypeString,
// Schema: map[string]*schema.Schema{ Required: true,
// "name": &schema.Schema{ ForceNew: true,
// Type: schema.TypeString, },
// Required: true,
// ForceNew: true, "resource_group_name": {
// }, Type: schema.TypeString,
// Required: true,
// "resource_group_name": &schema.Schema{ ForceNew: true,
// Type: schema.TypeString, },
// Required: true,
// ForceNew: true, "route_table_name": {
// }, Type: schema.TypeString,
// Required: true,
// "route_table_name": &schema.Schema{ ForceNew: true,
// Type: schema.TypeString, },
// Required: true,
// ForceNew: true, "address_prefix": {
// }, Type: schema.TypeString,
// Required: true,
// "address_prefix": &schema.Schema{ },
// Type: schema.TypeString,
// Required: true, "next_hop_type": {
// }, Type: schema.TypeString,
// Required: true,
// "next_hop_type": &schema.Schema{ ValidateFunc: validateRouteTableNextHopType,
// Type: schema.TypeString, },
// Required: true,
// ValidateFunc: validateRouteTableNextHopType, "next_hop_in_ip_address": {
// }, Type: schema.TypeString,
// Optional: true,
// "next_hop_in_ip_address": &schema.Schema{ Computed: true,
// Type: schema.TypeString, },
// Optional: true, },
// Computed: true, }
// }, }
// },
// } func resourceArmRouteCreate(d *schema.ResourceData, meta interface{}) error {
//} client := meta.(*ArmClient)
// routesClient := client.routesClient
//func resourceArmRouteCreate(d *schema.ResourceData, meta interface{}) error {
// client := meta.(*ArmClient) name := d.Get("name").(string)
// routesClient := client.routesClient rtName := d.Get("route_table_name").(string)
// resGroup := d.Get("resource_group_name").(string)
// name := d.Get("name").(string)
// rtName := d.Get("route_table_name").(string) addressPrefix := d.Get("address_prefix").(string)
// resGroup := d.Get("resource_group_name").(string) nextHopType := d.Get("next_hop_type").(string)
//
// addressPrefix := d.Get("address_prefix").(string) armMutexKV.Lock(rtName)
// nextHopType := d.Get("next_hop_type").(string) defer armMutexKV.Unlock(rtName)
//
// armMutexKV.Lock(rtName) properties := network.RoutePropertiesFormat{
// defer armMutexKV.Unlock(rtName) AddressPrefix: &addressPrefix,
// NextHopType: network.RouteNextHopType(nextHopType),
// properties := network.RoutePropertiesFormat{ }
// AddressPrefix: &addressPrefix,
// NextHopType: network.RouteNextHopType(nextHopType), if v, ok := d.GetOk("next_hop_in_ip_address"); ok {
// } nextHopInIpAddress := v.(string)
// properties.NextHopIPAddress = &nextHopInIpAddress
// if v, ok := d.GetOk("next_hop_in_ip_address"); ok { }
// nextHopInIpAddress := v.(string)
// properties.NextHopIPAddress = &nextHopInIpAddress route := network.Route{
// } Name: &name,
// Properties: &properties,
// route := network.Route{ }
// Name: &name,
// Properties: &properties, _, err := routesClient.CreateOrUpdate(resGroup, rtName, name, route, make(chan struct{}))
// } if err != nil {
// return err
// resp, err := routesClient.CreateOrUpdate(resGroup, rtName, name, route) }
// if err != nil {
// return err read, err := routesClient.Get(resGroup, rtName, name)
// } if err != nil {
// d.SetId(*resp.ID) return err
// }
// log.Printf("[DEBUG] Waiting for Route (%s) to become available", name) if read.ID == nil {
// stateConf := &resource.StateChangeConf{ return fmt.Errorf("Cannot read Route %s/%s (resource group %s) ID", rtName, name, resGroup)
// Pending: []string{"Accepted", "Updating"}, }
// Target: []string{"Succeeded"}, d.SetId(*read.ID)
// Refresh: routeStateRefreshFunc(client, resGroup, rtName, name),
// Timeout: 10 * time.Minute, return resourceArmRouteRead(d, meta)
// } }
// if _, err := stateConf.WaitForState(); err != nil {
// return fmt.Errorf("Error waiting for Route (%s) to become available: %s", name, err) func resourceArmRouteRead(d *schema.ResourceData, meta interface{}) error {
// } routesClient := meta.(*ArmClient).routesClient
//
// return resourceArmRouteRead(d, meta) id, err := parseAzureResourceID(d.Id())
//} if err != nil {
// return err
//func resourceArmRouteRead(d *schema.ResourceData, meta interface{}) error { }
// routesClient := meta.(*ArmClient).routesClient resGroup := id.ResourceGroup
// rtName := id.Path["routeTables"]
// id, err := parseAzureResourceID(d.Id()) routeName := id.Path["routes"]
// if err != nil {
// return err resp, err := routesClient.Get(resGroup, rtName, routeName)
// } if resp.StatusCode == http.StatusNotFound {
// resGroup := id.ResourceGroup d.SetId("")
// rtName := id.Path["routeTables"] return nil
// routeName := id.Path["routes"] }
// if err != nil {
// resp, err := routesClient.Get(resGroup, rtName, routeName) return fmt.Errorf("Error making Read request on Azure Route %s: %s", routeName, err)
// if resp.StatusCode == http.StatusNotFound { }
// d.SetId("")
// return nil return nil
// } }
// if err != nil {
// return fmt.Errorf("Error making Read request on Azure Route %s: %s", routeName, err) func resourceArmRouteDelete(d *schema.ResourceData, meta interface{}) error {
// } client := meta.(*ArmClient)
// routesClient := client.routesClient
// return nil
//} id, err := parseAzureResourceID(d.Id())
// if err != nil {
//func resourceArmRouteDelete(d *schema.ResourceData, meta interface{}) error { return err
// client := meta.(*ArmClient) }
// routesClient := client.routesClient resGroup := id.ResourceGroup
// rtName := id.Path["routeTables"]
// id, err := parseAzureResourceID(d.Id()) routeName := id.Path["routes"]
// if err != nil {
// return err armMutexKV.Lock(rtName)
// } defer armMutexKV.Unlock(rtName)
// resGroup := id.ResourceGroup
// rtName := id.Path["routeTables"] _, err = routesClient.Delete(resGroup, rtName, routeName, make(chan struct{}))
// routeName := id.Path["routes"]
// return err
// armMutexKV.Lock(rtName) }
// defer armMutexKV.Unlock(rtName)
//
// _, err = routesClient.Delete(resGroup, rtName, routeName)
//
// return err
//}
//
//func routeStateRefreshFunc(client *ArmClient, resourceGroupName string, routeTableName string, routeName string) resource.StateRefreshFunc {
// return func() (interface{}, string, error) {
// res, err := client.routesClient.Get(resourceGroupName, routeTableName, routeName)
// if err != nil {
// return nil, "", fmt.Errorf("Error issuing read request in routeStateRefreshFunc to Azure ARM for route '%s' (RG: '%s') (NSG: '%s'): %s", routeName, resourceGroupName, routeTableName, err)
// }
//
// return res, *res.Properties.ProvisioningState, nil
// }
//}

View File

@ -1,159 +1,159 @@
package azurerm package azurerm
//import ( import (
// "fmt" "fmt"
// "net/http" "net/http"
// "testing" "testing"
//
// "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/acctest"
// "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
// "github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
//) )
//
//func TestAccAzureRMRoute_basic(t *testing.T) { func TestAccAzureRMRoute_basic(t *testing.T) {
//
// ri := acctest.RandInt() ri := acctest.RandInt()
// config := fmt.Sprintf(testAccAzureRMRoute_basic, ri, ri, ri) config := fmt.Sprintf(testAccAzureRMRoute_basic, ri, ri, ri)
//
// resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
// PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
// Providers: testAccProviders, Providers: testAccProviders,
// CheckDestroy: testCheckAzureRMRouteDestroy, CheckDestroy: testCheckAzureRMRouteDestroy,
// Steps: []resource.TestStep{ Steps: []resource.TestStep{
// resource.TestStep{ {
// Config: config, Config: config,
// Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
// testCheckAzureRMRouteExists("azurerm_route.test"), testCheckAzureRMRouteExists("azurerm_route.test"),
// ), ),
// }, },
// }, },
// }) })
//} }
//
//func TestAccAzureRMRoute_multipleRoutes(t *testing.T) { func TestAccAzureRMRoute_multipleRoutes(t *testing.T) {
//
// ri := acctest.RandInt() ri := acctest.RandInt()
// preConfig := fmt.Sprintf(testAccAzureRMRoute_basic, ri, ri, ri) preConfig := fmt.Sprintf(testAccAzureRMRoute_basic, ri, ri, ri)
// postConfig := fmt.Sprintf(testAccAzureRMRoute_multipleRoutes, ri, ri, ri) postConfig := fmt.Sprintf(testAccAzureRMRoute_multipleRoutes, ri, ri, ri)
//
// resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
// PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
// Providers: testAccProviders, Providers: testAccProviders,
// CheckDestroy: testCheckAzureRMRouteDestroy, CheckDestroy: testCheckAzureRMRouteDestroy,
// Steps: []resource.TestStep{ Steps: []resource.TestStep{
// resource.TestStep{ {
// Config: preConfig, Config: preConfig,
// Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
// testCheckAzureRMRouteExists("azurerm_route.test"), testCheckAzureRMRouteExists("azurerm_route.test"),
// ), ),
// }, },
//
// resource.TestStep{ {
// Config: postConfig, Config: postConfig,
// Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
// testCheckAzureRMRouteExists("azurerm_route.test1"), testCheckAzureRMRouteExists("azurerm_route.test1"),
// ), ),
// }, },
// }, },
// }) })
//} }
//
//func testCheckAzureRMRouteExists(name string) resource.TestCheckFunc { func testCheckAzureRMRouteExists(name string) resource.TestCheckFunc {
// return func(s *terraform.State) error { return func(s *terraform.State) error {
//
// rs, ok := s.RootModule().Resources[name] rs, ok := s.RootModule().Resources[name]
// if !ok { if !ok {
// return fmt.Errorf("Not found: %s", name) return fmt.Errorf("Not found: %s", name)
// } }
//
// name := rs.Primary.Attributes["name"] name := rs.Primary.Attributes["name"]
// rtName := rs.Primary.Attributes["route_table_name"] rtName := rs.Primary.Attributes["route_table_name"]
// resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
// if !hasResourceGroup { if !hasResourceGroup {
// return fmt.Errorf("Bad: no resource group found in state for route: %s", name) return fmt.Errorf("Bad: no resource group found in state for route: %s", name)
// } }
//
// conn := testAccProvider.Meta().(*ArmClient).routesClient conn := testAccProvider.Meta().(*ArmClient).routesClient
//
// resp, err := conn.Get(resourceGroup, rtName, name) resp, err := conn.Get(resourceGroup, rtName, name)
// if err != nil { if err != nil {
// return fmt.Errorf("Bad: Get on routesClient: %s", err) return fmt.Errorf("Bad: Get on routesClient: %s", err)
// } }
//
// if resp.StatusCode == http.StatusNotFound { if resp.StatusCode == http.StatusNotFound {
// return fmt.Errorf("Bad: Route %q (resource group: %q) does not exist", name, resourceGroup) return fmt.Errorf("Bad: Route %q (resource group: %q) does not exist", name, resourceGroup)
// } }
//
// return nil return nil
// } }
//} }
//
//func testCheckAzureRMRouteDestroy(s *terraform.State) error { func testCheckAzureRMRouteDestroy(s *terraform.State) error {
// conn := testAccProvider.Meta().(*ArmClient).routesClient conn := testAccProvider.Meta().(*ArmClient).routesClient
//
// for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
// if rs.Type != "azurerm_route" { if rs.Type != "azurerm_route" {
// continue continue
// } }
//
// name := rs.Primary.Attributes["name"] name := rs.Primary.Attributes["name"]
// rtName := rs.Primary.Attributes["route_table_name"] rtName := rs.Primary.Attributes["route_table_name"]
// resourceGroup := rs.Primary.Attributes["resource_group_name"] resourceGroup := rs.Primary.Attributes["resource_group_name"]
//
// resp, err := conn.Get(resourceGroup, rtName, name) resp, err := conn.Get(resourceGroup, rtName, name)
//
// if err != nil { if err != nil {
// return nil return nil
// } }
//
// if resp.StatusCode != http.StatusNotFound { if resp.StatusCode != http.StatusNotFound {
// return fmt.Errorf("Route still exists:\n%#v", resp.Properties) return fmt.Errorf("Route still exists:\n%#v", resp.Properties)
// } }
// } }
//
// return nil return nil
//} }
//
//var testAccAzureRMRoute_basic = ` var testAccAzureRMRoute_basic = `
//resource "azurerm_resource_group" "test" { resource "azurerm_resource_group" "test" {
// name = "acctestrg-%d" name = "acctestrg-%d"
// location = "West US" location = "West US"
//} }
//
//resource "azurerm_route_table" "test" { resource "azurerm_route_table" "test" {
// name = "acctestrt%d" name = "acctestrt%d"
// location = "West US" location = "West US"
// resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
//} }
//
//resource "azurerm_route" "test" { resource "azurerm_route" "test" {
// name = "acctestroute%d" name = "acctestroute%d"
// resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
// route_table_name = "${azurerm_route_table.test.name}" route_table_name = "${azurerm_route_table.test.name}"
//
// address_prefix = "10.1.0.0/16" address_prefix = "10.1.0.0/16"
// next_hop_type = "vnetlocal" next_hop_type = "vnetlocal"
//} }
//` `
//
//var testAccAzureRMRoute_multipleRoutes = ` var testAccAzureRMRoute_multipleRoutes = `
//resource "azurerm_resource_group" "test" { resource "azurerm_resource_group" "test" {
// name = "acctestrg-%d" name = "acctestrg-%d"
// location = "West US" location = "West US"
//} }
//
//resource "azurerm_route_table" "test" { resource "azurerm_route_table" "test" {
// name = "acctestrt%d" name = "acctestrt%d"
// location = "West US" location = "West US"
// resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
//} }
//
//resource "azurerm_route" "test1" { resource "azurerm_route" "test1" {
// name = "acctestroute%d" name = "acctestroute%d"
// resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
// route_table_name = "${azurerm_route_table.test.name}" route_table_name = "${azurerm_route_table.test.name}"
//
// address_prefix = "10.2.0.0/16" address_prefix = "10.2.0.0/16"
// next_hop_type = "none" next_hop_type = "none"
//} }
//` `