provider/azurerm: Fix azurerm_storage_account
``` HTTP_PROXY=http://localhost:8888 make testacc TEST=./builtin/providers/azurerm TESTARGS="-run TestAccAzureRMStorageAccount" ==> Checking that code complies with gofmt requirements... /Users/James/Code/go/bin/stringer go generate $(go list ./... | grep -v /vendor/) 2016/06/01 18:05:12 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMStorageAccount -timeout 120m === RUN TestAccAzureRMStorageAccount_basic --- PASS: TestAccAzureRMStorageAccount_basic (89.48s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 89.491s ```
This commit is contained in:
parent
3831553c72
commit
26e2c9bec2
|
@ -55,8 +55,8 @@ func Provider() terraform.ResourceProvider {
|
||||||
"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(),
|
||||||
//"azurerm_storage_container": resourceArmStorageContainer(),
|
//"azurerm_storage_container": resourceArmStorageContainer(),
|
||||||
"azurerm_storage_queue": resourceArmStorageQueue(),
|
"azurerm_storage_queue": resourceArmStorageQueue(),
|
||||||
"azurerm_subnet": resourceArmSubnet(),
|
"azurerm_subnet": resourceArmSubnet(),
|
||||||
|
|
|
@ -1,309 +1,297 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "net/http"
|
"net/http"
|
||||||
// "regexp"
|
"regexp"
|
||||||
// "strings"
|
"strings"
|
||||||
//
|
|
||||||
// "github.com/Azure/azure-sdk-for-go/arm/storage"
|
"github.com/Azure/azure-sdk-for-go/arm/storage"
|
||||||
// "github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
//)
|
)
|
||||||
//
|
|
||||||
//func resourceArmStorageAccount() *schema.Resource {
|
func resourceArmStorageAccount() *schema.Resource {
|
||||||
// return &schema.Resource{
|
return &schema.Resource{
|
||||||
// Create: resourceArmStorageAccountCreate,
|
Create: resourceArmStorageAccountCreate,
|
||||||
// Read: resourceArmStorageAccountRead,
|
Read: resourceArmStorageAccountRead,
|
||||||
// Update: resourceArmStorageAccountUpdate,
|
Update: resourceArmStorageAccountUpdate,
|
||||||
// Delete: resourceArmStorageAccountDelete,
|
Delete: resourceArmStorageAccountDelete,
|
||||||
//
|
|
||||||
// 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,
|
||||||
// ValidateFunc: validateArmStorageAccountName,
|
ValidateFunc: validateArmStorageAccountName,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "resource_group_name": &schema.Schema{
|
"resource_group_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,
|
||||||
// Required: true,
|
Required: true,
|
||||||
// ForceNew: true,
|
ForceNew: true,
|
||||||
// StateFunc: azureRMNormalizeLocation,
|
StateFunc: azureRMNormalizeLocation,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "account_type": &schema.Schema{
|
"account_type": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Required: true,
|
Required: true,
|
||||||
// ValidateFunc: validateArmStorageAccountType,
|
ValidateFunc: validateArmStorageAccountType,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "primary_location": &schema.Schema{
|
"primary_location": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "secondary_location": &schema.Schema{
|
"secondary_location": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "primary_blob_endpoint": &schema.Schema{
|
"primary_blob_endpoint": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "secondary_blob_endpoint": &schema.Schema{
|
"secondary_blob_endpoint": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "primary_queue_endpoint": &schema.Schema{
|
"primary_queue_endpoint": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "secondary_queue_endpoint": &schema.Schema{
|
"secondary_queue_endpoint": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "primary_table_endpoint": &schema.Schema{
|
"primary_table_endpoint": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "secondary_table_endpoint": &schema.Schema{
|
"secondary_table_endpoint": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// // NOTE: The API does not appear to expose a secondary file endpoint
|
// NOTE: The API does not appear to expose a secondary file endpoint
|
||||||
// "primary_file_endpoint": &schema.Schema{
|
"primary_file_endpoint": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "primary_access_key": &schema.Schema{
|
"primary_access_key": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "secondary_access_key": &schema.Schema{
|
"secondary_access_key": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "tags": tagsSchema(),
|
"tags": tagsSchema(),
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
// client := meta.(*ArmClient).storageServiceClient
|
client := meta.(*ArmClient).storageServiceClient
|
||||||
//
|
|
||||||
// resourceGroupName := d.Get("resource_group_name").(string)
|
resourceGroupName := d.Get("resource_group_name").(string)
|
||||||
// storageAccountName := d.Get("name").(string)
|
storageAccountName := d.Get("name").(string)
|
||||||
// accountType := d.Get("account_type").(string)
|
accountType := d.Get("account_type").(string)
|
||||||
// location := d.Get("location").(string)
|
location := d.Get("location").(string)
|
||||||
// tags := d.Get("tags").(map[string]interface{})
|
tags := d.Get("tags").(map[string]interface{})
|
||||||
//
|
|
||||||
// opts := storage.AccountCreateParameters{
|
opts := storage.AccountCreateParameters{
|
||||||
// Location: &location,
|
Location: &location,
|
||||||
// Properties: &storage.AccountPropertiesCreateParameters{
|
Properties: &storage.AccountPropertiesCreateParameters{
|
||||||
// AccountType: storage.AccountType(accountType),
|
AccountType: storage.AccountType(accountType),
|
||||||
// },
|
},
|
||||||
// Tags: expandTags(tags),
|
Tags: expandTags(tags),
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// accResp, err := client.Create(resourceGroupName, storageAccountName, opts)
|
_, err := client.Create(resourceGroupName, storageAccountName, opts, make(chan struct{}))
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return fmt.Errorf("Error creating Azure Storage Account '%s': %s", storageAccountName, err)
|
return fmt.Errorf("Error creating Azure Storage Account '%s': %s", storageAccountName, err)
|
||||||
// }
|
}
|
||||||
// _, err = pollIndefinitelyAsNeeded(client.Client, accResp.Response.Response, http.StatusOK)
|
|
||||||
// if err != nil {
|
// The only way to get the ID back apparently is to read the resource again
|
||||||
// return fmt.Errorf("Error creating Azure Storage Account %q: %s", storageAccountName, err)
|
read, err := client.GetProperties(resourceGroupName, storageAccountName)
|
||||||
// }
|
if err != nil {
|
||||||
//
|
return err
|
||||||
// // The only way to get the ID back apparently is to read the resource again
|
}
|
||||||
// account, err := client.GetProperties(resourceGroupName, storageAccountName)
|
if read.ID == nil {
|
||||||
// if err != nil {
|
return fmt.Errorf("Cannot read Storage Account %s (resource group %s) ID",
|
||||||
// return fmt.Errorf("Error retrieving Azure Storage Account %q: %s", storageAccountName, err)
|
storageAccountName, resourceGroupName)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// d.SetId(*account.ID)
|
d.SetId(*read.ID)
|
||||||
//
|
|
||||||
// return resourceArmStorageAccountRead(d, meta)
|
return resourceArmStorageAccountRead(d, meta)
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//// resourceArmStorageAccountUpdate is unusual in the ARM API where most resources have a combined
|
// resourceArmStorageAccountUpdate is unusual in the ARM API where most resources have a combined
|
||||||
//// and idempotent operation for CreateOrUpdate. In particular updating all of the parameters
|
// and idempotent operation for CreateOrUpdate. In particular updating all of the parameters
|
||||||
//// available requires a call to Update per parameter...
|
// available requires a call to Update per parameter...
|
||||||
//func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) error {
|
func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
// client := meta.(*ArmClient).storageServiceClient
|
client := meta.(*ArmClient).storageServiceClient
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
id, err := parseAzureResourceID(d.Id())
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
// storageAccountName := id.Path["storageAccounts"]
|
storageAccountName := id.Path["storageAccounts"]
|
||||||
// resourceGroupName := id.ResourceGroup
|
resourceGroupName := id.ResourceGroup
|
||||||
//
|
|
||||||
// d.Partial(true)
|
d.Partial(true)
|
||||||
//
|
|
||||||
// if d.HasChange("account_type") {
|
if d.HasChange("account_type") {
|
||||||
// accountType := d.Get("account_type").(string)
|
accountType := d.Get("account_type").(string)
|
||||||
//
|
|
||||||
// opts := storage.AccountUpdateParameters{
|
opts := storage.AccountUpdateParameters{
|
||||||
// Properties: &storage.AccountPropertiesUpdateParameters{
|
Properties: &storage.AccountPropertiesUpdateParameters{
|
||||||
// AccountType: storage.AccountType(accountType),
|
AccountType: storage.AccountType(accountType),
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
// accResp, err := client.Update(resourceGroupName, storageAccountName, opts)
|
_, err := client.Update(resourceGroupName, storageAccountName, opts)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return fmt.Errorf("Error updating Azure Storage Account type %q: %s", storageAccountName, err)
|
return fmt.Errorf("Error updating Azure Storage Account type %q: %s", storageAccountName, err)
|
||||||
// }
|
}
|
||||||
// _, err = pollIndefinitelyAsNeeded(client.Client, accResp.Response.Response, http.StatusOK)
|
|
||||||
// if err != nil {
|
d.SetPartial("account_type")
|
||||||
// return fmt.Errorf("Error updating Azure Storage Account type %q: %s", storageAccountName, err)
|
}
|
||||||
// }
|
|
||||||
//
|
if d.HasChange("tags") {
|
||||||
// d.SetPartial("account_type")
|
tags := d.Get("tags").(map[string]interface{})
|
||||||
// }
|
|
||||||
//
|
opts := storage.AccountUpdateParameters{
|
||||||
// if d.HasChange("tags") {
|
Tags: expandTags(tags),
|
||||||
// tags := d.Get("tags").(map[string]interface{})
|
}
|
||||||
//
|
_, err := client.Update(resourceGroupName, storageAccountName, opts)
|
||||||
// opts := storage.AccountUpdateParameters{
|
if err != nil {
|
||||||
// Tags: expandTags(tags),
|
return fmt.Errorf("Error updating Azure Storage Account tags %q: %s", storageAccountName, err)
|
||||||
// }
|
}
|
||||||
// accResp, err := client.Update(resourceGroupName, storageAccountName, opts)
|
|
||||||
// if err != nil {
|
d.SetPartial("tags")
|
||||||
// return fmt.Errorf("Error updating Azure Storage Account tags %q: %s", storageAccountName, err)
|
}
|
||||||
// }
|
|
||||||
// _, err = pollIndefinitelyAsNeeded(client.Client, accResp.Response.Response, http.StatusOK)
|
d.Partial(false)
|
||||||
// if err != nil {
|
return nil
|
||||||
// return fmt.Errorf("Error updating Azure Storage Account tags %q: %s", storageAccountName, err)
|
}
|
||||||
// }
|
|
||||||
//
|
func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
// d.SetPartial("tags")
|
client := meta.(*ArmClient).storageServiceClient
|
||||||
// }
|
|
||||||
//
|
id, err := parseAzureResourceID(d.Id())
|
||||||
// d.Partial(false)
|
if err != nil {
|
||||||
// return nil
|
return err
|
||||||
//}
|
}
|
||||||
//
|
name := id.Path["storageAccounts"]
|
||||||
//func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) error {
|
resGroup := id.ResourceGroup
|
||||||
// client := meta.(*ArmClient).storageServiceClient
|
|
||||||
//
|
resp, err := client.GetProperties(resGroup, name)
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
if err != nil {
|
||||||
// if err != nil {
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
// return err
|
d.SetId("")
|
||||||
// }
|
return nil
|
||||||
// name := id.Path["storageAccounts"]
|
}
|
||||||
// resGroup := id.ResourceGroup
|
|
||||||
//
|
return fmt.Errorf("Error reading the state of AzureRM Storage Account %q: %s", name, err)
|
||||||
// resp, err := client.GetProperties(resGroup, name)
|
}
|
||||||
// if err != nil {
|
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
keys, err := client.ListKeys(resGroup, name)
|
||||||
// d.SetId("")
|
if err != nil {
|
||||||
// return nil
|
return err
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return fmt.Errorf("Error reading the state of AzureRM Storage Account %q: %s", name, err)
|
d.Set("primary_access_key", keys.Key1)
|
||||||
// }
|
d.Set("secondary_access_key", keys.Key2)
|
||||||
//
|
d.Set("location", resp.Location)
|
||||||
// keys, err := client.ListKeys(resGroup, name)
|
d.Set("account_type", resp.Properties.AccountType)
|
||||||
// if err != nil {
|
d.Set("primary_location", resp.Properties.PrimaryLocation)
|
||||||
// return err
|
d.Set("secondary_location", resp.Properties.SecondaryLocation)
|
||||||
// }
|
|
||||||
//
|
if resp.Properties.PrimaryEndpoints != nil {
|
||||||
// d.Set("primary_access_key", keys.Key1)
|
d.Set("primary_blob_endpoint", resp.Properties.PrimaryEndpoints.Blob)
|
||||||
// d.Set("secondary_access_key", keys.Key2)
|
d.Set("primary_queue_endpoint", resp.Properties.PrimaryEndpoints.Queue)
|
||||||
// d.Set("location", resp.Location)
|
d.Set("primary_table_endpoint", resp.Properties.PrimaryEndpoints.Table)
|
||||||
// d.Set("account_type", resp.Properties.AccountType)
|
d.Set("primary_file_endpoint", resp.Properties.PrimaryEndpoints.File)
|
||||||
// d.Set("primary_location", resp.Properties.PrimaryLocation)
|
}
|
||||||
// d.Set("secondary_location", resp.Properties.SecondaryLocation)
|
|
||||||
//
|
if resp.Properties.SecondaryEndpoints != nil {
|
||||||
// if resp.Properties.PrimaryEndpoints != nil {
|
if resp.Properties.SecondaryEndpoints.Blob != nil {
|
||||||
// d.Set("primary_blob_endpoint", resp.Properties.PrimaryEndpoints.Blob)
|
d.Set("secondary_blob_endpoint", resp.Properties.SecondaryEndpoints.Blob)
|
||||||
// d.Set("primary_queue_endpoint", resp.Properties.PrimaryEndpoints.Queue)
|
} else {
|
||||||
// d.Set("primary_table_endpoint", resp.Properties.PrimaryEndpoints.Table)
|
d.Set("secondary_blob_endpoint", "")
|
||||||
// d.Set("primary_file_endpoint", resp.Properties.PrimaryEndpoints.File)
|
}
|
||||||
// }
|
if resp.Properties.SecondaryEndpoints.Queue != nil {
|
||||||
//
|
d.Set("secondary_queue_endpoint", resp.Properties.SecondaryEndpoints.Queue)
|
||||||
// if resp.Properties.SecondaryEndpoints != nil {
|
} else {
|
||||||
// if resp.Properties.SecondaryEndpoints.Blob != nil {
|
d.Set("secondary_queue_endpoint", "")
|
||||||
// d.Set("secondary_blob_endpoint", resp.Properties.SecondaryEndpoints.Blob)
|
}
|
||||||
// } else {
|
if resp.Properties.SecondaryEndpoints.Table != nil {
|
||||||
// d.Set("secondary_blob_endpoint", "")
|
d.Set("secondary_table_endpoint", resp.Properties.SecondaryEndpoints.Table)
|
||||||
// }
|
} else {
|
||||||
// if resp.Properties.SecondaryEndpoints.Queue != nil {
|
d.Set("secondary_table_endpoint", "")
|
||||||
// d.Set("secondary_queue_endpoint", resp.Properties.SecondaryEndpoints.Queue)
|
}
|
||||||
// } else {
|
}
|
||||||
// d.Set("secondary_queue_endpoint", "")
|
|
||||||
// }
|
flattenAndSetTags(d, resp.Tags)
|
||||||
// if resp.Properties.SecondaryEndpoints.Table != nil {
|
|
||||||
// d.Set("secondary_table_endpoint", resp.Properties.SecondaryEndpoints.Table)
|
return nil
|
||||||
// } else {
|
}
|
||||||
// d.Set("secondary_table_endpoint", "")
|
|
||||||
// }
|
func resourceArmStorageAccountDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
// }
|
client := meta.(*ArmClient).storageServiceClient
|
||||||
//
|
|
||||||
// flattenAndSetTags(d, resp.Tags)
|
id, err := parseAzureResourceID(d.Id())
|
||||||
//
|
if err != nil {
|
||||||
// return nil
|
return err
|
||||||
//}
|
}
|
||||||
//
|
name := id.Path["storageAccounts"]
|
||||||
//func resourceArmStorageAccountDelete(d *schema.ResourceData, meta interface{}) error {
|
resGroup := id.ResourceGroup
|
||||||
// client := meta.(*ArmClient).storageServiceClient
|
|
||||||
//
|
_, err = client.Delete(resGroup, name)
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
if err != nil {
|
||||||
// if err != nil {
|
return fmt.Errorf("Error issuing AzureRM delete request for storage account %q: %s", name, err)
|
||||||
// return err
|
}
|
||||||
// }
|
|
||||||
// name := id.Path["storageAccounts"]
|
return nil
|
||||||
// resGroup := id.ResourceGroup
|
}
|
||||||
//
|
|
||||||
// accResp, err := client.Delete(resGroup, name)
|
func validateArmStorageAccountName(v interface{}, k string) (ws []string, es []error) {
|
||||||
// if err != nil {
|
input := v.(string)
|
||||||
// return fmt.Errorf("Error issuing AzureRM delete request for storage account %q: %s", name, err)
|
|
||||||
// }
|
if !regexp.MustCompile(`\A([a-z0-9]{3,24})\z`).MatchString(input) {
|
||||||
// _, err = pollIndefinitelyAsNeeded(client.Client, accResp.Response, http.StatusNotFound)
|
es = append(es, fmt.Errorf("name can only consist of lowercase letters and numbers, and must be between 3 and 24 characters long"))
|
||||||
// if err != nil {
|
}
|
||||||
// return fmt.Errorf("Error polling for AzureRM delete request for storage account %q: %s", name, err)
|
|
||||||
// }
|
return
|
||||||
//
|
}
|
||||||
// return nil
|
|
||||||
//}
|
func validateArmStorageAccountType(v interface{}, k string) (ws []string, es []error) {
|
||||||
//
|
validAccountTypes := []string{"standard_lrs", "standard_zrs",
|
||||||
//func validateArmStorageAccountName(v interface{}, k string) (ws []string, es []error) {
|
"standard_grs", "standard_ragrs", "premium_lrs"}
|
||||||
// input := v.(string)
|
|
||||||
//
|
input := strings.ToLower(v.(string))
|
||||||
// if !regexp.MustCompile(`\A([a-z0-9]{3,24})\z`).MatchString(input) {
|
|
||||||
// es = append(es, fmt.Errorf("name can only consist of lowercase letters and numbers, and must be between 3 and 24 characters long"))
|
for _, valid := range validAccountTypes {
|
||||||
// }
|
if valid == input {
|
||||||
//
|
return
|
||||||
// return
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func validateArmStorageAccountType(v interface{}, k string) (ws []string, es []error) {
|
es = append(es, fmt.Errorf("Invalid storage account type %q", input))
|
||||||
// validAccountTypes := []string{"standard_lrs", "standard_zrs",
|
return
|
||||||
// "standard_grs", "standard_ragrs", "premium_lrs"}
|
}
|
||||||
//
|
|
||||||
// input := strings.ToLower(v.(string))
|
|
||||||
//
|
|
||||||
// for _, valid := range validAccountTypes {
|
|
||||||
// if valid == input {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// es = append(es, fmt.Errorf("Invalid storage account type %q", input))
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
|
|
|
@ -1,166 +1,166 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "net/http"
|
"net/http"
|
||||||
// "testing"
|
"testing"
|
||||||
//
|
|
||||||
// "github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
// "github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
//)
|
)
|
||||||
//
|
|
||||||
//func TestValidateArmStorageAccountType(t *testing.T) {
|
func TestValidateArmStorageAccountType(t *testing.T) {
|
||||||
// testCases := []struct {
|
testCases := []struct {
|
||||||
// input string
|
input string
|
||||||
// shouldError bool
|
shouldError bool
|
||||||
// }{
|
}{
|
||||||
// {"standard_lrs", false},
|
{"standard_lrs", false},
|
||||||
// {"invalid", true},
|
{"invalid", true},
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
// _, es := validateArmStorageAccountType(test.input, "account_type")
|
_, es := validateArmStorageAccountType(test.input, "account_type")
|
||||||
//
|
|
||||||
// if test.shouldError && len(es) == 0 {
|
if test.shouldError && len(es) == 0 {
|
||||||
// t.Fatalf("Expected validating account_type %q to fail", test.input)
|
t.Fatalf("Expected validating account_type %q to fail", test.input)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func TestValidateArmStorageAccountName(t *testing.T) {
|
func TestValidateArmStorageAccountName(t *testing.T) {
|
||||||
// testCases := []struct {
|
testCases := []struct {
|
||||||
// input string
|
input string
|
||||||
// shouldError bool
|
shouldError bool
|
||||||
// }{
|
}{
|
||||||
// {"ab", true},
|
{"ab", true},
|
||||||
// {"ABC", true},
|
{"ABC", true},
|
||||||
// {"abc", false},
|
{"abc", false},
|
||||||
// {"123456789012345678901234", false},
|
{"123456789012345678901234", false},
|
||||||
// {"1234567890123456789012345", true},
|
{"1234567890123456789012345", true},
|
||||||
// {"abc12345", false},
|
{"abc12345", false},
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
// _, es := validateArmStorageAccountName(test.input, "name")
|
_, es := validateArmStorageAccountName(test.input, "name")
|
||||||
//
|
|
||||||
// if test.shouldError && len(es) == 0 {
|
if test.shouldError && len(es) == 0 {
|
||||||
// t.Fatalf("Expected validating name %q to fail", test.input)
|
t.Fatalf("Expected validating name %q to fail", test.input)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func TestAccAzureRMStorageAccount_basic(t *testing.T) {
|
func TestAccAzureRMStorageAccount_basic(t *testing.T) {
|
||||||
// resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
// PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
// Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
// CheckDestroy: testCheckAzureRMStorageAccountDestroy,
|
CheckDestroy: testCheckAzureRMStorageAccountDestroy,
|
||||||
// Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// resource.TestStep{
|
resource.TestStep{
|
||||||
// Config: testAccAzureRMStorageAccount_basic,
|
Config: testAccAzureRMStorageAccount_basic,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"),
|
testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"),
|
||||||
// resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_type", "Standard_LRS"),
|
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_type", "Standard_LRS"),
|
||||||
// resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.#", "1"),
|
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.#", "1"),
|
||||||
// resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.environment", "production"),
|
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.environment", "production"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// resource.TestStep{
|
resource.TestStep{
|
||||||
// Config: testAccAzureRMStorageAccount_update,
|
Config: testAccAzureRMStorageAccount_update,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"),
|
testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"),
|
||||||
// resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_type", "Standard_GRS"),
|
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_type", "Standard_GRS"),
|
||||||
// resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.#", "1"),
|
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.#", "1"),
|
||||||
// resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.environment", "staging"),
|
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.environment", "staging"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func testCheckAzureRMStorageAccountExists(name string) resource.TestCheckFunc {
|
func testCheckAzureRMStorageAccountExists(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)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// storageAccount := rs.Primary.Attributes["name"]
|
storageAccount := rs.Primary.Attributes["name"]
|
||||||
// resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
//
|
|
||||||
// // Ensure resource group exists in API
|
// Ensure resource group exists in API
|
||||||
// conn := testAccProvider.Meta().(*ArmClient).storageServiceClient
|
conn := testAccProvider.Meta().(*ArmClient).storageServiceClient
|
||||||
//
|
|
||||||
// resp, err := conn.GetProperties(resourceGroup, storageAccount)
|
resp, err := conn.GetProperties(resourceGroup, storageAccount)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return fmt.Errorf("Bad: Get on storageServiceClient: %s", err)
|
return fmt.Errorf("Bad: Get on storageServiceClient: %s", err)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
// return fmt.Errorf("Bad: StorageAccount %q (resource group: %q) does not exist", name, resourceGroup)
|
return fmt.Errorf("Bad: StorageAccount %q (resource group: %q) does not exist", name, resourceGroup)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func testCheckAzureRMStorageAccountDestroy(s *terraform.State) error {
|
func testCheckAzureRMStorageAccountDestroy(s *terraform.State) error {
|
||||||
// conn := testAccProvider.Meta().(*ArmClient).storageServiceClient
|
conn := testAccProvider.Meta().(*ArmClient).storageServiceClient
|
||||||
//
|
|
||||||
// for _, rs := range s.RootModule().Resources {
|
for _, rs := range s.RootModule().Resources {
|
||||||
// if rs.Type != "azurerm_storage_account" {
|
if rs.Type != "azurerm_storage_account" {
|
||||||
// continue
|
continue
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// name := rs.Primary.Attributes["name"]
|
name := rs.Primary.Attributes["name"]
|
||||||
// resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
//
|
|
||||||
// resp, err := conn.GetProperties(resourceGroup, name)
|
resp, err := conn.GetProperties(resourceGroup, name)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if resp.StatusCode != http.StatusNotFound {
|
if resp.StatusCode != http.StatusNotFound {
|
||||||
// return fmt.Errorf("Storage Account still exists:\n%#v", resp.Properties)
|
return fmt.Errorf("Storage Account still exists:\n%#v", resp.Properties)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return nil
|
return nil
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//var testAccAzureRMStorageAccount_basic = `
|
var testAccAzureRMStorageAccount_basic = `
|
||||||
//resource "azurerm_resource_group" "testrg" {
|
resource "azurerm_resource_group" "testrg" {
|
||||||
// name = "testAccAzureRMStorageAccountBasic"
|
name = "testAccAzureRMStorageAccountBasic"
|
||||||
// location = "westus"
|
location = "westus"
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//resource "azurerm_storage_account" "testsa" {
|
resource "azurerm_storage_account" "testsa" {
|
||||||
// name = "unlikely23exst2acct1435"
|
name = "unlikely23exst2acct1435"
|
||||||
// resource_group_name = "${azurerm_resource_group.testrg.name}"
|
resource_group_name = "${azurerm_resource_group.testrg.name}"
|
||||||
//
|
|
||||||
// location = "westus"
|
location = "westus"
|
||||||
// account_type = "Standard_LRS"
|
account_type = "Standard_LRS"
|
||||||
//
|
|
||||||
// tags {
|
tags {
|
||||||
// environment = "production"
|
environment = "production"
|
||||||
// }
|
}
|
||||||
//}`
|
}`
|
||||||
//
|
|
||||||
//var testAccAzureRMStorageAccount_update = `
|
var testAccAzureRMStorageAccount_update = `
|
||||||
//resource "azurerm_resource_group" "testrg" {
|
resource "azurerm_resource_group" "testrg" {
|
||||||
// name = "testAccAzureRMStorageAccountBasic"
|
name = "testAccAzureRMStorageAccountBasic"
|
||||||
// location = "westus"
|
location = "westus"
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//resource "azurerm_storage_account" "testsa" {
|
resource "azurerm_storage_account" "testsa" {
|
||||||
// name = "unlikely23exst2acct1435"
|
name = "unlikely23exst2acct1435"
|
||||||
// resource_group_name = "${azurerm_resource_group.testrg.name}"
|
resource_group_name = "${azurerm_resource_group.testrg.name}"
|
||||||
//
|
|
||||||
// location = "westus"
|
location = "westus"
|
||||||
// account_type = "Standard_GRS"
|
account_type = "Standard_GRS"
|
||||||
//
|
|
||||||
// tags {
|
tags {
|
||||||
// environment = "staging"
|
environment = "staging"
|
||||||
// }
|
}
|
||||||
//}`
|
}`
|
||||||
|
|
Loading…
Reference in New Issue