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_availability_set": resourceArmAvailabilitySet(),
|
||||||
//"azurerm_cdn_endpoint": resourceArmCdnEndpoint(),
|
//"azurerm_cdn_endpoint": resourceArmCdnEndpoint(),
|
||||||
//"azurerm_cdn_profile": resourceArmCdnProfile(),
|
//"azurerm_cdn_profile": resourceArmCdnProfile(),
|
||||||
//"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
|
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
|
||||||
"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(),
|
||||||
|
|
|
@ -1,136 +1,146 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "fmt"
|
"fmt"
|
||||||
//
|
|
||||||
// "github.com/Azure/azure-sdk-for-go/arm/network"
|
"github.com/Azure/azure-sdk-for-go/arm/network"
|
||||||
// "github.com/Azure/azure-sdk-for-go/core/http"
|
"github.com/Azure/azure-sdk-for-go/core/http"
|
||||||
// "github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
//)
|
)
|
||||||
//
|
|
||||||
//func resourceArmLocalNetworkGateway() *schema.Resource {
|
func resourceArmLocalNetworkGateway() *schema.Resource {
|
||||||
// return &schema.Resource{
|
return &schema.Resource{
|
||||||
// Create: resourceArmLocalNetworkGatewayCreate,
|
Create: resourceArmLocalNetworkGatewayCreate,
|
||||||
// Read: resourceArmLocalNetworkGatewayRead,
|
Read: resourceArmLocalNetworkGatewayRead,
|
||||||
// Update: resourceArmLocalNetworkGatewayCreate,
|
Update: resourceArmLocalNetworkGatewayCreate,
|
||||||
// Delete: resourceArmLocalNetworkGatewayDelete,
|
Delete: resourceArmLocalNetworkGatewayDelete,
|
||||||
//
|
|
||||||
// Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
// "name": &schema.Schema{
|
"name": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Required: true,
|
Required: true,
|
||||||
// ForceNew: true,
|
ForceNew: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "location": &schema.Schema{
|
"location": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Optional: true,
|
Optional: true,
|
||||||
// ForceNew: true,
|
ForceNew: true,
|
||||||
// StateFunc: azureRMNormalizeLocation,
|
StateFunc: azureRMNormalizeLocation,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "resource_group_name": &schema.Schema{
|
"resource_group_name": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Optional: true,
|
Optional: true,
|
||||||
// ForceNew: true,
|
ForceNew: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "gateway_address": &schema.Schema{
|
"gateway_address": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Required: true,
|
Required: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "address_space": &schema.Schema{
|
"address_space": {
|
||||||
// Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
// Required: true,
|
Required: true,
|
||||||
// Elem: &schema.Schema{
|
Elem: &schema.Schema{
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func resourceArmLocalNetworkGatewayCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceArmLocalNetworkGatewayCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
// lnetClient := meta.(*ArmClient).localNetConnClient
|
lnetClient := meta.(*ArmClient).localNetConnClient
|
||||||
//
|
|
||||||
// name := d.Get("name").(string)
|
name := d.Get("name").(string)
|
||||||
// location := d.Get("location").(string)
|
location := d.Get("location").(string)
|
||||||
// resGroup := d.Get("resource_group_name").(string)
|
resGroup := d.Get("resource_group_name").(string)
|
||||||
// ipAddress := d.Get("gateway_address").(string)
|
ipAddress := d.Get("gateway_address").(string)
|
||||||
//
|
|
||||||
// // fetch the 'address_space_prefixes:
|
// fetch the 'address_space_prefixes:
|
||||||
// prefixes := []string{}
|
prefixes := []string{}
|
||||||
// for _, pref := range d.Get("address_space").([]interface{}) {
|
for _, pref := range d.Get("address_space").([]interface{}) {
|
||||||
// prefixes = append(prefixes, pref.(string))
|
prefixes = append(prefixes, pref.(string))
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// resp, err := lnetClient.CreateOrUpdate(resGroup, name, network.LocalNetworkGateway{
|
gateway := network.LocalNetworkGateway{
|
||||||
// Name: &name,
|
Name: &name,
|
||||||
// Location: &location,
|
Location: &location,
|
||||||
// Properties: &network.LocalNetworkGatewayPropertiesFormat{
|
Properties: &network.LocalNetworkGatewayPropertiesFormat{
|
||||||
// LocalNetworkAddressSpace: &network.AddressSpace{
|
LocalNetworkAddressSpace: &network.AddressSpace{
|
||||||
// AddressPrefixes: &prefixes,
|
AddressPrefixes: &prefixes,
|
||||||
// },
|
},
|
||||||
// GatewayIPAddress: &ipAddress,
|
GatewayIPAddress: &ipAddress,
|
||||||
// },
|
},
|
||||||
// })
|
}
|
||||||
// if err != nil {
|
|
||||||
// return fmt.Errorf("Error creating Azure ARM Local Network Gateway '%s': %s", name, err)
|
_, 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)
|
||||||
// d.SetId(*resp.ID)
|
}
|
||||||
//
|
|
||||||
// return resourceArmLocalNetworkGatewayRead(d, meta)
|
read, err := lnetClient.Get(resGroup, name)
|
||||||
//}
|
if err != nil {
|
||||||
//
|
return err
|
||||||
//// resourceArmLocalNetworkGatewayRead goes ahead and reads the state of the corresponding ARM local network gateway.
|
}
|
||||||
//func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}) error {
|
if read.ID == nil {
|
||||||
// lnetClient := meta.(*ArmClient).localNetConnClient
|
return fmt.Errorf("Cannot read Virtual Network %s (resource group %s) ID", name, resGroup)
|
||||||
//
|
}
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
|
||||||
// if err != nil {
|
d.SetId(*read.ID)
|
||||||
// return err
|
|
||||||
// }
|
return resourceArmLocalNetworkGatewayRead(d, meta)
|
||||||
// name := id.Path["localNetworkGateways"]
|
}
|
||||||
// resGroup := id.ResourceGroup
|
|
||||||
//
|
// resourceArmLocalNetworkGatewayRead goes ahead and reads the state of the corresponding ARM local network gateway.
|
||||||
// resp, err := lnetClient.Get(resGroup, name)
|
func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
// if err != nil {
|
lnetClient := meta.(*ArmClient).localNetConnClient
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
|
||||||
// d.SetId("")
|
id, err := parseAzureResourceID(d.Id())
|
||||||
// return nil
|
if err != nil {
|
||||||
// }
|
return err
|
||||||
//
|
}
|
||||||
// return fmt.Errorf("Error reading the state of Azure ARM local network gateway '%s': %s", name, err)
|
name := id.Path["localNetworkGateways"]
|
||||||
// }
|
resGroup := id.ResourceGroup
|
||||||
//
|
|
||||||
// d.Set("gateway_address", resp.Properties.GatewayIPAddress)
|
resp, err := lnetClient.Get(resGroup, name)
|
||||||
//
|
if err != nil {
|
||||||
// prefs := []string{}
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
// if ps := *resp.Properties.LocalNetworkAddressSpace.AddressPrefixes; ps != nil {
|
d.SetId("")
|
||||||
// prefs = ps
|
return nil
|
||||||
// }
|
}
|
||||||
// d.Set("address_space", prefs)
|
|
||||||
//
|
return fmt.Errorf("Error reading the state of Azure ARM local network gateway '%s': %s", name, err)
|
||||||
// return nil
|
}
|
||||||
//}
|
|
||||||
//
|
d.Set("gateway_address", resp.Properties.GatewayIPAddress)
|
||||||
//// resourceArmLocalNetworkGatewayDelete deletes the specified ARM local network gateway.
|
|
||||||
//func resourceArmLocalNetworkGatewayDelete(d *schema.ResourceData, meta interface{}) error {
|
prefs := []string{}
|
||||||
// lnetClient := meta.(*ArmClient).localNetConnClient
|
if ps := *resp.Properties.LocalNetworkAddressSpace.AddressPrefixes; ps != nil {
|
||||||
//
|
prefs = ps
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
}
|
||||||
// if err != nil {
|
d.Set("address_space", prefs)
|
||||||
// return err
|
|
||||||
// }
|
return nil
|
||||||
// name := id.Path["localNetworkGateways"]
|
}
|
||||||
// resGroup := id.ResourceGroup
|
|
||||||
//
|
// resourceArmLocalNetworkGatewayDelete deletes the specified ARM local network gateway.
|
||||||
// _, err = lnetClient.Delete(resGroup, name)
|
func resourceArmLocalNetworkGatewayDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
// if err != nil {
|
lnetClient := meta.(*ArmClient).localNetConnClient
|
||||||
// return fmt.Errorf("Error issuing Azure ARM delete request of local network gateway '%s': %s", name, err)
|
|
||||||
// }
|
id, err := parseAzureResourceID(d.Id())
|
||||||
//
|
if err != nil {
|
||||||
// return 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
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "testing"
|
"testing"
|
||||||
//
|
|
||||||
// "github.com/Azure/azure-sdk-for-go/core/http"
|
"github.com/Azure/azure-sdk-for-go/core/http"
|
||||||
// "github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
// "github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
//)
|
)
|
||||||
//
|
|
||||||
//func TestAccAzureRMLocalNetworkGateway_basic(t *testing.T) {
|
func TestAccAzureRMLocalNetworkGateway_basic(t *testing.T) {
|
||||||
// name := "azurerm_local_network_gateway.test"
|
name := "azurerm_local_network_gateway.test"
|
||||||
//
|
|
||||||
// resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
// PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
// Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
// CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy,
|
CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy,
|
||||||
// Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// resource.TestStep{
|
{
|
||||||
// Config: testAccAzureRMLocalNetworkGatewayConfig_basic,
|
Config: testAccAzureRMLocalNetworkGatewayConfig_basic,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMLocalNetworkGatewayExists(name),
|
testCheckAzureRMLocalNetworkGatewayExists(name),
|
||||||
// resource.TestCheckResourceAttr(name, "gateway_address", "127.0.0.1"),
|
resource.TestCheckResourceAttr(name, "gateway_address", "127.0.0.1"),
|
||||||
// resource.TestCheckResourceAttr(name, "address_space.0", "127.0.0.0/8"),
|
resource.TestCheckResourceAttr(name, "address_space.0", "127.0.0.0/8"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//// testCheckAzureRMLocalNetworkGatewayExists returns the resurce.TestCheckFunc
|
// testCheckAzureRMLocalNetworkGatewayExists returns the resurce.TestCheckFunc
|
||||||
//// which checks whether or not the expected local network gateway exists both
|
// which checks whether or not the expected local network gateway exists both
|
||||||
//// in the schema, and on Azure.
|
// in the schema, and on Azure.
|
||||||
//func testCheckAzureRMLocalNetworkGatewayExists(name string) resource.TestCheckFunc {
|
func testCheckAzureRMLocalNetworkGatewayExists(name string) resource.TestCheckFunc {
|
||||||
// return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
// // first check within the schema for the local network gateway:
|
// first check within the schema for the local network gateway:
|
||||||
// res, ok := s.RootModule().Resources[name]
|
res, ok := s.RootModule().Resources[name]
|
||||||
// if !ok {
|
if !ok {
|
||||||
// return fmt.Errorf("Local network gateway '%s' not found.", name)
|
return fmt.Errorf("Local network gateway '%s' not found.", name)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // then, extract the name and the resource group:
|
// then, extract the name and the resource group:
|
||||||
// id, err := parseAzureResourceID(res.Primary.ID)
|
id, err := parseAzureResourceID(res.Primary.ID)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
// localNetName := id.Path["localNetworkGateways"]
|
localNetName := id.Path["localNetworkGateways"]
|
||||||
// resGrp := id.ResourceGroup
|
resGrp := id.ResourceGroup
|
||||||
//
|
|
||||||
// // and finally, check that it exists on Azure:
|
// and finally, check that it exists on Azure:
|
||||||
// lnetClient := testAccProvider.Meta().(*ArmClient).localNetConnClient
|
lnetClient := testAccProvider.Meta().(*ArmClient).localNetConnClient
|
||||||
//
|
|
||||||
// resp, err := lnetClient.Get(resGrp, localNetName)
|
resp, err := lnetClient.Get(resGrp, localNetName)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
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("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 fmt.Errorf("Error reading the state of local network gateway '%s'.", localNetName)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func testCheckAzureRMLocalNetworkGatewayDestroy(s *terraform.State) error {
|
func testCheckAzureRMLocalNetworkGatewayDestroy(s *terraform.State) error {
|
||||||
// for _, res := range s.RootModule().Resources {
|
for _, res := range s.RootModule().Resources {
|
||||||
// if res.Type != "azurerm_local_network_gateway" {
|
if res.Type != "azurerm_local_network_gateway" {
|
||||||
// continue
|
continue
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// id, err := parseAzureResourceID(res.Primary.ID)
|
id, err := parseAzureResourceID(res.Primary.ID)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
// localNetName := id.Path["localNetworkGateways"]
|
localNetName := id.Path["localNetworkGateways"]
|
||||||
// resGrp := id.ResourceGroup
|
resGrp := id.ResourceGroup
|
||||||
//
|
|
||||||
// lnetClient := testAccProvider.Meta().(*ArmClient).localNetConnClient
|
lnetClient := testAccProvider.Meta().(*ArmClient).localNetConnClient
|
||||||
// resp, err := lnetClient.Get(resGrp, localNetName)
|
resp, err := lnetClient.Get(resGrp, localNetName)
|
||||||
//
|
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if resp.StatusCode != http.StatusNotFound {
|
if resp.StatusCode != http.StatusNotFound {
|
||||||
// return fmt.Errorf("Local network gateway still exists:\n%#v", resp.Properties)
|
return fmt.Errorf("Local network gateway still exists:\n%#v", resp.Properties)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return nil
|
return nil
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//var testAccAzureRMLocalNetworkGatewayConfig_basic = `
|
var testAccAzureRMLocalNetworkGatewayConfig_basic = `
|
||||||
//resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
// name = "tftestingResourceGroup"
|
name = "tftestingResourceGroup"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//resource "azurerm_local_network_gateway" "test" {
|
resource "azurerm_local_network_gateway" "test" {
|
||||||
// name = "tftestingLocalNetworkGateway"
|
name = "tftestingLocalNetworkGateway"
|
||||||
// location = "${azurerm_resource_group.test.location}"
|
location = "${azurerm_resource_group.test.location}"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// gateway_address = "127.0.0.1"
|
gateway_address = "127.0.0.1"
|
||||||
// address_space = ["127.0.0.0/8"]
|
address_space = ["127.0.0.0/8"]
|
||||||
//}
|
}
|
||||||
//`
|
`
|
||||||
|
|
Loading…
Reference in New Issue