Skip to content

Commit

Permalink
provider/azurerm: arm_virtual_machine diagnostics_profile was causing a
Browse files Browse the repository at this point in the history
panic on the Read func

Fixes #8995

The Diagnostics profile was a badly laid out resource. All we needed to
set was whether it was enabled and the storage account to save the logs
to. The old schema parameter was deprecated and replaced with a much
simplier structure

```
% make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMVirtualMachine_diagnosticsProfile'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/09/29 12:21:04 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/azurerm -v
-run=TestAccAzureRMVirtualMachine_diagnosticsProfile -timeout 120m
=== RUN   TestAccAzureRMVirtualMachine_diagnosticsProfile
--- PASS: TestAccAzureRMVirtualMachine_diagnosticsProfile (1066.76s)
PASS
ok
github.com/hashicorp/terraform/builtin/providers/azurerm1066.776s
```
  • Loading branch information
stack72 committed Sep 29, 2016
1 parent 88c3554 commit 3ad1256
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 21 deletions.
76 changes: 55 additions & 21 deletions builtin/providers/azurerm/resource_arm_virtual_machine.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -214,13 +215,15 @@ func resourceArmVirtualMachine() *schema.Resource {
},

"diagnostics_profile": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ConflictsWith: []string{"boot_diagnostics"},
Deprecated: "Use field boot_diagnostics instead",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"boot_diagnostics": {
Type: schema.TypeSet,
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Expand All @@ -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,
Expand Down Expand Up @@ -455,7 +477,9 @@ func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) e

if _, ok := d.GetOk("diagnostics_profile"); ok {
diagnosticsProfile := expandAzureRmVirtualMachineDiagnosticsProfile(d)
properties.DiagnosticsProfile = &diagnosticsProfile
if diagnosticsProfile != nil {
properties.DiagnosticsProfile = diagnosticsProfile
}
}

osProfile, err := expandAzureRmVirtualMachineOsProfile(d)
Expand Down Expand Up @@ -751,14 +775,20 @@ func flattenAzureRmVirtualMachineImageReference(image *compute.ImageReference) [
return []interface{}{result}
}

func flattenAzureRmVirtualMachineDiagnosticsProfile(profile *compute.DiagnosticsProfile) map[string]interface{} {
func flattenAzureRmVirtualMachineDiagnosticsProfile(profile *compute.DiagnosticsProfile) []interface{} {
result := make(map[string]interface{})
bootDiagnostics := make(map[string]interface{})
bootDiagnostics["enabled"] = *profile.BootDiagnostics.Enabled
bootDiagnostics["storage_uri"] = *profile.BootDiagnostics.StorageURI

bootDiagnostics := make([]map[string]interface{}, 0)

diagnostic := make(map[string]interface{})
diagnostic["enabled"] = *profile.BootDiagnostics.Enabled
diagnostic["storage_uri"] = *profile.BootDiagnostics.StorageURI

bootDiagnostics = append(bootDiagnostics, diagnostic)

result["boot_diagnostics"] = bootDiagnostics

return result
return []interface{}{result}
}

func flattenAzureRmVirtualMachineNetworkInterfaces(profile *compute.NetworkProfile) []string {
Expand Down Expand Up @@ -1140,20 +1170,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)

return compute.DiagnosticsProfile{
BootDiagnostics: &compute.BootDiagnostics{
Enabled: &enabled,
StorageURI: &storageURI,
},
func expandAzureRmVirtualMachineDiagnosticsProfile(d *schema.ResourceData) *compute.DiagnosticsProfile {
bootDiagnostics := d.Get("boot_diagnostics").([]interface{})

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) {
Expand Down
Expand Up @@ -1254,6 +1254,13 @@ resource "azurerm_virtual_machine" "test" {
admin_password = "Password1234!"
}
diagnostics_profile {
boot_diagnostics {
enabled = true
storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}"
}
}
os_profile_windows_config {
winrm {
protocol = "http"
Expand Down

0 comments on commit 3ad1256

Please sign in to comment.