provider/azurerm: Fix azurerm_route_table
``` HTTP_PROXY=http://localhost:8888 make testacc TEST=./builtin/providers/azurerm TESTARGS="-run TestAccAzureRMRouteTable" ==> Checking that code complies with gofmt requirements... /Users/James/Code/go/bin/stringer go generate $(go list ./... | grep -v /vendor/) 2016/06/01 18:19:00 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMRouteTable -timeout 120m === RUN TestAccAzureRMRouteTable_basic --- PASS: TestAccAzureRMRouteTable_basic (76.52s) === RUN TestAccAzureRMRouteTable_withTags --- PASS: TestAccAzureRMRouteTable_withTags (92.15s) === RUN TestAccAzureRMRouteTable_multipleRoutes --- PASS: TestAccAzureRMRouteTable_multipleRoutes (98.14s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 266.828s ```
This commit is contained in:
parent
5f45521795
commit
9b9ec7bb6c
|
@ -54,7 +54,7 @@ func Provider() terraform.ResourceProvider {
|
|||
//"azurerm_network_security_rule": resourceArmNetworkSecurityRule(),
|
||||
"azurerm_public_ip": resourceArmPublicIp(),
|
||||
//"azurerm_route": resourceArmRoute(),
|
||||
//"azurerm_route_table": resourceArmRouteTable(),
|
||||
"azurerm_route_table": resourceArmRouteTable(),
|
||||
"azurerm_storage_account": resourceArmStorageAccount(),
|
||||
"azurerm_storage_blob": resourceArmStorageBlob(),
|
||||
"azurerm_storage_container": resourceArmStorageContainer(),
|
||||
|
|
|
@ -1,258 +1,242 @@
|
|||
package azurerm
|
||||
|
||||
//import (
|
||||
// "bytes"
|
||||
// "fmt"
|
||||
// "log"
|
||||
// "net/http"
|
||||
// "strings"
|
||||
// "time"
|
||||
//
|
||||
// "github.com/Azure/azure-sdk-for-go/arm/network"
|
||||
// "github.com/hashicorp/terraform/helper/hashcode"
|
||||
// "github.com/hashicorp/terraform/helper/resource"
|
||||
// "github.com/hashicorp/terraform/helper/schema"
|
||||
//)
|
||||
//
|
||||
//func resourceArmRouteTable() *schema.Resource {
|
||||
// return &schema.Resource{
|
||||
// Create: resourceArmRouteTableCreate,
|
||||
// Read: resourceArmRouteTableRead,
|
||||
// Update: resourceArmRouteTableCreate,
|
||||
// Delete: resourceArmRouteTableDelete,
|
||||
//
|
||||
// Schema: map[string]*schema.Schema{
|
||||
// "name": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Required: true,
|
||||
// ForceNew: true,
|
||||
// },
|
||||
//
|
||||
// "location": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Required: true,
|
||||
// ForceNew: true,
|
||||
// StateFunc: azureRMNormalizeLocation,
|
||||
// },
|
||||
//
|
||||
// "resource_group_name": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Required: true,
|
||||
// ForceNew: true,
|
||||
// },
|
||||
//
|
||||
// "route": &schema.Schema{
|
||||
// Type: schema.TypeSet,
|
||||
// Optional: true,
|
||||
// Computed: true,
|
||||
// Elem: &schema.Resource{
|
||||
// Schema: map[string]*schema.Schema{
|
||||
// "name": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Required: true,
|
||||
// },
|
||||
//
|
||||
// "address_prefix": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Required: true,
|
||||
// },
|
||||
//
|
||||
// "next_hop_type": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Required: true,
|
||||
// ValidateFunc: validateRouteTableNextHopType,
|
||||
// },
|
||||
//
|
||||
// "next_hop_in_ip_address": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Optional: true,
|
||||
// Computed: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// Set: resourceArmRouteTableRouteHash,
|
||||
// },
|
||||
//
|
||||
// "subnets": &schema.Schema{
|
||||
// Type: schema.TypeSet,
|
||||
// Optional: true,
|
||||
// Computed: true,
|
||||
// Elem: &schema.Schema{Type: schema.TypeString},
|
||||
// Set: schema.HashString,
|
||||
// },
|
||||
//
|
||||
// "tags": tagsSchema(),
|
||||
// },
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func resourceArmRouteTableCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
// client := meta.(*ArmClient)
|
||||
// routeTablesClient := client.routeTablesClient
|
||||
//
|
||||
// log.Printf("[INFO] preparing arguments for Azure ARM Route Table creation.")
|
||||
//
|
||||
// name := d.Get("name").(string)
|
||||
// location := d.Get("location").(string)
|
||||
// resGroup := d.Get("resource_group_name").(string)
|
||||
// tags := d.Get("tags").(map[string]interface{})
|
||||
//
|
||||
// routeSet := network.RouteTable{
|
||||
// Name: &name,
|
||||
// Location: &location,
|
||||
// Tags: expandTags(tags),
|
||||
// }
|
||||
//
|
||||
// if _, ok := d.GetOk("route"); ok {
|
||||
// properties := network.RouteTablePropertiesFormat{}
|
||||
// routes, routeErr := expandAzureRmRouteTableRoutes(d)
|
||||
// if routeErr != nil {
|
||||
// return fmt.Errorf("Error Building list of Route Table Routes: %s", routeErr)
|
||||
// }
|
||||
// if len(routes) > 0 {
|
||||
// routeSet.Properties = &properties
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// resp, err := routeTablesClient.CreateOrUpdate(resGroup, name, routeSet)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// d.SetId(*resp.ID)
|
||||
//
|
||||
// log.Printf("[DEBUG] Waiting for Route Table (%s) to become available", name)
|
||||
// stateConf := &resource.StateChangeConf{
|
||||
// Pending: []string{"Accepted", "Updating"},
|
||||
// Target: []string{"Succeeded"},
|
||||
// Refresh: routeTableStateRefreshFunc(client, resGroup, name),
|
||||
// Timeout: 10 * time.Minute,
|
||||
// }
|
||||
// if _, err := stateConf.WaitForState(); err != nil {
|
||||
// return fmt.Errorf("Error waiting forRoute Table (%s) to become available: %s", name, err)
|
||||
// }
|
||||
//
|
||||
// return resourceArmRouteTableRead(d, meta)
|
||||
//}
|
||||
//
|
||||
//func resourceArmRouteTableRead(d *schema.ResourceData, meta interface{}) error {
|
||||
// routeTablesClient := meta.(*ArmClient).routeTablesClient
|
||||
//
|
||||
// id, err := parseAzureResourceID(d.Id())
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// resGroup := id.ResourceGroup
|
||||
// name := id.Path["routeTables"]
|
||||
//
|
||||
// resp, err := routeTablesClient.Get(resGroup, name, "")
|
||||
// if resp.StatusCode == http.StatusNotFound {
|
||||
// d.SetId("")
|
||||
// return nil
|
||||
// }
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("Error making Read request on Azure Route Table %s: %s", name, err)
|
||||
// }
|
||||
//
|
||||
// if resp.Properties.Subnets != nil {
|
||||
// if len(*resp.Properties.Subnets) > 0 {
|
||||
// subnets := make([]string, 0, len(*resp.Properties.Subnets))
|
||||
// for _, subnet := range *resp.Properties.Subnets {
|
||||
// id := subnet.ID
|
||||
// subnets = append(subnets, *id)
|
||||
// }
|
||||
//
|
||||
// if err := d.Set("subnets", subnets); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// flattenAndSetTags(d, resp.Tags)
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func resourceArmRouteTableDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
// routeTablesClient := meta.(*ArmClient).routeTablesClient
|
||||
//
|
||||
// id, err := parseAzureResourceID(d.Id())
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// resGroup := id.ResourceGroup
|
||||
// name := id.Path["routeTables"]
|
||||
//
|
||||
// _, err = routeTablesClient.Delete(resGroup, name)
|
||||
//
|
||||
// return err
|
||||
//}
|
||||
//
|
||||
//func expandAzureRmRouteTableRoutes(d *schema.ResourceData) ([]network.Route, error) {
|
||||
// configs := d.Get("route").(*schema.Set).List()
|
||||
// routes := make([]network.Route, 0, len(configs))
|
||||
//
|
||||
// for _, configRaw := range configs {
|
||||
// data := configRaw.(map[string]interface{})
|
||||
//
|
||||
// address_prefix := data["address_prefix"].(string)
|
||||
// next_hop_type := data["next_hop_type"].(string)
|
||||
//
|
||||
// properties := network.RoutePropertiesFormat{
|
||||
// AddressPrefix: &address_prefix,
|
||||
// NextHopType: network.RouteNextHopType(next_hop_type),
|
||||
// }
|
||||
//
|
||||
// if v := data["next_hop_in_ip_address"].(string); v != "" {
|
||||
// properties.NextHopIPAddress = &v
|
||||
// }
|
||||
//
|
||||
// name := data["name"].(string)
|
||||
// route := network.Route{
|
||||
// Name: &name,
|
||||
// Properties: &properties,
|
||||
// }
|
||||
//
|
||||
// routes = append(routes, route)
|
||||
// }
|
||||
//
|
||||
// return routes, nil
|
||||
//}
|
||||
//
|
||||
//func routeTableStateRefreshFunc(client *ArmClient, resourceGroupName string, routeTableName string) resource.StateRefreshFunc {
|
||||
// return func() (interface{}, string, error) {
|
||||
// res, err := client.routeTablesClient.Get(resourceGroupName, routeTableName, "")
|
||||
// if err != nil {
|
||||
// return nil, "", fmt.Errorf("Error issuing read request in routeTableStateRefreshFunc to Azure ARM for route table '%s' (RG: '%s'): %s", routeTableName, resourceGroupName, err)
|
||||
// }
|
||||
//
|
||||
// return res, *res.Properties.ProvisioningState, nil
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func resourceArmRouteTableRouteHash(v interface{}) int {
|
||||
// var buf bytes.Buffer
|
||||
// m := v.(map[string]interface{})
|
||||
// buf.WriteString(fmt.Sprintf("%s-", m["name"].(string)))
|
||||
// buf.WriteString(fmt.Sprintf("%s-", m["address_prefix"].(string)))
|
||||
// buf.WriteString(fmt.Sprintf("%s-", m["next_hop_type"].(string)))
|
||||
//
|
||||
// return hashcode.String(buf.String())
|
||||
//}
|
||||
//
|
||||
//func validateRouteTableNextHopType(v interface{}, k string) (ws []string, errors []error) {
|
||||
// value := strings.ToLower(v.(string))
|
||||
// hopTypes := map[string]bool{
|
||||
// "virtualnetworkgateway": true,
|
||||
// "vnetlocal": true,
|
||||
// "internet": true,
|
||||
// "virtualappliance": true,
|
||||
// "none": true,
|
||||
// }
|
||||
//
|
||||
// if !hopTypes[value] {
|
||||
// errors = append(errors, fmt.Errorf("Route Table NextHopType Protocol can only be VirtualNetworkGateway, VnetLocal, Internet or VirtualAppliance"))
|
||||
// }
|
||||
// return
|
||||
//}
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/arm/network"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func resourceArmRouteTable() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceArmRouteTableCreate,
|
||||
Read: resourceArmRouteTableRead,
|
||||
Update: resourceArmRouteTableCreate,
|
||||
Delete: resourceArmRouteTableDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"location": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
StateFunc: azureRMNormalizeLocation,
|
||||
},
|
||||
|
||||
"resource_group_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"route": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"address_prefix": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"next_hop_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validateRouteTableNextHopType,
|
||||
},
|
||||
|
||||
"next_hop_in_ip_address": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Set: resourceArmRouteTableRouteHash,
|
||||
},
|
||||
|
||||
"subnets": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
Set: schema.HashString,
|
||||
},
|
||||
|
||||
"tags": tagsSchema(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceArmRouteTableCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
routeTablesClient := client.routeTablesClient
|
||||
|
||||
log.Printf("[INFO] preparing arguments for Azure ARM Route Table creation.")
|
||||
|
||||
name := d.Get("name").(string)
|
||||
location := d.Get("location").(string)
|
||||
resGroup := d.Get("resource_group_name").(string)
|
||||
tags := d.Get("tags").(map[string]interface{})
|
||||
|
||||
routeSet := network.RouteTable{
|
||||
Name: &name,
|
||||
Location: &location,
|
||||
Tags: expandTags(tags),
|
||||
}
|
||||
|
||||
if _, ok := d.GetOk("route"); ok {
|
||||
properties := network.RouteTablePropertiesFormat{}
|
||||
routes, routeErr := expandAzureRmRouteTableRoutes(d)
|
||||
if routeErr != nil {
|
||||
return fmt.Errorf("Error Building list of Route Table Routes: %s", routeErr)
|
||||
}
|
||||
if len(routes) > 0 {
|
||||
routeSet.Properties = &properties
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_, err := routeTablesClient.CreateOrUpdate(resGroup, name, routeSet, make(chan struct{}))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
read, err := routeTablesClient.Get(resGroup, name, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if read.ID == nil {
|
||||
return fmt.Errorf("Cannot read Route Table %s (resource group %s) ID", name, resGroup)
|
||||
}
|
||||
|
||||
d.SetId(*read.ID)
|
||||
|
||||
return resourceArmRouteTableRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceArmRouteTableRead(d *schema.ResourceData, meta interface{}) error {
|
||||
routeTablesClient := meta.(*ArmClient).routeTablesClient
|
||||
|
||||
id, err := parseAzureResourceID(d.Id())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resGroup := id.ResourceGroup
|
||||
name := id.Path["routeTables"]
|
||||
|
||||
resp, err := routeTablesClient.Get(resGroup, name, "")
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error making Read request on Azure Route Table %s: %s", name, err)
|
||||
}
|
||||
|
||||
if resp.Properties.Subnets != nil {
|
||||
if len(*resp.Properties.Subnets) > 0 {
|
||||
subnets := make([]string, 0, len(*resp.Properties.Subnets))
|
||||
for _, subnet := range *resp.Properties.Subnets {
|
||||
id := subnet.ID
|
||||
subnets = append(subnets, *id)
|
||||
}
|
||||
|
||||
if err := d.Set("subnets", subnets); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flattenAndSetTags(d, resp.Tags)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceArmRouteTableDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
routeTablesClient := meta.(*ArmClient).routeTablesClient
|
||||
|
||||
id, err := parseAzureResourceID(d.Id())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resGroup := id.ResourceGroup
|
||||
name := id.Path["routeTables"]
|
||||
|
||||
_, err = routeTablesClient.Delete(resGroup, name, make(chan struct{}))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func expandAzureRmRouteTableRoutes(d *schema.ResourceData) ([]network.Route, error) {
|
||||
configs := d.Get("route").(*schema.Set).List()
|
||||
routes := make([]network.Route, 0, len(configs))
|
||||
|
||||
for _, configRaw := range configs {
|
||||
data := configRaw.(map[string]interface{})
|
||||
|
||||
address_prefix := data["address_prefix"].(string)
|
||||
next_hop_type := data["next_hop_type"].(string)
|
||||
|
||||
properties := network.RoutePropertiesFormat{
|
||||
AddressPrefix: &address_prefix,
|
||||
NextHopType: network.RouteNextHopType(next_hop_type),
|
||||
}
|
||||
|
||||
if v := data["next_hop_in_ip_address"].(string); v != "" {
|
||||
properties.NextHopIPAddress = &v
|
||||
}
|
||||
|
||||
name := data["name"].(string)
|
||||
route := network.Route{
|
||||
Name: &name,
|
||||
Properties: &properties,
|
||||
}
|
||||
|
||||
routes = append(routes, route)
|
||||
}
|
||||
|
||||
return routes, nil
|
||||
}
|
||||
|
||||
func resourceArmRouteTableRouteHash(v interface{}) int {
|
||||
var buf bytes.Buffer
|
||||
m := v.(map[string]interface{})
|
||||
buf.WriteString(fmt.Sprintf("%s-", m["name"].(string)))
|
||||
buf.WriteString(fmt.Sprintf("%s-", m["address_prefix"].(string)))
|
||||
buf.WriteString(fmt.Sprintf("%s-", m["next_hop_type"].(string)))
|
||||
|
||||
return hashcode.String(buf.String())
|
||||
}
|
||||
|
||||
func validateRouteTableNextHopType(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := strings.ToLower(v.(string))
|
||||
hopTypes := map[string]bool{
|
||||
"virtualnetworkgateway": true,
|
||||
"vnetlocal": true,
|
||||
"internet": true,
|
||||
"virtualappliance": true,
|
||||
"none": true,
|
||||
}
|
||||
|
||||
if !hopTypes[value] {
|
||||
errors = append(errors, fmt.Errorf("Route Table NextHopType Protocol can only be VirtualNetworkGateway, VnetLocal, Internet or VirtualAppliance"))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,294 +1,294 @@
|
|||
package azurerm
|
||||
|
||||
//import (
|
||||
// "fmt"
|
||||
// "net/http"
|
||||
// "testing"
|
||||
//
|
||||
// "github.com/hashicorp/terraform/helper/acctest"
|
||||
// "github.com/hashicorp/terraform/helper/resource"
|
||||
// "github.com/hashicorp/terraform/terraform"
|
||||
//)
|
||||
//
|
||||
//func TestResourceAzureRMRouteTableNextHopType_validation(t *testing.T) {
|
||||
// cases := []struct {
|
||||
// Value string
|
||||
// ErrCount int
|
||||
// }{
|
||||
// {
|
||||
// Value: "Random",
|
||||
// ErrCount: 1,
|
||||
// },
|
||||
// {
|
||||
// Value: "VirtualNetworkGateway",
|
||||
// ErrCount: 0,
|
||||
// },
|
||||
// {
|
||||
// Value: "VNETLocal",
|
||||
// ErrCount: 0,
|
||||
// },
|
||||
// {
|
||||
// Value: "Internet",
|
||||
// ErrCount: 0,
|
||||
// },
|
||||
// {
|
||||
// Value: "VirtualAppliance",
|
||||
// ErrCount: 0,
|
||||
// },
|
||||
// {
|
||||
// Value: "None",
|
||||
// ErrCount: 0,
|
||||
// },
|
||||
// {
|
||||
// Value: "VIRTUALNETWORKGATEWAY",
|
||||
// ErrCount: 0,
|
||||
// },
|
||||
// {
|
||||
// Value: "virtualnetworkgateway",
|
||||
// ErrCount: 0,
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// for _, tc := range cases {
|
||||
// _, errors := validateRouteTableNextHopType(tc.Value, "azurerm_route_table")
|
||||
//
|
||||
// if len(errors) != tc.ErrCount {
|
||||
// t.Fatalf("Expected the Azure RM Route Table nextHopType to trigger a validation error")
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func TestAccAzureRMRouteTable_basic(t *testing.T) {
|
||||
//
|
||||
// ri := acctest.RandInt()
|
||||
// config := fmt.Sprintf(testAccAzureRMRouteTable_basic, ri, ri)
|
||||
//
|
||||
// resource.Test(t, resource.TestCase{
|
||||
// PreCheck: func() { testAccPreCheck(t) },
|
||||
// Providers: testAccProviders,
|
||||
// CheckDestroy: testCheckAzureRMRouteTableDestroy,
|
||||
// Steps: []resource.TestStep{
|
||||
// resource.TestStep{
|
||||
// Config: config,
|
||||
// Check: resource.ComposeTestCheckFunc(
|
||||
// testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||
// ),
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
//}
|
||||
//
|
||||
//func TestAccAzureRMRouteTable_withTags(t *testing.T) {
|
||||
//
|
||||
// ri := acctest.RandInt()
|
||||
// preConfig := fmt.Sprintf(testAccAzureRMRouteTable_withTags, ri, ri)
|
||||
// postConfig := fmt.Sprintf(testAccAzureRMRouteTable_withTagsUpdate, ri, ri)
|
||||
//
|
||||
// resource.Test(t, resource.TestCase{
|
||||
// PreCheck: func() { testAccPreCheck(t) },
|
||||
// Providers: testAccProviders,
|
||||
// CheckDestroy: testCheckAzureRMRouteTableDestroy,
|
||||
// Steps: []resource.TestStep{
|
||||
// resource.TestStep{
|
||||
// Config: preConfig,
|
||||
// Check: resource.ComposeTestCheckFunc(
|
||||
// testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||
// resource.TestCheckResourceAttr(
|
||||
// "azurerm_route_table.test", "tags.#", "2"),
|
||||
// resource.TestCheckResourceAttr(
|
||||
// "azurerm_route_table.test", "tags.environment", "Production"),
|
||||
// resource.TestCheckResourceAttr(
|
||||
// "azurerm_route_table.test", "tags.cost_center", "MSFT"),
|
||||
// ),
|
||||
// },
|
||||
//
|
||||
// resource.TestStep{
|
||||
// Config: postConfig,
|
||||
// Check: resource.ComposeTestCheckFunc(
|
||||
// testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||
// resource.TestCheckResourceAttr(
|
||||
// "azurerm_route_table.test", "tags.#", "1"),
|
||||
// resource.TestCheckResourceAttr(
|
||||
// "azurerm_route_table.test", "tags.environment", "staging"),
|
||||
// ),
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
//}
|
||||
//
|
||||
//func TestAccAzureRMRouteTable_multipleRoutes(t *testing.T) {
|
||||
//
|
||||
// ri := acctest.RandInt()
|
||||
// preConfig := fmt.Sprintf(testAccAzureRMRouteTable_basic, ri, ri)
|
||||
// postConfig := fmt.Sprintf(testAccAzureRMRouteTable_multipleRoutes, ri, ri)
|
||||
//
|
||||
// resource.Test(t, resource.TestCase{
|
||||
// PreCheck: func() { testAccPreCheck(t) },
|
||||
// Providers: testAccProviders,
|
||||
// CheckDestroy: testCheckAzureRMRouteTableDestroy,
|
||||
// Steps: []resource.TestStep{
|
||||
// resource.TestStep{
|
||||
// Config: preConfig,
|
||||
// Check: resource.ComposeTestCheckFunc(
|
||||
// testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||
// resource.TestCheckResourceAttr(
|
||||
// "azurerm_route_table.test", "route.#", "1"),
|
||||
// ),
|
||||
// },
|
||||
//
|
||||
// resource.TestStep{
|
||||
// Config: postConfig,
|
||||
// Check: resource.ComposeTestCheckFunc(
|
||||
// testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||
// resource.TestCheckResourceAttr(
|
||||
// "azurerm_route_table.test", "route.#", "2"),
|
||||
// ),
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
//}
|
||||
//
|
||||
//func testCheckAzureRMRouteTableExists(name string) resource.TestCheckFunc {
|
||||
// return func(s *terraform.State) error {
|
||||
//
|
||||
// rs, ok := s.RootModule().Resources[name]
|
||||
// if !ok {
|
||||
// return fmt.Errorf("Not found: %s", name)
|
||||
// }
|
||||
//
|
||||
// name := rs.Primary.Attributes["name"]
|
||||
// resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||
// if !hasResourceGroup {
|
||||
// return fmt.Errorf("Bad: no resource group found in state for route table: %s", name)
|
||||
// }
|
||||
//
|
||||
// conn := testAccProvider.Meta().(*ArmClient).routeTablesClient
|
||||
//
|
||||
// resp, err := conn.Get(resourceGroup, name, "")
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("Bad: Get on routeTablesClient: %s", err)
|
||||
// }
|
||||
//
|
||||
// if resp.StatusCode == http.StatusNotFound {
|
||||
// return fmt.Errorf("Bad: Route Table %q (resource group: %q) does not exist", name, resourceGroup)
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func testCheckAzureRMRouteTableDestroy(s *terraform.State) error {
|
||||
// conn := testAccProvider.Meta().(*ArmClient).routeTablesClient
|
||||
//
|
||||
// for _, rs := range s.RootModule().Resources {
|
||||
// if rs.Type != "azurerm_route_table" {
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// name := rs.Primary.Attributes["name"]
|
||||
// resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||
//
|
||||
// resp, err := conn.Get(resourceGroup, name, "")
|
||||
//
|
||||
// if err != nil {
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// if resp.StatusCode != http.StatusNotFound {
|
||||
// return fmt.Errorf("Route Table still exists:\n%#v", resp.Properties)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//var testAccAzureRMRouteTable_basic = `
|
||||
//resource "azurerm_resource_group" "test" {
|
||||
// name = "acctestrg-%d"
|
||||
// location = "West US"
|
||||
//}
|
||||
//
|
||||
//resource "azurerm_route_table" "test" {
|
||||
// name = "acctestrt%d"
|
||||
// location = "West US"
|
||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
//
|
||||
// route {
|
||||
// name = "route1"
|
||||
// address_prefix = "*"
|
||||
// next_hop_type = "internet"
|
||||
// }
|
||||
//}
|
||||
//`
|
||||
//
|
||||
//var testAccAzureRMRouteTable_multipleRoutes = `
|
||||
//resource "azurerm_resource_group" "test" {
|
||||
// name = "acctestrg-%d"
|
||||
// location = "West US"
|
||||
//}
|
||||
//
|
||||
//resource "azurerm_route_table" "test" {
|
||||
// name = "acctestrt%d"
|
||||
// location = "West US"
|
||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
//
|
||||
// route {
|
||||
// name = "route1"
|
||||
// address_prefix = "*"
|
||||
// next_hop_type = "internet"
|
||||
// }
|
||||
//
|
||||
// route {
|
||||
// name = "route2"
|
||||
// address_prefix = "*"
|
||||
// next_hop_type = "virtualappliance"
|
||||
// }
|
||||
//}
|
||||
//`
|
||||
//
|
||||
//var testAccAzureRMRouteTable_withTags = `
|
||||
//resource "azurerm_resource_group" "test" {
|
||||
// name = "acctestrg-%d"
|
||||
// location = "West US"
|
||||
//}
|
||||
//
|
||||
//resource "azurerm_route_table" "test" {
|
||||
// name = "acctestrt%d"
|
||||
// location = "West US"
|
||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
//
|
||||
// route {
|
||||
// name = "route1"
|
||||
// address_prefix = "*"
|
||||
// next_hop_type = "internet"
|
||||
// }
|
||||
//
|
||||
// tags {
|
||||
// environment = "Production"
|
||||
// cost_center = "MSFT"
|
||||
// }
|
||||
//}
|
||||
//`
|
||||
//
|
||||
//var testAccAzureRMRouteTable_withTagsUpdate = `
|
||||
//resource "azurerm_resource_group" "test" {
|
||||
// name = "acctestrg-%d"
|
||||
// location = "West US"
|
||||
//}
|
||||
//
|
||||
//resource "azurerm_route_table" "test" {
|
||||
// name = "acctestrt%d"
|
||||
// location = "West US"
|
||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
//
|
||||
// route {
|
||||
// name = "route1"
|
||||
// address_prefix = "*"
|
||||
// next_hop_type = "internet"
|
||||
// }
|
||||
//
|
||||
// tags {
|
||||
// environment = "staging"
|
||||
// }
|
||||
//}
|
||||
//`
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestResourceAzureRMRouteTableNextHopType_validation(t *testing.T) {
|
||||
cases := []struct {
|
||||
Value string
|
||||
ErrCount int
|
||||
}{
|
||||
{
|
||||
Value: "Random",
|
||||
ErrCount: 1,
|
||||
},
|
||||
{
|
||||
Value: "VirtualNetworkGateway",
|
||||
ErrCount: 0,
|
||||
},
|
||||
{
|
||||
Value: "VNETLocal",
|
||||
ErrCount: 0,
|
||||
},
|
||||
{
|
||||
Value: "Internet",
|
||||
ErrCount: 0,
|
||||
},
|
||||
{
|
||||
Value: "VirtualAppliance",
|
||||
ErrCount: 0,
|
||||
},
|
||||
{
|
||||
Value: "None",
|
||||
ErrCount: 0,
|
||||
},
|
||||
{
|
||||
Value: "VIRTUALNETWORKGATEWAY",
|
||||
ErrCount: 0,
|
||||
},
|
||||
{
|
||||
Value: "virtualnetworkgateway",
|
||||
ErrCount: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
_, errors := validateRouteTableNextHopType(tc.Value, "azurerm_route_table")
|
||||
|
||||
if len(errors) != tc.ErrCount {
|
||||
t.Fatalf("Expected the Azure RM Route Table nextHopType to trigger a validation error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccAzureRMRouteTable_basic(t *testing.T) {
|
||||
|
||||
ri := acctest.RandInt()
|
||||
config := fmt.Sprintf(testAccAzureRMRouteTable_basic, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMRouteTableDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMRouteTable_withTags(t *testing.T) {
|
||||
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAzureRMRouteTable_withTags, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAzureRMRouteTable_withTagsUpdate, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMRouteTableDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: preConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_route_table.test", "tags.#", "2"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_route_table.test", "tags.environment", "Production"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_route_table.test", "tags.cost_center", "MSFT"),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: postConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_route_table.test", "tags.#", "1"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_route_table.test", "tags.environment", "staging"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMRouteTable_multipleRoutes(t *testing.T) {
|
||||
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAzureRMRouteTable_basic, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAzureRMRouteTable_multipleRoutes, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMRouteTableDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: preConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_route_table.test", "route.#", "1"),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: postConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_route_table.test", "route.#", "2"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testCheckAzureRMRouteTableExists(name string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
|
||||
rs, ok := s.RootModule().Resources[name]
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", name)
|
||||
}
|
||||
|
||||
name := rs.Primary.Attributes["name"]
|
||||
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||
if !hasResourceGroup {
|
||||
return fmt.Errorf("Bad: no resource group found in state for route table: %s", name)
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*ArmClient).routeTablesClient
|
||||
|
||||
resp, err := conn.Get(resourceGroup, name, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Bad: Get on routeTablesClient: %s", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
return fmt.Errorf("Bad: Route Table %q (resource group: %q) does not exist", name, resourceGroup)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testCheckAzureRMRouteTableDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*ArmClient).routeTablesClient
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "azurerm_route_table" {
|
||||
continue
|
||||
}
|
||||
|
||||
name := rs.Primary.Attributes["name"]
|
||||
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||
|
||||
resp, err := conn.Get(resourceGroup, name, "")
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusNotFound {
|
||||
return fmt.Errorf("Route Table still exists:\n%#v", resp.Properties)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var testAccAzureRMRouteTable_basic = `
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "acctestrg-%d"
|
||||
location = "West US"
|
||||
}
|
||||
|
||||
resource "azurerm_route_table" "test" {
|
||||
name = "acctestrt%d"
|
||||
location = "West US"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
|
||||
route {
|
||||
name = "route1"
|
||||
address_prefix = "*"
|
||||
next_hop_type = "internet"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMRouteTable_multipleRoutes = `
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "acctestrg-%d"
|
||||
location = "West US"
|
||||
}
|
||||
|
||||
resource "azurerm_route_table" "test" {
|
||||
name = "acctestrt%d"
|
||||
location = "West US"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
|
||||
route {
|
||||
name = "route1"
|
||||
address_prefix = "*"
|
||||
next_hop_type = "internet"
|
||||
}
|
||||
|
||||
route {
|
||||
name = "route2"
|
||||
address_prefix = "*"
|
||||
next_hop_type = "virtualappliance"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMRouteTable_withTags = `
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "acctestrg-%d"
|
||||
location = "West US"
|
||||
}
|
||||
|
||||
resource "azurerm_route_table" "test" {
|
||||
name = "acctestrt%d"
|
||||
location = "West US"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
|
||||
route {
|
||||
name = "route1"
|
||||
address_prefix = "*"
|
||||
next_hop_type = "internet"
|
||||
}
|
||||
|
||||
tags {
|
||||
environment = "Production"
|
||||
cost_center = "MSFT"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMRouteTable_withTagsUpdate = `
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "acctestrg-%d"
|
||||
location = "West US"
|
||||
}
|
||||
|
||||
resource "azurerm_route_table" "test" {
|
||||
name = "acctestrt%d"
|
||||
location = "West US"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
|
||||
route {
|
||||
name = "route1"
|
||||
address_prefix = "*"
|
||||
next_hop_type = "internet"
|
||||
}
|
||||
|
||||
tags {
|
||||
environment = "staging"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue