Merge pull request #9122 from hashicorp/b-arm-vm-diagnostics
provider/azurerm: arm_virtual_machine diagnostics_profile was causing a panic on the Read func
This commit is contained in:
commit
89138fe22b
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/Azure/azure-sdk-for-go/arm/compute"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
riviera "github.com/jen20/riviera/azure"
|
||||
)
|
||||
|
||||
func resourceArmVirtualMachine() *schema.Resource {
|
||||
|
@ -214,9 +215,11 @@ func resourceArmVirtualMachine() *schema.Resource {
|
|||
},
|
||||
|
||||
"diagnostics_profile": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
MaxItems: 1,
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
MaxItems: 1,
|
||||
ConflictsWith: []string{"boot_diagnostics"},
|
||||
Deprecated: "Use field boot_diagnostics instead",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"boot_diagnostics": {
|
||||
|
@ -241,6 +244,25 @@ func resourceArmVirtualMachine() *schema.Resource {
|
|||
},
|
||||
},
|
||||
|
||||
"boot_diagnostics": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"storage_uri": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
"os_profile": {
|
||||
Type: schema.TypeSet,
|
||||
Required: true,
|
||||
|
@ -453,9 +475,11 @@ func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) e
|
|||
StorageProfile: &storageProfile,
|
||||
}
|
||||
|
||||
if _, ok := d.GetOk("diagnostics_profile"); ok {
|
||||
if _, ok := d.GetOk("boot_diagnostics"); ok {
|
||||
diagnosticsProfile := expandAzureRmVirtualMachineDiagnosticsProfile(d)
|
||||
properties.DiagnosticsProfile = &diagnosticsProfile
|
||||
if diagnosticsProfile != nil {
|
||||
properties.DiagnosticsProfile = diagnosticsProfile
|
||||
}
|
||||
}
|
||||
|
||||
osProfile, err := expandAzureRmVirtualMachineOsProfile(d)
|
||||
|
@ -577,8 +601,8 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err
|
|||
}
|
||||
}
|
||||
|
||||
if resp.Properties.DiagnosticsProfile != nil {
|
||||
if err := d.Set("diagnostics_profile", flattenAzureRmVirtualMachineDiagnosticsProfile(resp.Properties.DiagnosticsProfile)); err != nil {
|
||||
if resp.Properties.DiagnosticsProfile != nil && resp.Properties.DiagnosticsProfile.BootDiagnostics != nil {
|
||||
if err := d.Set("boot_diagnostics", flattenAzureRmVirtualMachineDiagnosticsProfile(resp.Properties.DiagnosticsProfile.BootDiagnostics)); err != nil {
|
||||
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Diagnostics Profile: %#v", err)
|
||||
}
|
||||
}
|
||||
|
@ -751,14 +775,13 @@ func flattenAzureRmVirtualMachineImageReference(image *compute.ImageReference) [
|
|||
return []interface{}{result}
|
||||
}
|
||||
|
||||
func flattenAzureRmVirtualMachineDiagnosticsProfile(profile *compute.DiagnosticsProfile) map[string]interface{} {
|
||||
func flattenAzureRmVirtualMachineDiagnosticsProfile(profile *compute.BootDiagnostics) []interface{} {
|
||||
result := make(map[string]interface{})
|
||||
bootDiagnostics := make(map[string]interface{})
|
||||
bootDiagnostics["enabled"] = *profile.BootDiagnostics.Enabled
|
||||
bootDiagnostics["storage_uri"] = *profile.BootDiagnostics.StorageURI
|
||||
result["boot_diagnostics"] = bootDiagnostics
|
||||
|
||||
return result
|
||||
result["enabled"] = *profile.Enabled
|
||||
result["storage_uri"] = *profile.StorageURI
|
||||
|
||||
return []interface{}{result}
|
||||
}
|
||||
|
||||
func flattenAzureRmVirtualMachineNetworkInterfaces(profile *compute.NetworkProfile) []string {
|
||||
|
@ -1140,20 +1163,24 @@ func expandAzureRmVirtualMachineDataDisk(d *schema.ResourceData) ([]compute.Data
|
|||
return data_disks, nil
|
||||
}
|
||||
|
||||
func expandAzureRmVirtualMachineDiagnosticsProfile(d *schema.ResourceData) compute.DiagnosticsProfile {
|
||||
diagnosticsProfiles := d.Get("diagnostics_profile").(*schema.Set).List()
|
||||
diagnosticsProfile := diagnosticsProfiles[0].(map[string]interface{})
|
||||
bootDiagnosticses := diagnosticsProfile["boot_diagnostics"].(*schema.Set).List()
|
||||
bootDiagnostics := bootDiagnosticses[0].(map[string]interface{})
|
||||
enabled := bootDiagnostics["enabled"].(bool)
|
||||
storageURI := bootDiagnostics["storage_uri"].(string)
|
||||
func expandAzureRmVirtualMachineDiagnosticsProfile(d *schema.ResourceData) *compute.DiagnosticsProfile {
|
||||
bootDiagnostics := d.Get("boot_diagnostics").([]interface{})
|
||||
|
||||
return compute.DiagnosticsProfile{
|
||||
BootDiagnostics: &compute.BootDiagnostics{
|
||||
Enabled: &enabled,
|
||||
StorageURI: &storageURI,
|
||||
},
|
||||
diagnosticsProfile := &compute.DiagnosticsProfile{}
|
||||
if len(bootDiagnostics) > 0 {
|
||||
bootDiagnostic := bootDiagnostics[0].(map[string]interface{})
|
||||
|
||||
diagnostic := &compute.BootDiagnostics{
|
||||
Enabled: riviera.Bool(bootDiagnostic["enabled"].(bool)),
|
||||
StorageURI: riviera.String(bootDiagnostic["storage_uri"].(string)),
|
||||
}
|
||||
|
||||
diagnosticsProfile.BootDiagnostics = diagnostic
|
||||
|
||||
return diagnosticsProfile
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func expandAzureRmVirtualMachineImageReference(d *schema.ResourceData) (*compute.ImageReference, error) {
|
||||
|
|
|
@ -1300,6 +1300,11 @@ resource "azurerm_virtual_machine" "test" {
|
|||
admin_password = "Password1234!"
|
||||
}
|
||||
|
||||
boot_diagnostics {
|
||||
enabled = true
|
||||
storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}"
|
||||
}
|
||||
|
||||
os_profile_windows_config {
|
||||
winrm {
|
||||
protocol = "http"
|
||||
|
|
|
@ -207,7 +207,7 @@ The following arguments are supported:
|
|||
* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created.
|
||||
* `plan` - (Optional) A plan block as documented below.
|
||||
* `availability_set_id` - (Optional) The Id of the Availability Set in which to create the virtual machine
|
||||
* `diagnostics_profile` - (Optional) A Diagnostics Profile block as referenced below.
|
||||
* `boot_diagnostics` - (Optional) A boot diagnostics profile block as referenced below.
|
||||
* `vm_size` - (Required) Specifies the [size of the virtual machine](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-size-specs/).
|
||||
* `storage_image_reference` - (Optional) A Storage Image Reference block as documented below.
|
||||
* `storage_os_disk` - (Required) A Storage OS Disk block as referenced below.
|
||||
|
@ -229,10 +229,6 @@ For more information on the different example configurations, please check out t
|
|||
* `publisher` - (Optional) Specifies the publisher of the image.
|
||||
* `product` - (Optional) Specifies the product of the image from the marketplace.
|
||||
|
||||
`diagnostics_profile` supports the following:
|
||||
|
||||
* `boot_diagnostics`: (Required) A Boot Diagnostics block as documented below.
|
||||
|
||||
`boot_diagnostics` supports the following:
|
||||
|
||||
* `enabled`: (Required) Whether to enable boot diagnostics for the virtual machine.
|
||||
|
|
Loading…
Reference in New Issue