provider/azurerm: fix virtual_machine reading plan as the wrong type (#10626)

TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMVirtualMachine_plan -timeout 120m
=== RUN   TestAccAzureRMVirtualMachine_plan
--- PASS: TestAccAzureRMVirtualMachine_plan (798.75s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/azurerm	798.835s
This commit is contained in:
Peter McAtominey 2016-12-09 09:41:45 +00:00 committed by Paul Stack
parent 6f2f92fc35
commit 6f21b78710
2 changed files with 117 additions and 3 deletions

View File

@ -582,7 +582,7 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err
d.Set("location", resp.Location) d.Set("location", resp.Location)
if resp.Plan != nil { if resp.Plan != nil {
if err := d.Set("plan", flattenAzureRmVirtualMachinePlan(resp.Plan)); err != nil { if err := d.Set("plan", schema.NewSet(resourceArmVirtualMachinePlanHash, flattenAzureRmVirtualMachinePlan(resp.Plan))); err != nil {
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Plan error: %#v", err) return fmt.Errorf("[DEBUG] Error setting Virtual Machine Plan error: %#v", err)
} }
} }
@ -788,13 +788,13 @@ func resourceArmVirtualMachineStorageOsProfileWindowsConfigHash(v interface{}) i
return hashcode.String(buf.String()) return hashcode.String(buf.String())
} }
func flattenAzureRmVirtualMachinePlan(plan *compute.Plan) map[string]interface{} { func flattenAzureRmVirtualMachinePlan(plan *compute.Plan) []interface{} {
result := make(map[string]interface{}) result := make(map[string]interface{})
result["name"] = *plan.Name result["name"] = *plan.Name
result["publisher"] = *plan.Publisher result["publisher"] = *plan.Publisher
result["product"] = *plan.Product result["product"] = *plan.Product
return result return []interface{}{result}
} }
func flattenAzureRmVirtualMachineImageReference(image *compute.ImageReference) []interface{} { func flattenAzureRmVirtualMachineImageReference(image *compute.ImageReference) []interface{} {

View File

@ -392,6 +392,25 @@ func TestAccAzureRMVirtualMachine_changeOSDiskVhdUri(t *testing.T) {
}) })
} }
func TestAccAzureRMVirtualMachine_plan(t *testing.T) {
var vm compute.VirtualMachine
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMVirtualMachine_plan, ri, ri, ri, ri, ri, ri, ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
),
},
},
})
}
func testCheckAzureRMVirtualMachineExists(name string, vm *compute.VirtualMachine) resource.TestCheckFunc { func testCheckAzureRMVirtualMachineExists(name string, vm *compute.VirtualMachine) 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
@ -2159,3 +2178,98 @@ resource "azurerm_virtual_machine" "test" {
} }
} }
` `
var testAccAzureRMVirtualMachine_plan = `
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_network_interface" "test" {
name = "acctni-%d"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "dynamic"
}
}
resource "azurerm_storage_account" "test" {
name = "accsa%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "westus"
account_type = "Standard_LRS"
tags {
environment = "staging"
}
}
resource "azurerm_storage_container" "test" {
name = "vhds"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
resource "azurerm_virtual_machine" "test" {
name = "acctvm-%d"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
network_interface_ids = ["${azurerm_network_interface.test.id}"]
vm_size = "Standard_DS1_v2"
storage_image_reference {
publisher = "kemptech"
offer = "vlm-azure"
sku = "freeloadmaster"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
caching = "ReadWrite"
create_option = "FromImage"
disk_size_gb = "45"
}
os_profile {
computer_name = "hostname%d"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
plan {
name = "freeloadmaster"
publisher = "kemptech"
product = "vlm-azure"
}
tags {
environment = "Production"
cost-center = "Ops"
}
}
`