provider/azurerm: Fix azurerm_subnet
``` make testacc TEST=./builtin/providers/azurerm TESTARGS="-run TestAccAzureRMSubnet" ==> Checking that code complies with gofmt requirements... /Users/James/Code/go/bin/stringer go generate $(go list ./... | grep -v /vendor/) 2016/06/01 16:54:37 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMSubnet -timeout 120m === RUN TestAccAzureRMSubnet_basic --- PASS: TestAccAzureRMSubnet_basic (131.83s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 131.844s ```
This commit is contained in:
parent
36a204506f
commit
876d0269df
|
@ -59,7 +59,7 @@ func Provider() terraform.ResourceProvider {
|
||||||
"azurerm_storage_blob": resourceArmStorageBlob(),
|
"azurerm_storage_blob": resourceArmStorageBlob(),
|
||||||
//"azurerm_storage_container": resourceArmStorageContainer(),
|
//"azurerm_storage_container": resourceArmStorageContainer(),
|
||||||
"azurerm_storage_queue": resourceArmStorageQueue(),
|
"azurerm_storage_queue": resourceArmStorageQueue(),
|
||||||
//"azurerm_subnet": resourceArmSubnet(),
|
"azurerm_subnet": resourceArmSubnet(),
|
||||||
//"azurerm_template_deployment": resourceArmTemplateDeployment(),
|
//"azurerm_template_deployment": resourceArmTemplateDeployment(),
|
||||||
//"azurerm_virtual_machine": resourceArmVirtualMachine(),
|
//"azurerm_virtual_machine": resourceArmVirtualMachine(),
|
||||||
"azurerm_virtual_network": resourceArmVirtualNetwork(),
|
"azurerm_virtual_network": resourceArmVirtualNetwork(),
|
||||||
|
|
|
@ -1,188 +1,184 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "log"
|
"log"
|
||||||
// "net/http"
|
"net/http"
|
||||||
// "time"
|
|
||||||
//
|
"github.com/Azure/azure-sdk-for-go/arm/network"
|
||||||
// "github.com/Azure/azure-sdk-for-go/arm/network"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
// "github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
// "github.com/hashicorp/terraform/helper/schema"
|
)
|
||||||
//)
|
|
||||||
//
|
func resourceArmSubnet() *schema.Resource {
|
||||||
//func resourceArmSubnet() *schema.Resource {
|
return &schema.Resource{
|
||||||
// return &schema.Resource{
|
Create: resourceArmSubnetCreate,
|
||||||
// Create: resourceArmSubnetCreate,
|
Read: resourceArmSubnetRead,
|
||||||
// Read: resourceArmSubnetRead,
|
Update: resourceArmSubnetCreate,
|
||||||
// Update: resourceArmSubnetCreate,
|
Delete: resourceArmSubnetDelete,
|
||||||
// Delete: resourceArmSubnetDelete,
|
|
||||||
//
|
Schema: map[string]*schema.Schema{
|
||||||
// Schema: map[string]*schema.Schema{
|
"name": {
|
||||||
// "name": &schema.Schema{
|
Type: schema.TypeString,
|
||||||
// Type: schema.TypeString,
|
Required: true,
|
||||||
// Required: true,
|
ForceNew: true,
|
||||||
// ForceNew: true,
|
},
|
||||||
// },
|
|
||||||
//
|
"resource_group_name": {
|
||||||
// "resource_group_name": &schema.Schema{
|
Type: schema.TypeString,
|
||||||
// Type: schema.TypeString,
|
Required: true,
|
||||||
// Required: true,
|
ForceNew: true,
|
||||||
// ForceNew: true,
|
},
|
||||||
// },
|
|
||||||
//
|
"virtual_network_name": {
|
||||||
// "virtual_network_name": &schema.Schema{
|
Type: schema.TypeString,
|
||||||
// Type: schema.TypeString,
|
Required: true,
|
||||||
// Required: true,
|
ForceNew: true,
|
||||||
// ForceNew: true,
|
},
|
||||||
// },
|
|
||||||
//
|
"address_prefix": {
|
||||||
// "address_prefix": &schema.Schema{
|
Type: schema.TypeString,
|
||||||
// Type: schema.TypeString,
|
Required: true,
|
||||||
// Required: true,
|
},
|
||||||
// },
|
|
||||||
//
|
"network_security_group_id": {
|
||||||
// "network_security_group_id": &schema.Schema{
|
Type: schema.TypeString,
|
||||||
// Type: schema.TypeString,
|
Optional: true,
|
||||||
// Optional: true,
|
Computed: true,
|
||||||
// Computed: true,
|
},
|
||||||
// },
|
|
||||||
//
|
"route_table_id": {
|
||||||
// "route_table_id": &schema.Schema{
|
Type: schema.TypeString,
|
||||||
// Type: schema.TypeString,
|
Optional: true,
|
||||||
// Optional: true,
|
Computed: true,
|
||||||
// Computed: true,
|
},
|
||||||
// },
|
|
||||||
//
|
"ip_configurations": {
|
||||||
// "ip_configurations": &schema.Schema{
|
Type: schema.TypeSet,
|
||||||
// Type: schema.TypeSet,
|
Optional: true,
|
||||||
// Optional: true,
|
Computed: true,
|
||||||
// Computed: true,
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
// Elem: &schema.Schema{Type: schema.TypeString},
|
Set: schema.HashString,
|
||||||
// Set: schema.HashString,
|
},
|
||||||
// },
|
},
|
||||||
// },
|
}
|
||||||
// }
|
}
|
||||||
//}
|
|
||||||
//
|
func resourceArmSubnetCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
//func resourceArmSubnetCreate(d *schema.ResourceData, meta interface{}) error {
|
client := meta.(*ArmClient)
|
||||||
// client := meta.(*ArmClient)
|
subnetClient := client.subnetClient
|
||||||
// subnetClient := client.subnetClient
|
|
||||||
//
|
log.Printf("[INFO] preparing arguments for Azure ARM Subnet creation.")
|
||||||
// log.Printf("[INFO] preparing arguments for Azure ARM Subnet creation.")
|
|
||||||
//
|
name := d.Get("name").(string)
|
||||||
// name := d.Get("name").(string)
|
vnetName := d.Get("virtual_network_name").(string)
|
||||||
// vnetName := d.Get("virtual_network_name").(string)
|
resGroup := d.Get("resource_group_name").(string)
|
||||||
// resGroup := d.Get("resource_group_name").(string)
|
addressPrefix := d.Get("address_prefix").(string)
|
||||||
// addressPrefix := d.Get("address_prefix").(string)
|
|
||||||
//
|
armMutexKV.Lock(vnetName)
|
||||||
// armMutexKV.Lock(vnetName)
|
defer armMutexKV.Unlock(vnetName)
|
||||||
// defer armMutexKV.Unlock(vnetName)
|
|
||||||
//
|
properties := network.SubnetPropertiesFormat{
|
||||||
// properties := network.SubnetPropertiesFormat{
|
AddressPrefix: &addressPrefix,
|
||||||
// AddressPrefix: &addressPrefix,
|
}
|
||||||
// }
|
|
||||||
//
|
if v, ok := d.GetOk("network_security_group_id"); ok {
|
||||||
// if v, ok := d.GetOk("network_security_group_id"); ok {
|
nsgId := v.(string)
|
||||||
// nsgId := v.(string)
|
properties.NetworkSecurityGroup = &network.SecurityGroup{
|
||||||
// properties.NetworkSecurityGroup = &network.SecurityGroup{
|
ID: &nsgId,
|
||||||
// ID: &nsgId,
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
if v, ok := d.GetOk("route_table_id"); ok {
|
||||||
// if v, ok := d.GetOk("route_table_id"); ok {
|
rtId := v.(string)
|
||||||
// rtId := v.(string)
|
properties.RouteTable = &network.RouteTable{
|
||||||
// properties.RouteTable = &network.RouteTable{
|
ID: &rtId,
|
||||||
// ID: &rtId,
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
subnet := network.Subnet{
|
||||||
// subnet := network.Subnet{
|
Name: &name,
|
||||||
// Name: &name,
|
Properties: &properties,
|
||||||
// Properties: &properties,
|
}
|
||||||
// }
|
|
||||||
//
|
_, err := subnetClient.CreateOrUpdate(resGroup, vnetName, name, subnet, make(chan struct{}))
|
||||||
// resp, err := subnetClient.CreateOrUpdate(resGroup, vnetName, name, subnet)
|
if err != nil {
|
||||||
// if err != nil {
|
return err
|
||||||
// return err
|
}
|
||||||
// }
|
|
||||||
//
|
read, err := subnetClient.Get(resGroup, vnetName, name, "")
|
||||||
// d.SetId(*resp.ID)
|
if err != nil {
|
||||||
//
|
return err
|
||||||
// log.Printf("[DEBUG] Waiting for Subnet (%s) to become available", name)
|
}
|
||||||
// stateConf := &resource.StateChangeConf{
|
if read.ID == nil {
|
||||||
// Pending: []string{"Accepted", "Updating"},
|
return fmt.Errorf("Cannot read Subnet %s/%s (resource group %s) ID", vnetName, name, resGroup)
|
||||||
// Target: []string{"Succeeded"},
|
}
|
||||||
// Refresh: subnetRuleStateRefreshFunc(client, resGroup, vnetName, name),
|
|
||||||
// Timeout: 10 * time.Minute,
|
d.SetId(*read.ID)
|
||||||
// }
|
|
||||||
// if _, err := stateConf.WaitForState(); err != nil {
|
return resourceArmSubnetRead(d, meta)
|
||||||
// return fmt.Errorf("Error waiting for Subnet (%s) to become available: %s", name, err)
|
}
|
||||||
// }
|
|
||||||
//
|
func resourceArmSubnetRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
// return resourceArmSubnetRead(d, meta)
|
subnetClient := meta.(*ArmClient).subnetClient
|
||||||
//}
|
|
||||||
//
|
id, err := parseAzureResourceID(d.Id())
|
||||||
//func resourceArmSubnetRead(d *schema.ResourceData, meta interface{}) error {
|
if err != nil {
|
||||||
// subnetClient := meta.(*ArmClient).subnetClient
|
return err
|
||||||
//
|
}
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
resGroup := id.ResourceGroup
|
||||||
// if err != nil {
|
vnetName := id.Path["virtualNetworks"]
|
||||||
// return err
|
name := id.Path["subnets"]
|
||||||
// }
|
|
||||||
// resGroup := id.ResourceGroup
|
resp, err := subnetClient.Get(resGroup, vnetName, name, "")
|
||||||
// vnetName := id.Path["virtualNetworks"]
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
// name := id.Path["subnets"]
|
d.SetId("")
|
||||||
//
|
return nil
|
||||||
// resp, err := subnetClient.Get(resGroup, vnetName, name, "")
|
}
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
if err != nil {
|
||||||
// d.SetId("")
|
return fmt.Errorf("Error making Read request on Azure Subnet %s: %s", name, err)
|
||||||
// return nil
|
}
|
||||||
// }
|
|
||||||
// if err != nil {
|
if resp.Properties.IPConfigurations != nil && len(*resp.Properties.IPConfigurations) > 0 {
|
||||||
// return fmt.Errorf("Error making Read request on Azure Subnet %s: %s", name, err)
|
ips := make([]string, 0, len(*resp.Properties.IPConfigurations))
|
||||||
// }
|
for _, ip := range *resp.Properties.IPConfigurations {
|
||||||
//
|
ips = append(ips, *ip.ID)
|
||||||
// if resp.Properties.IPConfigurations != nil && len(*resp.Properties.IPConfigurations) > 0 {
|
}
|
||||||
// ips := make([]string, 0, len(*resp.Properties.IPConfigurations))
|
|
||||||
// for _, ip := range *resp.Properties.IPConfigurations {
|
if err := d.Set("ip_configurations", ips); err != nil {
|
||||||
// ips = append(ips, *ip.ID)
|
return err
|
||||||
// }
|
}
|
||||||
//
|
}
|
||||||
// if err := d.Set("ip_configurations", ips); err != nil {
|
|
||||||
// return err
|
return nil
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
func resourceArmSubnetDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
// return nil
|
subnetClient := meta.(*ArmClient).subnetClient
|
||||||
//}
|
|
||||||
//
|
id, err := parseAzureResourceID(d.Id())
|
||||||
//func resourceArmSubnetDelete(d *schema.ResourceData, meta interface{}) error {
|
if err != nil {
|
||||||
// subnetClient := meta.(*ArmClient).subnetClient
|
return err
|
||||||
//
|
}
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
resGroup := id.ResourceGroup
|
||||||
// if err != nil {
|
name := id.Path["subnets"]
|
||||||
// return err
|
vnetName := id.Path["virtualNetworks"]
|
||||||
// }
|
|
||||||
// resGroup := id.ResourceGroup
|
armMutexKV.Lock(vnetName)
|
||||||
// name := id.Path["subnets"]
|
defer armMutexKV.Unlock(vnetName)
|
||||||
// vnetName := id.Path["virtualNetworks"]
|
|
||||||
//
|
_, err = subnetClient.Delete(resGroup, vnetName, name, make(chan struct{}))
|
||||||
// armMutexKV.Lock(vnetName)
|
|
||||||
// defer armMutexKV.Unlock(vnetName)
|
return err
|
||||||
//
|
}
|
||||||
// _, err = subnetClient.Delete(resGroup, vnetName, name)
|
|
||||||
//
|
func subnetRuleStateRefreshFunc(client *ArmClient, resourceGroupName string, virtualNetworkName string, subnetName string) resource.StateRefreshFunc {
|
||||||
// return err
|
return func() (interface{}, string, error) {
|
||||||
//}
|
res, err := client.subnetClient.Get(resourceGroupName, virtualNetworkName, subnetName, "")
|
||||||
//
|
if err != nil {
|
||||||
//func subnetRuleStateRefreshFunc(client *ArmClient, resourceGroupName string, virtualNetworkName string, subnetName string) resource.StateRefreshFunc {
|
return nil, "", fmt.Errorf("Error issuing read request in subnetRuleStateRefreshFunc to Azure ARM for subnet '%s' (RG: '%s') (VNN: '%s'): %s", subnetName, resourceGroupName, virtualNetworkName, err)
|
||||||
// return func() (interface{}, string, error) {
|
}
|
||||||
// res, err := client.subnetClient.Get(resourceGroupName, virtualNetworkName, subnetName, "")
|
|
||||||
// if err != nil {
|
return res, *res.Properties.ProvisioningState, nil
|
||||||
// return nil, "", fmt.Errorf("Error issuing read request in subnetRuleStateRefreshFunc to Azure ARM for subnet '%s' (RG: '%s') (VNN: '%s'): %s", subnetName, resourceGroupName, virtualNetworkName, err)
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return res, *res.Properties.ProvisioningState, nil
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
|
@ -1,108 +1,108 @@
|
||||||
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 TestAccAzureRMSubnet_basic(t *testing.T) {
|
func TestAccAzureRMSubnet_basic(t *testing.T) {
|
||||||
//
|
|
||||||
// ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
// config := fmt.Sprintf(testAccAzureRMSubnet_basic, ri, ri, ri)
|
config := fmt.Sprintf(testAccAzureRMSubnet_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: testCheckAzureRMSubnetDestroy,
|
CheckDestroy: testCheckAzureRMSubnetDestroy,
|
||||||
// Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// resource.TestStep{
|
resource.TestStep{
|
||||||
// Config: config,
|
Config: config,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMSubnetExists("azurerm_subnet.test"),
|
testCheckAzureRMSubnetExists("azurerm_subnet.test"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func testCheckAzureRMSubnetExists(name string) resource.TestCheckFunc {
|
func testCheckAzureRMSubnetExists(name string) resource.TestCheckFunc {
|
||||||
// return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
// // Ensure we have enough information in state to look up in API
|
// Ensure we have enough information in state to look up in API
|
||||||
// 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"]
|
||||||
// vnetName := rs.Primary.Attributes["virtual_network_name"]
|
vnetName := rs.Primary.Attributes["virtual_network_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 subnet: %s", name)
|
return fmt.Errorf("Bad: no resource group found in state for subnet: %s", name)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// conn := testAccProvider.Meta().(*ArmClient).subnetClient
|
conn := testAccProvider.Meta().(*ArmClient).subnetClient
|
||||||
//
|
|
||||||
// resp, err := conn.Get(resourceGroup, vnetName, name, "")
|
resp, err := conn.Get(resourceGroup, vnetName, name, "")
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return fmt.Errorf("Bad: Get on subnetClient: %s", err)
|
return fmt.Errorf("Bad: Get on subnetClient: %s", err)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
// return fmt.Errorf("Bad: Subnet %q (resource group: %q) does not exist", name, resourceGroup)
|
return fmt.Errorf("Bad: Subnet %q (resource group: %q) does not exist", name, resourceGroup)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func testCheckAzureRMSubnetDestroy(s *terraform.State) error {
|
func testCheckAzureRMSubnetDestroy(s *terraform.State) error {
|
||||||
// conn := testAccProvider.Meta().(*ArmClient).subnetClient
|
conn := testAccProvider.Meta().(*ArmClient).subnetClient
|
||||||
//
|
|
||||||
// for _, rs := range s.RootModule().Resources {
|
for _, rs := range s.RootModule().Resources {
|
||||||
// if rs.Type != "azurerm_subnet" {
|
if rs.Type != "azurerm_subnet" {
|
||||||
// continue
|
continue
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// name := rs.Primary.Attributes["name"]
|
name := rs.Primary.Attributes["name"]
|
||||||
// vnetName := rs.Primary.Attributes["virtual_network_name"]
|
vnetName := rs.Primary.Attributes["virtual_network_name"]
|
||||||
// resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
//
|
|
||||||
// resp, err := conn.Get(resourceGroup, vnetName, name, "")
|
resp, err := conn.Get(resourceGroup, vnetName, name, "")
|
||||||
//
|
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if resp.StatusCode != http.StatusNotFound {
|
if resp.StatusCode != http.StatusNotFound {
|
||||||
// return fmt.Errorf("Subnet still exists:\n%#v", resp.Properties)
|
return fmt.Errorf("Subnet still exists:\n%#v", resp.Properties)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return nil
|
return nil
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//var testAccAzureRMSubnet_basic = `
|
var testAccAzureRMSubnet_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_virtual_network" "test" {
|
resource "azurerm_virtual_network" "test" {
|
||||||
// name = "acctestvirtnet%d"
|
name = "acctestvirtnet%d"
|
||||||
// address_space = ["10.0.0.0/16"]
|
address_space = ["10.0.0.0/16"]
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//resource "azurerm_subnet" "test" {
|
resource "azurerm_subnet" "test" {
|
||||||
// name = "acctestsubnet%d"
|
name = "acctestsubnet%d"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// virtual_network_name = "${azurerm_virtual_network.test.name}"
|
virtual_network_name = "${azurerm_virtual_network.test.name}"
|
||||||
// address_prefix = "10.0.2.0/24"
|
address_prefix = "10.0.2.0/24"
|
||||||
//}
|
}
|
||||||
//`
|
`
|
||||||
|
|
Loading…
Reference in New Issue