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 // It is much more convenient to provide a Storage Service which
// has been created beforehand as the creation of one takes a lot // has been created beforehand as the creation of one takes a lot
// and would greatly impede the multitude of tests which rely on one. // 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") var testAccStorageServiceName = os.Getenv("AZURE_STORAGE")
const testAccStorageContainerName = "terraform-testing-container" const testAccStorageContainerName = "terraform-testing-container"

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,6 @@ package azure
import ( import (
"fmt" "fmt"
"testing" "testing"
"time"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -15,23 +14,21 @@ func TestAccAzureStorageBlockBlob(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: testAccCheckAzureStorageBlobDeleted, CheckDestroy: testAccCheckAzureStorageBlobDeleted("block"),
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAzureStorageBlockBlobConfig, Config: testAccAzureStorageBlockBlobConfig,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAzureStorageBlobExists(name), testAccCheckAzureStorageBlobExists(name, "block"),
resource.TestCheckResourceAttr(name, "name", "tftesting-blob"), resource.TestCheckResourceAttr(name, "name", "tftesting-blob"),
resource.TestCheckResourceAttr(name, "type", "BlockBlob"), 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), 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) { func TestAccAzureStoragePageBlob(t *testing.T) {
@ -40,27 +37,25 @@ func TestAccAzureStoragePageBlob(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: testAccCheckAzureStorageBlobDeleted, CheckDestroy: testAccCheckAzureStorageBlobDeleted("page"),
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAzureStoragePageBlobConfig, Config: testAccAzureStoragePageBlobConfig,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAzureStorageBlobExists(name), testAccCheckAzureStorageBlobExists(name, "page"),
resource.TestCheckResourceAttr(name, "name", "tftesting-blob"), resource.TestCheckResourceAttr(name, "name", "tftesting-blob"),
resource.TestCheckResourceAttr(name, "type", "PageBlob"), resource.TestCheckResourceAttr(name, "type", "PageBlob"),
resource.TestCheckResourceAttr(name, "size", "512"), 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), 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 { return func(s *terraform.State) error {
resource, ok := s.RootModule().Resources[name] resource, ok := s.RootModule().Resources[name]
if !ok { if !ok {
@ -77,7 +72,8 @@ func testAccCheckAzureStorageBlobExists(name string) resource.TestCheckFunc {
return err 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 { if err != nil {
return err return err
} }
@ -89,7 +85,8 @@ func testAccCheckAzureStorageBlobExists(name string) resource.TestCheckFunc {
} }
} }
func testAccCheckAzureStorageBlobDeleted(s *terraform.State) error { func testAccCheckAzureStorageBlobDeleted(typ string) resource.TestCheckFunc {
return func(s *terraform.State) error {
for _, resource := range s.RootModule().Resources { for _, resource := range s.RootModule().Resources {
if resource.Type != "azure_storage_blob" { if resource.Type != "azure_storage_blob" {
continue continue
@ -101,7 +98,8 @@ func testAccCheckAzureStorageBlobDeleted(s *terraform.State) error {
return err 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 { if err != nil {
return err return err
} }
@ -111,29 +109,45 @@ func testAccCheckAzureStorageBlobDeleted(s *terraform.State) error {
} }
return nil return nil
}
}
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"
} }
var testAccAzureStorageBlockBlobConfig = testAccAzureStorageContainerConfig + fmt.Sprintf(`
resource "azure_storage_blob" "foo" { resource "azure_storage_blob" "foo" {
name = "tftesting-blob" name = "tftesting-blob"
type = "BlockBlob" type = "BlockBlob"
# NOTE: A pre-existing Storage Service is used here so as to avoid # NOTE: A pre-existing Storage Service is used here so as to avoid
# the huge wait for creation of one. # the huge wait for creation of one.
storage_service_name = "%s" storage_service_name = "${azure_storage_container.foo.storage_service_name}"
storage_container_name = "%s" 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" { resource "azure_storage_blob" "foo" {
name = "tftesting-blob" name = "tftesting-blob"
type = "PageBlob" type = "PageBlob"
# NOTE: A pre-existing Storage Service is used here so as to avoid # NOTE: A pre-existing Storage Service is used here so as to avoid
# the huge wait for creation of one. # the huge wait for creation of one.
storage_service_name = "%s" storage_service_name = "${azure_storage_container.foo.storage_service_name}"
storage_container_name = "%s" storage_container_name = "${azure_storage_container.foo.name}"
# NOTE: must be a multiple of 512: # NOTE: must be a multiple of 512:
size = 512 size = 512
} }
`, testAccStorageServiceName, testAccStorageContainerName) `, testAccStorageContainerName, testAccStorageServiceName)

View File

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

View File

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