provider/azurerm: Fix azurerm_local_network_gateway
``` HTTP_PROXY=http://localhost:8888 make testacc TEST=./builtin/providers/azurerm TESTARGS="-run TestAccAzureRMLocalNetworkGateway_" ==> Checking that code complies with gofmt requirements... /Users/James/Code/go/bin/stringer go generate $(go list ./... | grep -v /vendor/) 2016/06/01 18:59:05 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMLocalNetworkGateway_ -timeout 120m === RUN TestAccAzureRMLocalNetworkGateway_basic --- PASS: TestAccAzureRMLocalNetworkGateway_basic (95.25s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 95.260s ```
This commit is contained in:
parent
bde2c502b6
commit
0e3da1f98c
|
@ -48,7 +48,7 @@ func Provider() terraform.ResourceProvider {
|
|||
"azurerm_availability_set": resourceArmAvailabilitySet(),
|
||||
//"azurerm_cdn_endpoint": resourceArmCdnEndpoint(),
|
||||
//"azurerm_cdn_profile": resourceArmCdnProfile(),
|
||||
//"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
|
||||
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
|
||||
"azurerm_network_interface": resourceArmNetworkInterface(),
|
||||
//"azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
|
||||
//"azurerm_network_security_rule": resourceArmNetworkSecurityRule(),
|
||||
|
|
|
@ -1,136 +1,146 @@
|
|||
package azurerm
|
||||
|
||||
//import (
|
||||
// "fmt"
|
||||
//
|
||||
// "github.com/Azure/azure-sdk-for-go/arm/network"
|
||||
// "github.com/Azure/azure-sdk-for-go/core/http"
|
||||
// "github.com/hashicorp/terraform/helper/schema"
|
||||
//)
|
||||
//
|
||||
//func resourceArmLocalNetworkGateway() *schema.Resource {
|
||||
// return &schema.Resource{
|
||||
// Create: resourceArmLocalNetworkGatewayCreate,
|
||||
// Read: resourceArmLocalNetworkGatewayRead,
|
||||
// Update: resourceArmLocalNetworkGatewayCreate,
|
||||
// Delete: resourceArmLocalNetworkGatewayDelete,
|
||||
//
|
||||
// Schema: map[string]*schema.Schema{
|
||||
// "name": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Required: true,
|
||||
// ForceNew: true,
|
||||
// },
|
||||
//
|
||||
// "location": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Optional: true,
|
||||
// ForceNew: true,
|
||||
// StateFunc: azureRMNormalizeLocation,
|
||||
// },
|
||||
//
|
||||
// "resource_group_name": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Optional: true,
|
||||
// ForceNew: true,
|
||||
// },
|
||||
//
|
||||
// "gateway_address": &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// Required: true,
|
||||
// },
|
||||
//
|
||||
// "address_space": &schema.Schema{
|
||||
// Type: schema.TypeList,
|
||||
// Required: true,
|
||||
// Elem: &schema.Schema{
|
||||
// Type: schema.TypeString,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func resourceArmLocalNetworkGatewayCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
// lnetClient := meta.(*ArmClient).localNetConnClient
|
||||
//
|
||||
// name := d.Get("name").(string)
|
||||
// location := d.Get("location").(string)
|
||||
// resGroup := d.Get("resource_group_name").(string)
|
||||
// ipAddress := d.Get("gateway_address").(string)
|
||||
//
|
||||
// // fetch the 'address_space_prefixes:
|
||||
// prefixes := []string{}
|
||||
// for _, pref := range d.Get("address_space").([]interface{}) {
|
||||
// prefixes = append(prefixes, pref.(string))
|
||||
// }
|
||||
//
|
||||
// resp, err := lnetClient.CreateOrUpdate(resGroup, name, network.LocalNetworkGateway{
|
||||
// Name: &name,
|
||||
// Location: &location,
|
||||
// Properties: &network.LocalNetworkGatewayPropertiesFormat{
|
||||
// LocalNetworkAddressSpace: &network.AddressSpace{
|
||||
// AddressPrefixes: &prefixes,
|
||||
// },
|
||||
// GatewayIPAddress: &ipAddress,
|
||||
// },
|
||||
// })
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("Error creating Azure ARM Local Network Gateway '%s': %s", name, err)
|
||||
// }
|
||||
//
|
||||
// d.SetId(*resp.ID)
|
||||
//
|
||||
// return resourceArmLocalNetworkGatewayRead(d, meta)
|
||||
//}
|
||||
//
|
||||
//// resourceArmLocalNetworkGatewayRead goes ahead and reads the state of the corresponding ARM local network gateway.
|
||||
//func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}) error {
|
||||
// lnetClient := meta.(*ArmClient).localNetConnClient
|
||||
//
|
||||
// id, err := parseAzureResourceID(d.Id())
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// name := id.Path["localNetworkGateways"]
|
||||
// resGroup := id.ResourceGroup
|
||||
//
|
||||
// resp, err := lnetClient.Get(resGroup, name)
|
||||
// if err != nil {
|
||||
// if resp.StatusCode == http.StatusNotFound {
|
||||
// d.SetId("")
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// return fmt.Errorf("Error reading the state of Azure ARM local network gateway '%s': %s", name, err)
|
||||
// }
|
||||
//
|
||||
// d.Set("gateway_address", resp.Properties.GatewayIPAddress)
|
||||
//
|
||||
// prefs := []string{}
|
||||
// if ps := *resp.Properties.LocalNetworkAddressSpace.AddressPrefixes; ps != nil {
|
||||
// prefs = ps
|
||||
// }
|
||||
// d.Set("address_space", prefs)
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//// resourceArmLocalNetworkGatewayDelete deletes the specified ARM local network gateway.
|
||||
//func resourceArmLocalNetworkGatewayDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
// lnetClient := meta.(*ArmClient).localNetConnClient
|
||||
//
|
||||
// id, err := parseAzureResourceID(d.Id())
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// name := id.Path["localNetworkGateways"]
|
||||
// resGroup := id.ResourceGroup
|
||||
//
|
||||
// _, err = lnetClient.Delete(resGroup, name)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("Error issuing Azure ARM delete request of local network gateway '%s': %s", name, err)
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/arm/network"
|
||||
"github.com/Azure/azure-sdk-for-go/core/http"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func resourceArmLocalNetworkGateway() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceArmLocalNetworkGatewayCreate,
|
||||
Read: resourceArmLocalNetworkGatewayRead,
|
||||
Update: resourceArmLocalNetworkGatewayCreate,
|
||||
Delete: resourceArmLocalNetworkGatewayDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"location": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
StateFunc: azureRMNormalizeLocation,
|
||||
},
|
||||
|
||||
"resource_group_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"gateway_address": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"address_space": {
|
||||
Type: schema.TypeList,
|
||||
Required: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceArmLocalNetworkGatewayCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
lnetClient := meta.(*ArmClient).localNetConnClient
|
||||
|
||||
name := d.Get("name").(string)
|
||||
location := d.Get("location").(string)
|
||||
resGroup := d.Get("resource_group_name").(string)
|
||||
ipAddress := d.Get("gateway_address").(string)
|
||||
|
||||
// fetch the 'address_space_prefixes:
|
||||
prefixes := []string{}
|
||||
for _, pref := range d.Get("address_space").([]interface{}) {
|
||||
prefixes = append(prefixes, pref.(string))
|
||||
}
|
||||
|
||||
gateway := network.LocalNetworkGateway{
|
||||
Name: &name,
|
||||
Location: &location,
|
||||
Properties: &network.LocalNetworkGatewayPropertiesFormat{
|
||||
LocalNetworkAddressSpace: &network.AddressSpace{
|
||||
AddressPrefixes: &prefixes,
|
||||
},
|
||||
GatewayIPAddress: &ipAddress,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := lnetClient.CreateOrUpdate(resGroup, name, gateway, make(chan struct{}))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating Azure ARM Local Network Gateway '%s': %s", name, err)
|
||||
}
|
||||
|
||||
read, err := lnetClient.Get(resGroup, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if read.ID == nil {
|
||||
return fmt.Errorf("Cannot read Virtual Network %s (resource group %s) ID", name, resGroup)
|
||||
}
|
||||
|
||||
d.SetId(*read.ID)
|
||||
|
||||
return resourceArmLocalNetworkGatewayRead(d, meta)
|
||||
}
|
||||
|
||||
// resourceArmLocalNetworkGatewayRead goes ahead and reads the state of the corresponding ARM local network gateway.
|
||||
func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}) error {
|
||||
lnetClient := meta.(*ArmClient).localNetConnClient
|
||||
|
||||
id, err := parseAzureResourceID(d.Id())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
name := id.Path["localNetworkGateways"]
|
||||
resGroup := id.ResourceGroup
|
||||
|
||||
resp, err := lnetClient.Get(resGroup, name)
|
||||
if err != nil {
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("Error reading the state of Azure ARM local network gateway '%s': %s", name, err)
|
||||
}
|
||||
|
||||
d.Set("gateway_address", resp.Properties.GatewayIPAddress)
|
||||
|
||||
prefs := []string{}
|
||||
if ps := *resp.Properties.LocalNetworkAddressSpace.AddressPrefixes; ps != nil {
|
||||
prefs = ps
|
||||
}
|
||||
d.Set("address_space", prefs)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// resourceArmLocalNetworkGatewayDelete deletes the specified ARM local network gateway.
|
||||
func resourceArmLocalNetworkGatewayDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
lnetClient := meta.(*ArmClient).localNetConnClient
|
||||
|
||||
id, err := parseAzureResourceID(d.Id())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
name := id.Path["localNetworkGateways"]
|
||||
resGroup := id.ResourceGroup
|
||||
|
||||
_, err = lnetClient.Delete(resGroup, name, make(chan struct{}))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error issuing Azure ARM delete request of local network gateway '%s': %s", name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,108 +1,108 @@
|
|||
package azurerm
|
||||
|
||||
//import (
|
||||
// "fmt"
|
||||
// "testing"
|
||||
//
|
||||
// "github.com/Azure/azure-sdk-for-go/core/http"
|
||||
// "github.com/hashicorp/terraform/helper/resource"
|
||||
// "github.com/hashicorp/terraform/terraform"
|
||||
//)
|
||||
//
|
||||
//func TestAccAzureRMLocalNetworkGateway_basic(t *testing.T) {
|
||||
// name := "azurerm_local_network_gateway.test"
|
||||
//
|
||||
// resource.Test(t, resource.TestCase{
|
||||
// PreCheck: func() { testAccPreCheck(t) },
|
||||
// Providers: testAccProviders,
|
||||
// CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy,
|
||||
// Steps: []resource.TestStep{
|
||||
// resource.TestStep{
|
||||
// Config: testAccAzureRMLocalNetworkGatewayConfig_basic,
|
||||
// Check: resource.ComposeTestCheckFunc(
|
||||
// testCheckAzureRMLocalNetworkGatewayExists(name),
|
||||
// resource.TestCheckResourceAttr(name, "gateway_address", "127.0.0.1"),
|
||||
// resource.TestCheckResourceAttr(name, "address_space.0", "127.0.0.0/8"),
|
||||
// ),
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
//}
|
||||
//
|
||||
//// testCheckAzureRMLocalNetworkGatewayExists returns the resurce.TestCheckFunc
|
||||
//// which checks whether or not the expected local network gateway exists both
|
||||
//// in the schema, and on Azure.
|
||||
//func testCheckAzureRMLocalNetworkGatewayExists(name string) resource.TestCheckFunc {
|
||||
// return func(s *terraform.State) error {
|
||||
// // first check within the schema for the local network gateway:
|
||||
// res, ok := s.RootModule().Resources[name]
|
||||
// if !ok {
|
||||
// return fmt.Errorf("Local network gateway '%s' not found.", name)
|
||||
// }
|
||||
//
|
||||
// // then, extract the name and the resource group:
|
||||
// id, err := parseAzureResourceID(res.Primary.ID)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// localNetName := id.Path["localNetworkGateways"]
|
||||
// resGrp := id.ResourceGroup
|
||||
//
|
||||
// // and finally, check that it exists on Azure:
|
||||
// lnetClient := testAccProvider.Meta().(*ArmClient).localNetConnClient
|
||||
//
|
||||
// resp, err := lnetClient.Get(resGrp, localNetName)
|
||||
// if err != nil {
|
||||
// if resp.StatusCode == http.StatusNotFound {
|
||||
// return fmt.Errorf("Local network gateway '%s' (resource group '%s') does not exist on Azure.", localNetName, resGrp)
|
||||
// }
|
||||
//
|
||||
// return fmt.Errorf("Error reading the state of local network gateway '%s'.", localNetName)
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func testCheckAzureRMLocalNetworkGatewayDestroy(s *terraform.State) error {
|
||||
// for _, res := range s.RootModule().Resources {
|
||||
// if res.Type != "azurerm_local_network_gateway" {
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// id, err := parseAzureResourceID(res.Primary.ID)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// localNetName := id.Path["localNetworkGateways"]
|
||||
// resGrp := id.ResourceGroup
|
||||
//
|
||||
// lnetClient := testAccProvider.Meta().(*ArmClient).localNetConnClient
|
||||
// resp, err := lnetClient.Get(resGrp, localNetName)
|
||||
//
|
||||
// if err != nil {
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// if resp.StatusCode != http.StatusNotFound {
|
||||
// return fmt.Errorf("Local network gateway still exists:\n%#v", resp.Properties)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//var testAccAzureRMLocalNetworkGatewayConfig_basic = `
|
||||
//resource "azurerm_resource_group" "test" {
|
||||
// name = "tftestingResourceGroup"
|
||||
// location = "West US"
|
||||
//}
|
||||
//
|
||||
//resource "azurerm_local_network_gateway" "test" {
|
||||
// name = "tftestingLocalNetworkGateway"
|
||||
// location = "${azurerm_resource_group.test.location}"
|
||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
// gateway_address = "127.0.0.1"
|
||||
// address_space = ["127.0.0.0/8"]
|
||||
//}
|
||||
//`
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/core/http"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAzureRMLocalNetworkGateway_basic(t *testing.T) {
|
||||
name := "azurerm_local_network_gateway.test"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccAzureRMLocalNetworkGatewayConfig_basic,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMLocalNetworkGatewayExists(name),
|
||||
resource.TestCheckResourceAttr(name, "gateway_address", "127.0.0.1"),
|
||||
resource.TestCheckResourceAttr(name, "address_space.0", "127.0.0.0/8"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// testCheckAzureRMLocalNetworkGatewayExists returns the resurce.TestCheckFunc
|
||||
// which checks whether or not the expected local network gateway exists both
|
||||
// in the schema, and on Azure.
|
||||
func testCheckAzureRMLocalNetworkGatewayExists(name string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
// first check within the schema for the local network gateway:
|
||||
res, ok := s.RootModule().Resources[name]
|
||||
if !ok {
|
||||
return fmt.Errorf("Local network gateway '%s' not found.", name)
|
||||
}
|
||||
|
||||
// then, extract the name and the resource group:
|
||||
id, err := parseAzureResourceID(res.Primary.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
localNetName := id.Path["localNetworkGateways"]
|
||||
resGrp := id.ResourceGroup
|
||||
|
||||
// and finally, check that it exists on Azure:
|
||||
lnetClient := testAccProvider.Meta().(*ArmClient).localNetConnClient
|
||||
|
||||
resp, err := lnetClient.Get(resGrp, localNetName)
|
||||
if err != nil {
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
return fmt.Errorf("Local network gateway '%s' (resource group '%s') does not exist on Azure.", localNetName, resGrp)
|
||||
}
|
||||
|
||||
return fmt.Errorf("Error reading the state of local network gateway '%s'.", localNetName)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testCheckAzureRMLocalNetworkGatewayDestroy(s *terraform.State) error {
|
||||
for _, res := range s.RootModule().Resources {
|
||||
if res.Type != "azurerm_local_network_gateway" {
|
||||
continue
|
||||
}
|
||||
|
||||
id, err := parseAzureResourceID(res.Primary.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
localNetName := id.Path["localNetworkGateways"]
|
||||
resGrp := id.ResourceGroup
|
||||
|
||||
lnetClient := testAccProvider.Meta().(*ArmClient).localNetConnClient
|
||||
resp, err := lnetClient.Get(resGrp, localNetName)
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusNotFound {
|
||||
return fmt.Errorf("Local network gateway still exists:\n%#v", resp.Properties)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var testAccAzureRMLocalNetworkGatewayConfig_basic = `
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "tftestingResourceGroup"
|
||||
location = "West US"
|
||||
}
|
||||
|
||||
resource "azurerm_local_network_gateway" "test" {
|
||||
name = "tftestingLocalNetworkGateway"
|
||||
location = "${azurerm_resource_group.test.location}"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
gateway_address = "127.0.0.1"
|
||||
address_space = ["127.0.0.0/8"]
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue