Skip to content

Commit 971b08f

Browse files
committed
Merge conflict resolution of virtual_machine.html.markdown in AzureRM
2 parents ef9aa6b + 08f2e67 commit 971b08f

3 files changed

Lines changed: 187 additions & 0 deletions

File tree

builtin/providers/azurerm/resource_arm_virtual_machine.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,34 @@ func resourceArmVirtualMachine() *schema.Resource {
213213
Default: false,
214214
},
215215

216+
"diagnostics_profile": {
217+
Type: schema.TypeSet,
218+
Optional: true,
219+
MaxItems: 1,
220+
Elem: &schema.Resource{
221+
Schema: map[string]*schema.Schema{
222+
"boot_diagnostics": {
223+
Type: schema.TypeSet,
224+
Required: true,
225+
MaxItems: 1,
226+
Elem: &schema.Resource{
227+
Schema: map[string]*schema.Schema{
228+
"enabled": {
229+
Type: schema.TypeBool,
230+
Required: true,
231+
},
232+
233+
"storage_uri": {
234+
Type: schema.TypeString,
235+
Required: true,
236+
},
237+
},
238+
},
239+
},
240+
},
241+
},
242+
},
243+
216244
"os_profile": {
217245
Type: schema.TypeSet,
218246
Required: true,
@@ -425,6 +453,11 @@ func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) e
425453
StorageProfile: &storageProfile,
426454
}
427455

456+
if _, ok := d.GetOk("diagnostics_profile"); ok {
457+
diagnosticsProfile := expandAzureRmVirtualMachineDiagnosticsProfile(d)
458+
properties.DiagnosticsProfile = &diagnosticsProfile
459+
}
460+
428461
osProfile, err := expandAzureRmVirtualMachineOsProfile(d)
429462
if err != nil {
430463
return err
@@ -544,6 +577,12 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err
544577
}
545578
}
546579

580+
if resp.Properties.DiagnosticsProfile != nil {
581+
if err := d.Set("diagnostics_profile", flattenAzureRmVirtualMachineDiagnosticsProfile(resp.Properties.DiagnosticsProfile)); err != nil {
582+
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Diagnostics Profile: %#v", err)
583+
}
584+
}
585+
547586
if resp.Properties.NetworkProfile != nil {
548587
if err := d.Set("network_interface_ids", flattenAzureRmVirtualMachineNetworkInterfaces(resp.Properties.NetworkProfile)); err != nil {
549588
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Storage Network Interfaces: %#v", err)
@@ -712,6 +751,16 @@ func flattenAzureRmVirtualMachineImageReference(image *compute.ImageReference) [
712751
return []interface{}{result}
713752
}
714753

754+
func flattenAzureRmVirtualMachineDiagnosticsProfile(profile *compute.DiagnosticsProfile) map[string]interface{} {
755+
result := make(map[string]interface{})
756+
bootDiagnostics := make(map[string]interface{})
757+
bootDiagnostics["enabled"] = *profile.BootDiagnostics.Enabled
758+
bootDiagnostics["storage_uri"] = *profile.BootDiagnostics.StorageURI
759+
result["boot_diagnostics"] = bootDiagnostics
760+
761+
return result
762+
}
763+
715764
func flattenAzureRmVirtualMachineNetworkInterfaces(profile *compute.NetworkProfile) []string {
716765
result := make([]string, 0, len(*profile.NetworkInterfaces))
717766
for _, nic := range *profile.NetworkInterfaces {
@@ -1091,6 +1140,22 @@ func expandAzureRmVirtualMachineDataDisk(d *schema.ResourceData) ([]compute.Data
10911140
return data_disks, nil
10921141
}
10931142

1143+
func expandAzureRmVirtualMachineDiagnosticsProfile(d *schema.ResourceData) compute.DiagnosticsProfile {
1144+
diagnosticsProfiles := d.Get("diagnostics_profile").(*schema.Set).List()
1145+
diagnosticsProfile := diagnosticsProfiles[0].(map[string]interface{})
1146+
bootDiagnosticses := diagnosticsProfile["boot_diagnostics"].(*schema.Set).List()
1147+
bootDiagnostics := bootDiagnosticses[0].(map[string]interface{})
1148+
enabled := bootDiagnostics["enabled"].(bool)
1149+
storageURI := bootDiagnostics["storage_uri"].(string)
1150+
1151+
return compute.DiagnosticsProfile{
1152+
BootDiagnostics: &compute.BootDiagnostics{
1153+
Enabled: &enabled,
1154+
StorageURI: &storageURI,
1155+
},
1156+
}
1157+
}
1158+
10941159
func expandAzureRmVirtualMachineImageReference(d *schema.ResourceData) (*compute.ImageReference, error) {
10951160
storageImageRefs := d.Get("storage_image_reference").(*schema.Set).List()
10961161

builtin/providers/azurerm/resource_arm_virtual_machine_test.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,25 @@ func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) {
159159
})
160160
}
161161

162+
func TestAccAzureRMVirtualMachine_diagnosticsProfile(t *testing.T) {
163+
var vm compute.VirtualMachine
164+
ri := acctest.RandInt()
165+
config := fmt.Sprintf(testAccAzureRMVirtualMachine_diagnosticsProfile, ri, ri, ri, ri, ri, ri)
166+
resource.Test(t, resource.TestCase{
167+
PreCheck: func() { testAccPreCheck(t) },
168+
Providers: testAccProviders,
169+
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
170+
Steps: []resource.TestStep{
171+
{
172+
Config: config,
173+
Check: resource.ComposeTestCheckFunc(
174+
testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
175+
),
176+
},
177+
},
178+
})
179+
}
180+
162181
func TestAccAzureRMVirtualMachine_winRMConfig(t *testing.T) {
163182
var vm compute.VirtualMachine
164183
ri := acctest.RandInt()
@@ -1154,7 +1173,100 @@ resource "azurerm_virtual_machine" "test" {
11541173
content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>"
11551174
}
11561175
}
1176+
1177+
diagnostics_profile {
1178+
boot_diagnostics {
1179+
enabled = true
1180+
storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}"
1181+
}
1182+
}
1183+
}
1184+
`
1185+
1186+
var testAccAzureRMVirtualMachine_diagnosticsProfile = `
1187+
resource "azurerm_resource_group" "test" {
1188+
name = "acctestrg-%d"
1189+
location = "West US"
1190+
}
1191+
1192+
resource "azurerm_virtual_network" "test" {
1193+
name = "acctvn-%d"
1194+
address_space = ["10.0.0.0/16"]
1195+
location = "West US"
1196+
resource_group_name = "${azurerm_resource_group.test.name}"
1197+
}
1198+
1199+
resource "azurerm_subnet" "test" {
1200+
name = "acctsub-%d"
1201+
resource_group_name = "${azurerm_resource_group.test.name}"
1202+
virtual_network_name = "${azurerm_virtual_network.test.name}"
1203+
address_prefix = "10.0.2.0/24"
1204+
}
1205+
1206+
resource "azurerm_network_interface" "test" {
1207+
name = "acctni-%d"
1208+
location = "West US"
1209+
resource_group_name = "${azurerm_resource_group.test.name}"
1210+
1211+
ip_configuration {
1212+
name = "testconfiguration1"
1213+
subnet_id = "${azurerm_subnet.test.id}"
1214+
private_ip_address_allocation = "dynamic"
1215+
}
1216+
}
1217+
1218+
resource "azurerm_storage_account" "test" {
1219+
name = "accsa%d"
1220+
resource_group_name = "${azurerm_resource_group.test.name}"
1221+
location = "westus"
1222+
account_type = "Standard_LRS"
1223+
1224+
tags {
1225+
environment = "staging"
1226+
}
1227+
}
1228+
1229+
resource "azurerm_storage_container" "test" {
1230+
name = "vhds"
1231+
resource_group_name = "${azurerm_resource_group.test.name}"
1232+
storage_account_name = "${azurerm_storage_account.test.name}"
1233+
container_access_type = "private"
1234+
}
1235+
1236+
resource "azurerm_virtual_machine" "test" {
1237+
name = "acctvm-%d"
1238+
location = "West US"
1239+
resource_group_name = "${azurerm_resource_group.test.name}"
1240+
network_interface_ids = ["${azurerm_network_interface.test.id}"]
1241+
vm_size = "Standard_A0"
1242+
1243+
storage_image_reference {
1244+
publisher = "MicrosoftWindowsServer"
1245+
offer = "WindowsServer"
1246+
sku = "2012-Datacenter"
1247+
version = "latest"
1248+
}
1249+
1250+
storage_os_disk {
1251+
name = "myosdisk1"
1252+
vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
1253+
caching = "ReadWrite"
1254+
create_option = "FromImage"
1255+
}
1256+
1257+
os_profile {
1258+
computer_name = "winhost01"
1259+
admin_username = "testadmin"
1260+
admin_password = "Password1234!"
1261+
}
1262+
1263+
os_profile_windows_config {
1264+
winrm {
1265+
protocol = "http"
1266+
}
1267+
}
11571268
}
1269+
11581270
`
11591271

11601272
var testAccAzureRMVirtualMachine_winRMConfig = `

website/source/docs/providers/azurerm/r/virtual_machine.html.markdown

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ The following arguments are supported:
207207
* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created.
208208
* `plan` - (Optional) A plan block as documented below.
209209
* `availability_set_id` - (Optional) The Id of the Availability Set in which to create the virtual machine
210+
* `diagnostics_profile` - (Optional) A Diagnostics Profile block as referenced below.
210211
* `vm_size` - (Required) Specifies the [size of the virtual machine](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-size-specs/).
211212
* `storage_image_reference` - (Optional) A Storage Image Reference block as documented below.
212213
* `storage_os_disk` - (Required) A Storage OS Disk block as referenced below.
@@ -228,6 +229,15 @@ For more information on the different example configurations, please check out t
228229
* `publisher` - (Optional) Specifies the publisher of the image.
229230
* `product` - (Optional) Specifies the product of the image from the marketplace.
230231

232+
`diagnostics_profile` supports the following:
233+
234+
* `boot_diagnostics`: (Required) A Boot Diagnostics block as documented below.
235+
236+
`boot_diagnostics` supports the following:
237+
238+
* `enabled`: (Required) Whether to enable boot diagnostics for the virtual machine.
239+
* `storage_uri`: (Required) Blob endpoint for the storage account to hold the virtual machine's diagnostic files. This must be the root of a storage account, and not a storage container.
240+
231241
`storage_image_reference` supports the following:
232242

233243
* `publisher` - (Required) Specifies the publisher of the image used to create the virtual machine

0 commit comments

Comments
 (0)