Minor fixups, refactors and test updates.

This commit is contained in:
aznashwan 2015-06-11 21:26:49 +03:00
parent 9670e69613
commit 137cb9778e
9 changed files with 75 additions and 63 deletions

Binary file not shown.

View File

@ -18,6 +18,7 @@ const testAccSecurityGroupName = "terraform-security-group"
// It is much more convenient to provide a Storage Service which
// has been created beforehand as the creation of one takes a lot
// and would greatly impede the multitude of tests which rely on one.
// NOTE: the storage container should be located in `West US`.
var testAccStorageServiceName = os.Getenv("AZURE_STORAGE")
const testAccStorageContainerName = "terraform-testing-container"

View File

@ -182,7 +182,7 @@ resource "azure_instance" "foo" {
resource "azure_data_disk" "foo" {
lun = 0
size = 10
storage_service_name = "${azure_instance.foo.storage}"
storage_service_name = "${azure_instance.foo.storage_service_name}"
virtual_machine = "${azure_instance.foo.id}"
}`, testAccStorageServiceName)
@ -201,7 +201,7 @@ resource "azure_data_disk" "foo" {
lun = 1
size = 10
caching = "ReadOnly"
storage_service_name = "${azure_instance.foo.storage}"
storage_service_name = "${azure_instance.foo.storage_service_name}"
virtual_machine = "${azure_instance.foo.id}"
}`, testAccStorageServiceName)
@ -220,7 +220,7 @@ resource "azure_instance" "bar" {
name = "terraform-test2"
image = "Ubuntu Server 14.04 LTS"
size = "Basic_A1"
storage_service_name = "${azure_instance.foo.storage}"
storage_service_name = "${azure_instance.foo.storage_service_name}"
location = "West US"
username = "terraform"
password = "Pass!admin123"
@ -230,6 +230,6 @@ resource "azure_data_disk" "foo" {
lun = 2
size = 20
caching = "ReadWrite"
storage_service_name = "${azure_instance.bar.storage}"
storage_service_name = "${azure_instance.bar.storage_service_name}"
virtual_machine = "${azure_instance.bar.id}"
}`, testAccStorageServiceName)

View File

@ -2,7 +2,6 @@ package azure
import (
"fmt"
"os"
"testing"
"github.com/Azure/azure-sdk-for-go/management"
@ -356,6 +355,8 @@ resource "azure_security_group_rule" "foo" {
source_port_range = "*"
destination_address_prefix = "*"
destination_port_range = "3389"
action = "Deny"
type = "Inbound"
protocol = "TCP"
}
@ -410,6 +411,8 @@ resource "azure_security_group_rule" "foo" {
source_port_range = "*"
destination_address_prefix = "*"
destination_port_range = "3389"
type = "Inbound"
action = "Deny"
protocol = "TCP"
}
@ -426,6 +429,8 @@ resource "azure_security_group_rule" "bar" {
source_port_range = "*"
destination_address_prefix = "*"
destination_port_range = "3389"
type = "Inbound"
action = "Deny"
protocol = "TCP"
}

View File

@ -32,7 +32,6 @@ func resourceAzureSecurityGroupRule() *schema.Resource {
ForceNew: true,
Description: parameterDescriptions["netsecgroup_secgroup_name"],
},
// TODO(aznashwan): update Sander's docs to remove default.
"type": &schema.Schema{
Type: schema.TypeString,
Required: true,
@ -43,7 +42,6 @@ func resourceAzureSecurityGroupRule() *schema.Resource {
Required: true,
Description: parameterDescriptions["netsecgroup_priority"],
},
// TODO(aznashwan): update Sander's docs to remove default.
"action": &schema.Schema{
Type: schema.TypeString,
Required: true,
@ -69,7 +67,6 @@ func resourceAzureSecurityGroupRule() *schema.Resource {
Required: true,
Description: parameterDescriptions["netsecgroup_dest_port_range"],
},
// TODO(aznashwan): update Sander's docs to remove default.
"protocol": &schema.Schema{
Type: schema.TypeString,
Required: true,

View File

@ -25,12 +25,9 @@ func resourceAzureStorageBlob() *schema.Resource {
Description: parameterDescriptions["name"],
},
"type": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
DefaultFunc: func() (interface{}, error) {
return "BlockBlob", nil
},
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: parameterDescriptions["type"],
},
"size": &schema.Schema{

View File

@ -3,7 +3,6 @@ package azure
import (
"fmt"
"testing"
"time"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
@ -15,23 +14,21 @@ func TestAccAzureStorageBlockBlob(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAzureStorageBlobDeleted,
CheckDestroy: testAccCheckAzureStorageBlobDeleted("block"),
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAzureStorageBlockBlobConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAzureStorageBlobExists(name),
testAccCheckAzureStorageBlobExists(name, "block"),
resource.TestCheckResourceAttr(name, "name", "tftesting-blob"),
resource.TestCheckResourceAttr(name, "type", "BlockBlob"),
resource.TestCheckResourceAttr(name, "storage_container_name", testAccStorageContainerName),
resource.TestCheckResourceAttr(name, "storage_container_name",
fmt.Sprintf("%s-block", testAccStorageContainerName)),
resource.TestCheckResourceAttr(name, "storage_service_name", testAccStorageServiceName),
),
},
},
})
// because containers take a while to get deleted, sleep for a while:
time.Sleep(5 * time.Minute)
}
func TestAccAzureStoragePageBlob(t *testing.T) {
@ -40,27 +37,25 @@ func TestAccAzureStoragePageBlob(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAzureStorageBlobDeleted,
CheckDestroy: testAccCheckAzureStorageBlobDeleted("page"),
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAzureStoragePageBlobConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAzureStorageBlobExists(name),
testAccCheckAzureStorageBlobExists(name, "page"),
resource.TestCheckResourceAttr(name, "name", "tftesting-blob"),
resource.TestCheckResourceAttr(name, "type", "PageBlob"),
resource.TestCheckResourceAttr(name, "size", "512"),
resource.TestCheckResourceAttr(name, "storage_container_name", testAccStorageContainerName),
resource.TestCheckResourceAttr(name, "storage_container_name",
fmt.Sprintf("%s-page", testAccStorageContainerName)),
resource.TestCheckResourceAttr(name, "storage_service_name", testAccStorageServiceName),
),
},
},
})
// because containers take a while to get deleted, sleep for a while:
time.Sleep(5 * time.Minute)
}
func testAccCheckAzureStorageBlobExists(name string) resource.TestCheckFunc {
func testAccCheckAzureStorageBlobExists(name, typ string) resource.TestCheckFunc {
return func(s *terraform.State) error {
resource, ok := s.RootModule().Resources[name]
if !ok {
@ -77,7 +72,8 @@ func testAccCheckAzureStorageBlobExists(name string) resource.TestCheckFunc {
return err
}
exists, err := blobClient.BlobExists(testAccStorageContainerName, resource.Primary.ID)
exists, err := blobClient.BlobExists(fmt.Sprintf("%s-%s", testAccStorageContainerName, typ),
resource.Primary.ID)
if err != nil {
return err
}
@ -89,51 +85,69 @@ func testAccCheckAzureStorageBlobExists(name string) resource.TestCheckFunc {
}
}
func testAccCheckAzureStorageBlobDeleted(s *terraform.State) error {
for _, resource := range s.RootModule().Resources {
if resource.Type != "azure_storage_blob" {
continue
func testAccCheckAzureStorageBlobDeleted(typ string) resource.TestCheckFunc {
return func(s *terraform.State) error {
for _, resource := range s.RootModule().Resources {
if resource.Type != "azure_storage_blob" {
continue
}
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient
blobClient, err := getStorageServiceBlobClient(mgmtClient, testAccStorageServiceName)
if err != nil {
return err
}
exists, err := blobClient.BlobExists(fmt.Sprintf("%s-%s", testAccStorageContainerName,
typ), resource.Primary.ID)
if err != nil {
return err
}
if exists {
return fmt.Errorf("Azure Storage Blob still exists.")
}
}
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient
blobClient, err := getStorageServiceBlobClient(mgmtClient, testAccStorageServiceName)
if err != nil {
return err
}
exists, err := blobClient.BlobExists(testAccStorageContainerName, resource.Primary.ID)
if err != nil {
return err
}
if exists {
return fmt.Errorf("Azure Storage Blob still exists.")
}
return nil
}
return nil
}
var testAccAzureStorageBlockBlobConfig = testAccAzureStorageContainerConfig + fmt.Sprintf(`
var testAccAzureStorageBlockBlobConfig = fmt.Sprintf(`
resource "azure_storage_container" "foo" {
name = "%s-block"
container_access_type = "blob"
# NOTE: A pre-existing Storage Service is used here so as to avoid
# the huge wait for creation of one.
storage_service_name = "%s"
}
resource "azure_storage_blob" "foo" {
name = "tftesting-blob"
type = "BlockBlob"
# NOTE: A pre-existing Storage Service is used here so as to avoid
# the huge wait for creation of one.
storage_service_name = "%s"
storage_container_name = "%s"
storage_service_name = "${azure_storage_container.foo.storage_service_name}"
storage_container_name = "${azure_storage_container.foo.name}"
}
`, testAccStorageContainerName, testAccStorageServiceName)
var testAccAzureStoragePageBlobConfig = fmt.Sprintf(`
resource "azure_storage_container" "foo" {
name = "%s-page"
container_access_type = "blob"
# NOTE: A pre-existing Storage Service is used here so as to avoid
# the huge wait for creation of one.
storage_service_name = "%s"
}
`, testAccStorageServiceName, testAccStorageContainerName)
var testAccAzureStoragePageBlobConfig = testAccAzureStorageContainerConfig + fmt.Sprintf(`
resource "azure_storage_blob" "foo" {
name = "tftesting-blob"
type = "PageBlob"
# NOTE: A pre-existing Storage Service is used here so as to avoid
# the huge wait for creation of one.
storage_service_name = "%s"
storage_container_name = "%s"
storage_service_name = "${azure_storage_container.foo.storage_service_name}"
storage_container_name = "${azure_storage_container.foo.name}"
# NOTE: must be a multiple of 512:
size = 512
}
`, testAccStorageServiceName, testAccStorageContainerName)
`, testAccStorageContainerName, testAccStorageServiceName)

View File

@ -25,12 +25,9 @@ func resourceAzureStorageContainer() *schema.Resource {
Description: parameterDescriptions["name"],
},
"storage_service_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
DefaultFunc: func() (interface{}, error) {
return "", nil
},
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: parameterDescriptions["storage_service_name"],
},
"container_access_type": &schema.Schema{

View File

@ -3,6 +3,7 @@ package azure
import (
"fmt"
"testing"
"time"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"