From a6d8b45f53d8d33efcb1d5c19dca0360c45c7aa6 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Wed, 1 Mar 2017 15:48:07 -0800 Subject: [PATCH 001/107] mcardosos/azure-for-go-sdk/arm/compute@v8.1.0-beta --- .../azurerm/resource_arm_virtual_machine.go | 2 +- vendor/vendor.json | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index 3ba431a22..b78a58ec2 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -9,7 +9,7 @@ import ( "net/url" "strings" - "github.com/Azure/azure-sdk-for-go/arm/compute" + "github.com/mcardosos/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" riviera "github.com/jen20/riviera/azure" diff --git a/vendor/vendor.json b/vendor/vendor.json index 8de8042de..0b033f90c 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -23,7 +23,7 @@ "version": "v8.0.1-beta", "versionExact": "v8.0.1-beta" }, - { + /*{ "checksumSHA1": "+w9njWehvjvkFK4JHAEtTgvmVgE=", "comment": "v2.1.1-beta-8-gca4d906", "path": "github.com/Azure/azure-sdk-for-go/arm/compute", @@ -31,7 +31,7 @@ "revisionTime": "2017-02-08T01:01:20Z", "version": "v8.0.1-beta", "versionExact": "v8.0.1-beta" - }, + },*/ { "checksumSHA1": "JbbZWArn6iqSs+neT5X8AxxH6o0=", "comment": "v2.1.1-beta-8-gca4d906", @@ -2347,6 +2347,14 @@ "path": "github.com/maximilien/softlayer-go/softlayer", "revision": "85659debe44fab5792fc92cf755c04b115b9dc19" }, + { + "checksumSHA1": "MJ2PfEAmNJ0/H+uFcNYKWdiQIiM=", + "path": "github.com/mcardosos/azure-sdk-for-go/arm/compute", + "revision": "a7cd8005acf2eb9ffa8298450616e042370c22bc", + "revisionTime": "2017-02-28T01:51:47Z", + "version": "=v8.1.0-beta", + "versionExact": "v8.1.0-beta" + }, { "checksumSHA1": "GSum+utW01N3KeMdvAPnsW0TemM=", "path": "github.com/michaelklishin/rabbit-hole", From 9f6a7dccf92bedeb6088496a41b83fb5e1da4429 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Wed, 1 Mar 2017 15:49:56 -0800 Subject: [PATCH 002/107] compute managed disk support --- .../azurerm/resource_arm_virtual_machine.go | 108 +++++++++++++++--- 1 file changed, 94 insertions(+), 14 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index b78a58ec2..0b2d3c614 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -12,6 +12,7 @@ import ( "github.com/mcardosos/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" riviera "github.com/jen20/riviera/azure" ) @@ -142,10 +143,27 @@ func resourceArmVirtualMachine() *schema.Resource { "vhd_uri": { Type: schema.TypeString, - Required: true, + Optional: true, ForceNew: true, }, + "managed_disk": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "storage_account_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(compute.PremiumLRS), + string(compute.StandardLRS), + }, true), + }, + }, + }, + }, + "image_uri": { Type: schema.TypeString, Optional: true, @@ -190,7 +208,24 @@ func resourceArmVirtualMachine() *schema.Resource { "vhd_uri": { Type: schema.TypeString, - Required: true, + Optional: true, + }, + + "managed_disk": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "storage_account_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(compute.PremiumLRS), + string(compute.StandardLRS), + }, true), + }, + }, + }, }, "create_option": { @@ -770,8 +805,13 @@ func resourceArmVirtualMachineStorageOsDiskHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) buf.WriteString(fmt.Sprintf("%s-", m["name"].(string))) - buf.WriteString(fmt.Sprintf("%s-", m["vhd_uri"].(string))) - + if m["vhd_uri"] != nil { + buf.WriteString(fmt.Sprintf("%s-", m["vhd_uri"].(string))) + } + if m["managed_disk"] != nil { + managedDisk := m["managed_disk"].(map[string]interface{}) + buf.WriteString(fmt.Sprintf("%s-", managedDisk["storage_account_type"].(string))) + } return hashcode.String(buf.String()) } @@ -869,7 +909,12 @@ func flattenAzureRmVirtualMachineDataDisk(disks *[]compute.DataDisk) interface{} for i, disk := range *disks { l := make(map[string]interface{}) l["name"] = *disk.Name - l["vhd_uri"] = *disk.Vhd.URI + if disk.Vhd != nil { + l["vhd_uri"] = *disk.Vhd.URI + } + if disk.ManagedDisk != nil { + l["managed_disk"] = flattenAzureRmVirtualMachineManagedDisk(disk.ManagedDisk) + } l["create_option"] = disk.CreateOption l["caching"] = string(disk.Caching) if disk.DiskSizeGB != nil { @@ -975,7 +1020,12 @@ func flattenAzureRmVirtualMachineOsProfileLinuxConfiguration(config *compute.Lin func flattenAzureRmVirtualMachineOsDisk(disk *compute.OSDisk) []interface{} { result := make(map[string]interface{}) result["name"] = *disk.Name - result["vhd_uri"] = *disk.Vhd.URI + if disk.Vhd != nil { + result["vhd_uri"] = *disk.Vhd.URI + } + if disk.ManagedDisk != nil { + result["managed_disk"] = flattenAzureRmVirtualMachineManagedDisk(disk.ManagedDisk) + } result["create_option"] = disk.CreateOption result["caching"] = disk.Caching if disk.DiskSizeGB != nil { @@ -985,6 +1035,12 @@ func flattenAzureRmVirtualMachineOsDisk(disk *compute.OSDisk) []interface{} { return []interface{}{result} } +func flattenAzureRmVirtualMachineManagedDisk(params *compute.ManagedDiskParameters) map[string]interface{} { + managedDisk := make(map[string]interface{}) + managedDisk["storage_account_type"] = string(params.StorageAccountType) + return managedDisk +} + func expandAzureRmVirtualMachinePlan(d *schema.ResourceData) (*compute.Plan, error) { planConfigs := d.Get("plan").(*schema.Set).List() @@ -1208,17 +1264,26 @@ func expandAzureRmVirtualMachineDataDisk(d *schema.ResourceData) ([]compute.Data name := config["name"].(string) vhd := config["vhd_uri"].(string) + managedDisk := config["managed_disk"].(map[string]interface{}) createOption := config["create_option"].(string) lun := int32(config["lun"].(int)) data_disk := compute.DataDisk{ - Name: &name, - Vhd: &compute.VirtualHardDisk{ - URI: &vhd, - }, + Name: &name, Lun: &lun, CreateOption: compute.DiskCreateOptionTypes(createOption), } + if vhd != "" && managedDisk != nil { + return nil, fmt.Errorf("[ERROR] Conflict between `vhd_uri` and `managed_disk` (only one or the other can be used)") + } else if vhd != "" { + data_disk.Vhd = &compute.VirtualHardDisk{ + URI: &vhd, + } + } else if managedDisk != nil { + data_disk.ManagedDisk = expandAzureRmVirtualMachineManagedDisk(managedDisk) + } else { + return nil, fmt.Errorf("[ERROR] A value must be specified for either `vhd_uri` or `managed_disk`") + } if v := config["caching"].(string); v != "" { data_disk.Caching = compute.CachingTypes(v) @@ -1299,17 +1364,25 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk, name := disk["name"].(string) vhdURI := disk["vhd_uri"].(string) + managedDisk := disk["managed_disk"].(map[string]interface{}) imageURI := disk["image_uri"].(string) createOption := disk["create_option"].(string) osDisk := &compute.OSDisk{ - Name: &name, - Vhd: &compute.VirtualHardDisk{ - URI: &vhdURI, - }, + Name: &name, CreateOption: compute.DiskCreateOptionTypes(createOption), } + if vhdURI != "" { + osDisk.Vhd = &compute.VirtualHardDisk{ + URI: &vhdURI, + } + } else if managedDisk != nil { + osDisk.ManagedDisk = expandAzureRmVirtualMachineManagedDisk(managedDisk) + } else { + return nil, fmt.Errorf("[ERROR] must specify value for either vhd_uri or managed_disk") + } + if v := disk["image_uri"].(string); v != "" { osDisk.Image = &compute.VirtualHardDisk{ URI: &imageURI, @@ -1338,6 +1411,13 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk, return osDisk, nil } +func expandAzureRmVirtualMachineManagedDisk(managedDisk map[string]interface{}) *compute.ManagedDiskParameters { + managedDiskParameters := &compute.ManagedDiskParameters{ + StorageAccountType: compute.StorageAccountTypes(managedDisk["storage_account_type"].(string)), + } + return managedDiskParameters +} + func findStorageAccountResourceGroup(meta interface{}, storageAccountName string) (string, error) { client := meta.(*ArmClient).resourceFindClient filter := fmt.Sprintf("name eq '%s' and resourceType eq 'Microsoft.Storage/storageAccounts'", storageAccountName) From a3a2c38eeb232691e22bce3f1d819c82e74c5732 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Wed, 1 Mar 2017 15:50:34 -0800 Subject: [PATCH 003/107] make fmt --- builtin/providers/azurerm/resource_arm_virtual_machine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index 0b2d3c614..6136ceacb 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -9,11 +9,11 @@ import ( "net/url" "strings" - "github.com/mcardosos/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" riviera "github.com/jen20/riviera/azure" + "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) func resourceArmVirtualMachine() *schema.Resource { From d1bca91cee37a102243ebe5f52aa3f3e2d030e9c Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Wed, 1 Mar 2017 15:56:47 -0800 Subject: [PATCH 004/107] updated other arm/compute references to mcardosos --- builtin/providers/azurerm/config.go | 2 +- builtin/providers/azurerm/resource_arm_availability_set.go | 2 +- .../providers/azurerm/resource_arm_virtual_machine_extension.go | 2 +- .../providers/azurerm/resource_arm_virtual_machine_scale_set.go | 2 +- builtin/providers/azurerm/resource_arm_virtual_machine_test.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/providers/azurerm/config.go b/builtin/providers/azurerm/config.go index bbf15712f..fc89d4d70 100644 --- a/builtin/providers/azurerm/config.go +++ b/builtin/providers/azurerm/config.go @@ -8,7 +8,6 @@ import ( "net/http/httputil" "github.com/Azure/azure-sdk-for-go/arm/cdn" - "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/arm/containerregistry" "github.com/Azure/azure-sdk-for-go/arm/containerservice" "github.com/Azure/azure-sdk-for-go/arm/eventhub" @@ -25,6 +24,7 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/hashicorp/terraform/terraform" riviera "github.com/jen20/riviera/azure" + "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) // ArmClient contains the handles to all the specific Azure Resource Manager diff --git a/builtin/providers/azurerm/resource_arm_availability_set.go b/builtin/providers/azurerm/resource_arm_availability_set.go index 3e5f57d90..8852d0397 100644 --- a/builtin/providers/azurerm/resource_arm_availability_set.go +++ b/builtin/providers/azurerm/resource_arm_availability_set.go @@ -5,9 +5,9 @@ import ( "log" "net/http" - "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/schema" "github.com/jen20/riviera/azure" + "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) func resourceArmAvailabilitySet() *schema.Resource { diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go b/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go index 129e205c5..dba2d76c4 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go @@ -6,8 +6,8 @@ import ( "net/http" "reflect" - "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/schema" + "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) func resourceArmVirtualMachineExtensions() *schema.Resource { diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go b/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go index 02389f670..8b3ce7f3e 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go @@ -7,9 +7,9 @@ import ( "log" "net/http" - "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" + "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) func resourceArmVirtualMachineScaleSet() *schema.Resource { diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go index b81ca08c0..02f237950 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go @@ -6,10 +6,10 @@ import ( "strings" "testing" - "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" + "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { From 637915337f7f97a4059a40cfbc0249267afcdff3 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Wed, 1 Mar 2017 17:10:27 -0800 Subject: [PATCH 005/107] provider/azurerm: Bumped AzureRM/compute SDK to v8.1.0-beta --- builtin/providers/azurerm/config.go | 2 +- .../azurerm/resource_arm_availability_set.go | 2 +- .../azurerm/resource_arm_virtual_machine.go | 2 +- .../resource_arm_virtual_machine_extension.go | 2 +- .../resource_arm_virtual_machine_scale_set.go | 2 +- .../resource_arm_virtual_machine_test.go | 2 +- .../arm/compute/availabilitysets.go | 2 +- .../azure-sdk-for-go/arm/compute/client.go | 6 +- .../azure-sdk-for-go/arm/compute/models.go | 157 ++++++++++++++++-- .../azure-sdk-for-go/arm/compute/usage.go | 2 +- .../azure-sdk-for-go/arm/compute/version.go | 6 +- .../compute/virtualmachineextensionimages.go | 2 +- .../arm/compute/virtualmachineextensions.go | 2 +- .../arm/compute/virtualmachineimages.go | 2 +- .../arm/compute/virtualmachines.go | 72 +++++++- .../arm/compute/virtualmachinescalesets.go | 83 +++++++-- .../arm/compute/virtualmachinescalesetvms.go | 72 +++++++- .../arm/compute/virtualmachinesizes.go | 2 +- vendor/vendor.json | 22 +-- 19 files changed, 375 insertions(+), 67 deletions(-) diff --git a/builtin/providers/azurerm/config.go b/builtin/providers/azurerm/config.go index fc89d4d70..bbf15712f 100644 --- a/builtin/providers/azurerm/config.go +++ b/builtin/providers/azurerm/config.go @@ -8,6 +8,7 @@ import ( "net/http/httputil" "github.com/Azure/azure-sdk-for-go/arm/cdn" + "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/arm/containerregistry" "github.com/Azure/azure-sdk-for-go/arm/containerservice" "github.com/Azure/azure-sdk-for-go/arm/eventhub" @@ -24,7 +25,6 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/hashicorp/terraform/terraform" riviera "github.com/jen20/riviera/azure" - "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) // ArmClient contains the handles to all the specific Azure Resource Manager diff --git a/builtin/providers/azurerm/resource_arm_availability_set.go b/builtin/providers/azurerm/resource_arm_availability_set.go index 8852d0397..3e5f57d90 100644 --- a/builtin/providers/azurerm/resource_arm_availability_set.go +++ b/builtin/providers/azurerm/resource_arm_availability_set.go @@ -5,9 +5,9 @@ import ( "log" "net/http" + "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/schema" "github.com/jen20/riviera/azure" - "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) func resourceArmAvailabilitySet() *schema.Resource { diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index 6136ceacb..9c4fd47ca 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -9,11 +9,11 @@ import ( "net/url" "strings" + "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" riviera "github.com/jen20/riviera/azure" - "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) func resourceArmVirtualMachine() *schema.Resource { diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go b/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go index dba2d76c4..129e205c5 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_extension.go @@ -6,8 +6,8 @@ import ( "net/http" "reflect" + "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/schema" - "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) func resourceArmVirtualMachineExtensions() *schema.Resource { diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go b/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go index 8b3ce7f3e..02389f670 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set.go @@ -7,9 +7,9 @@ import ( "log" "net/http" + "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" - "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) func resourceArmVirtualMachineScaleSet() *schema.Resource { diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go index 02f237950..b81ca08c0 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go @@ -6,10 +6,10 @@ import ( "strings" "testing" + "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" - "github.com/mcardosos/azure-sdk-for-go/arm/compute" ) func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/availabilitysets.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/availabilitysets.go index 88176f3c3..1188c8b7c 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/availabilitysets.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/availabilitysets.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/client.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/client.go index 3f7e1f3f5..bbe0af39c 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/client.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/client.go @@ -1,5 +1,5 @@ // Package compute implements the Azure ARM Compute service API version -// 2016-03-30. +// 2016-04-30-preview. // // The Compute Management Client. package compute @@ -18,7 +18,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. @@ -28,7 +28,7 @@ import ( const ( // APIVersion is the version of the Compute - APIVersion = "2016-03-30" + APIVersion = "2016-04-30-preview" // DefaultBaseURI is the default URI used for the service Compute DefaultBaseURI = "https://management.azure.com" diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/models.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/models.go index 4cb2bd32c..405048772 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/models.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/models.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. @@ -66,6 +66,19 @@ const ( InstanceView InstanceViewTypes = "instanceView" ) +// OperatingSystemStateTypes enumerates the values for operating system state +// types. +type OperatingSystemStateTypes string + +const ( + // Generalized specifies the generalized state for operating system state + // types. + Generalized OperatingSystemStateTypes = "Generalized" + // Specialized specifies the specialized state for operating system state + // types. + Specialized OperatingSystemStateTypes = "Specialized" +) + // OperatingSystemTypes enumerates the values for operating system types. type OperatingSystemTypes string @@ -117,6 +130,16 @@ const ( Warning StatusLevelTypes = "Warning" ) +// StorageAccountTypes enumerates the values for storage account types. +type StorageAccountTypes string + +const ( + // PremiumLRS specifies the premium lrs state for storage account types. + PremiumLRS StorageAccountTypes = "Premium_LRS" + // StandardLRS specifies the standard lrs state for storage account types. + StandardLRS StorageAccountTypes = "Standard_LRS" +) + // UpgradeMode enumerates the values for upgrade mode. type UpgradeMode string @@ -374,6 +397,7 @@ type AvailabilitySet struct { Location *string `json:"location,omitempty"` Tags *map[string]*string `json:"tags,omitempty"` *AvailabilitySetProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` } // AvailabilitySetListResult is the List Availability Set operation response. @@ -388,6 +412,7 @@ type AvailabilitySetProperties struct { PlatformFaultDomainCount *int32 `json:"platformFaultDomainCount,omitempty"` VirtualMachines *[]SubResource `json:"virtualMachines,omitempty"` Statuses *[]InstanceViewStatus `json:"statuses,omitempty"` + Managed *bool `json:"managed,omitempty"` } // BootDiagnostics is describes Boot Diagnostics. @@ -405,13 +430,14 @@ type BootDiagnosticsInstanceView struct { // DataDisk is describes a data disk. type DataDisk struct { - Lun *int32 `json:"lun,omitempty"` - Name *string `json:"name,omitempty"` - Vhd *VirtualHardDisk `json:"vhd,omitempty"` - Image *VirtualHardDisk `json:"image,omitempty"` - Caching CachingTypes `json:"caching,omitempty"` - CreateOption DiskCreateOptionTypes `json:"createOption,omitempty"` - DiskSizeGB *int32 `json:"diskSizeGB,omitempty"` + Lun *int32 `json:"lun,omitempty"` + Name *string `json:"name,omitempty"` + Vhd *VirtualHardDisk `json:"vhd,omitempty"` + Image *VirtualHardDisk `json:"image,omitempty"` + Caching CachingTypes `json:"caching,omitempty"` + CreateOption DiskCreateOptionTypes `json:"createOption,omitempty"` + DiskSizeGB *int32 `json:"diskSizeGB,omitempty"` + ManagedDisk *ManagedDiskParameters `json:"managedDisk,omitempty"` } // DataDiskImage is contains the data disk images information. @@ -442,14 +468,79 @@ type HardwareProfile struct { VMSize VirtualMachineSizeTypes `json:"vmSize,omitempty"` } +// Image is describes an Image. +type Image struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` + *ImageProperties `json:"properties,omitempty"` +} + +// ImageDataDisk is describes a data disk. +type ImageDataDisk struct { + Lun *int32 `json:"lun,omitempty"` + Snapshot *SubResource `json:"snapshot,omitempty"` + ManagedDisk *SubResource `json:"managedDisk,omitempty"` + BlobURI *string `json:"blobUri,omitempty"` + Caching CachingTypes `json:"caching,omitempty"` + DiskSizeGB *int32 `json:"diskSizeGB,omitempty"` +} + +// ImageListResult is the List Image operation response. +type ImageListResult struct { + autorest.Response `json:"-"` + Value *[]Image `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// ImageListResultPreparer prepares a request to retrieve the next set of results. It returns +// nil if no more results exist. +func (client ImageListResult) ImageListResultPreparer() (*http.Request, error) { + if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(client.NextLink))) +} + +// ImageOSDisk is describes an Operating System disk. +type ImageOSDisk struct { + OsType OperatingSystemTypes `json:"osType,omitempty"` + OsState OperatingSystemStateTypes `json:"osState,omitempty"` + Snapshot *SubResource `json:"snapshot,omitempty"` + ManagedDisk *SubResource `json:"managedDisk,omitempty"` + BlobURI *string `json:"blobUri,omitempty"` + Caching CachingTypes `json:"caching,omitempty"` + DiskSizeGB *int32 `json:"diskSizeGB,omitempty"` +} + +// ImageProperties is describes the properties of an Image. +type ImageProperties struct { + SourceVirtualMachine *SubResource `json:"sourceVirtualMachine,omitempty"` + StorageProfile *ImageStorageProfile `json:"storageProfile,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} + // ImageReference is the image reference. type ImageReference struct { + ID *string `json:"id,omitempty"` Publisher *string `json:"publisher,omitempty"` Offer *string `json:"offer,omitempty"` Sku *string `json:"sku,omitempty"` Version *string `json:"version,omitempty"` } +// ImageStorageProfile is describes a storage profile. +type ImageStorageProfile struct { + OsDisk *ImageOSDisk `json:"osDisk,omitempty"` + DataDisks *[]ImageDataDisk `json:"dataDisks,omitempty"` +} + // InnerError is inner error details. type InnerError struct { Exceptiontype *string `json:"exceptiontype,omitempty"` @@ -520,6 +611,12 @@ type LongRunningOperationProperties struct { Output *map[string]interface{} `json:"output,omitempty"` } +// ManagedDiskParameters is the parameters of a managed disk. +type ManagedDiskParameters struct { + ID *string `json:"id,omitempty"` + StorageAccountType StorageAccountTypes `json:"storageAccountType,omitempty"` +} + // NetworkInterfaceReference is describes a network interface reference. type NetworkInterfaceReference struct { ID *string `json:"id,omitempty"` @@ -557,6 +654,7 @@ type OSDisk struct { Caching CachingTypes `json:"caching,omitempty"` CreateOption DiskCreateOptionTypes `json:"createOption,omitempty"` DiskSizeGB *int32 `json:"diskSizeGB,omitempty"` + ManagedDisk *ManagedDiskParameters `json:"managedDisk,omitempty"` } // OSDiskImage is contains the os disk image information. @@ -631,6 +729,11 @@ type SubResource struct { ID *string `json:"id,omitempty"` } +// SubResourceReadOnly is +type SubResourceReadOnly struct { + ID *string `json:"id,omitempty"` +} + // UpgradePolicy is describes an upgrade policy - automatic or manual. type UpgradePolicy struct { Mode UpgradeMode `json:"mode,omitempty"` @@ -854,9 +957,21 @@ type VirtualMachineScaleSet struct { Location *string `json:"location,omitempty"` Tags *map[string]*string `json:"tags,omitempty"` Sku *Sku `json:"sku,omitempty"` + Plan *Plan `json:"plan,omitempty"` *VirtualMachineScaleSetProperties `json:"properties,omitempty"` } +// VirtualMachineScaleSetDataDisk is describes a virtual machine scale set data +// disk. +type VirtualMachineScaleSetDataDisk struct { + Name *string `json:"name,omitempty"` + Lun *int32 `json:"lun,omitempty"` + Caching CachingTypes `json:"caching,omitempty"` + CreateOption DiskCreateOptionTypes `json:"createOption,omitempty"` + DiskSizeGB *int32 `json:"diskSizeGB,omitempty"` + ManagedDisk *VirtualMachineScaleSetManagedDiskParameters `json:"managedDisk,omitempty"` +} + // VirtualMachineScaleSetExtension is describes a Virtual Machine Scale Set // Extension. type VirtualMachineScaleSetExtension struct { @@ -975,6 +1090,12 @@ func (client VirtualMachineScaleSetListWithLinkResult) VirtualMachineScaleSetLis autorest.WithBaseURL(to.String(client.NextLink))) } +// VirtualMachineScaleSetManagedDiskParameters is describes the parameters of a +// ScaleSet managed disk. +type VirtualMachineScaleSetManagedDiskParameters struct { + StorageAccountType StorageAccountTypes `json:"storageAccountType,omitempty"` +} + // VirtualMachineScaleSetNetworkConfiguration is describes a virtual machine // scale set network profile's network configurations. type VirtualMachineScaleSetNetworkConfiguration struct { @@ -999,12 +1120,13 @@ type VirtualMachineScaleSetNetworkProfile struct { // VirtualMachineScaleSetOSDisk is describes a virtual machine scale set // operating system disk. type VirtualMachineScaleSetOSDisk struct { - Name *string `json:"name,omitempty"` - Caching CachingTypes `json:"caching,omitempty"` - CreateOption DiskCreateOptionTypes `json:"createOption,omitempty"` - OsType OperatingSystemTypes `json:"osType,omitempty"` - Image *VirtualHardDisk `json:"image,omitempty"` - VhdContainers *[]string `json:"vhdContainers,omitempty"` + Name *string `json:"name,omitempty"` + Caching CachingTypes `json:"caching,omitempty"` + CreateOption DiskCreateOptionTypes `json:"createOption,omitempty"` + OsType OperatingSystemTypes `json:"osType,omitempty"` + Image *VirtualHardDisk `json:"image,omitempty"` + VhdContainers *[]string `json:"vhdContainers,omitempty"` + ManagedDisk *VirtualMachineScaleSetManagedDiskParameters `json:"managedDisk,omitempty"` } // VirtualMachineScaleSetOSProfile is describes a virtual machine scale set OS @@ -1026,6 +1148,7 @@ type VirtualMachineScaleSetProperties struct { VirtualMachineProfile *VirtualMachineScaleSetVMProfile `json:"virtualMachineProfile,omitempty"` ProvisioningState *string `json:"provisioningState,omitempty"` Overprovision *bool `json:"overprovision,omitempty"` + SinglePlacementGroup *bool `json:"singlePlacementGroup,omitempty"` } // VirtualMachineScaleSetSku is describes an available virtual machine scale @@ -1047,8 +1170,9 @@ type VirtualMachineScaleSetSkuCapacity struct { // VirtualMachineScaleSetStorageProfile is describes a virtual machine scale // set storage profile. type VirtualMachineScaleSetStorageProfile struct { - ImageReference *ImageReference `json:"imageReference,omitempty"` - OsDisk *VirtualMachineScaleSetOSDisk `json:"osDisk,omitempty"` + ImageReference *ImageReference `json:"imageReference,omitempty"` + OsDisk *VirtualMachineScaleSetOSDisk `json:"osDisk,omitempty"` + DataDisks *[]VirtualMachineScaleSetDataDisk `json:"dataDisks,omitempty"` } // VirtualMachineScaleSetVM is describes a virtual machine scale set virtual @@ -1098,6 +1222,7 @@ type VirtualMachineScaleSetVMInstanceView struct { Extensions *[]VirtualMachineExtensionInstanceView `json:"extensions,omitempty"` BootDiagnostics *BootDiagnosticsInstanceView `json:"bootDiagnostics,omitempty"` Statuses *[]InstanceViewStatus `json:"statuses,omitempty"` + PlacementGroupID *string `json:"placementGroupId,omitempty"` } // VirtualMachineScaleSetVMListResult is the List Virtual Machine Scale Set VMs diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/usage.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/usage.go index 0ae6f581f..241b95bea 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/usage.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/usage.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/version.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/version.go index ecc8ec723..b28e58d36 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/version.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/version.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. @@ -26,7 +26,7 @@ import ( const ( major = "8" - minor = "0" + minor = "1" patch = "0" tag = "beta" userAgentFormat = "Azure-SDK-For-Go/%s arm-%s/%s" @@ -41,7 +41,7 @@ var ( // UserAgent returns the UserAgent string to use when sending http.Requests. func UserAgent() string { if userAgent == "" { - userAgent = fmt.Sprintf(userAgentFormat, Version(), "compute", "2016-03-30") + userAgent = fmt.Sprintf(userAgentFormat, Version(), "compute", "2016-04-30-preview") } return userAgent } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineextensionimages.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineextensionimages.go index 06038e5d3..dc91c9b4b 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineextensionimages.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineextensionimages.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineextensions.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineextensions.go index 3caec0316..143877549 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineextensions.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineextensions.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineimages.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineimages.go index bf5a02cfb..21562370b 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineimages.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachineimages.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachines.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachines.go index fb1908975..d1009f9d8 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachines.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachines.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. @@ -121,6 +121,74 @@ func (client VirtualMachinesClient) CaptureResponder(resp *http.Response) (resul return } +// ConvertToManagedDisks converts virtual machine disks from blob-based to +// managed disks. Virtual machine must be stop-deallocated before invoking this +// operation. This method may poll for completion. Polling can be canceled by +// passing the cancel channel argument. The channel will be used to cancel +// polling and any outstanding HTTP requests. +// +// resourceGroupName is the name of the resource group. vmName is the name of +// the virtual machine. +func (client VirtualMachinesClient) ConvertToManagedDisks(resourceGroupName string, vmName string, cancel <-chan struct{}) (result autorest.Response, err error) { + req, err := client.ConvertToManagedDisksPreparer(resourceGroupName, vmName, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "ConvertToManagedDisks", nil, "Failure preparing request") + } + + resp, err := client.ConvertToManagedDisksSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "ConvertToManagedDisks", resp, "Failure sending request") + } + + result, err = client.ConvertToManagedDisksResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "ConvertToManagedDisks", resp, "Failure responding to request") + } + + return +} + +// ConvertToManagedDisksPreparer prepares the ConvertToManagedDisks request. +func (client VirtualMachinesClient) ConvertToManagedDisksPreparer(resourceGroupName string, vmName string, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "vmName": autorest.Encode("path", vmName), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/convertToManagedDisks", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// ConvertToManagedDisksSender sends the ConvertToManagedDisks request. The method will close the +// http.Response Body if it receives an error. +func (client VirtualMachinesClient) ConvertToManagedDisksSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// ConvertToManagedDisksResponder handles the response to the ConvertToManagedDisks request. The method always +// closes the http.Response Body. +func (client VirtualMachinesClient) ConvertToManagedDisksResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + // CreateOrUpdate the operation to create or update a virtual machine. This // method may poll for completion. Polling can be canceled by passing the // cancel channel argument. The channel will be used to cancel polling and any @@ -145,8 +213,6 @@ func (client VirtualMachinesClient) CreateOrUpdate(resourceGroupName string, vmN {Target: "parameters.VirtualMachineProperties.StorageProfile.OsDisk.EncryptionSettings.KeyEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, }}, }}, - {Target: "parameters.VirtualMachineProperties.StorageProfile.OsDisk.Name", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.VirtualMachineProperties.StorageProfile.OsDisk.Vhd", Name: validation.Null, Rule: true, Chain: nil}, }}, }}, }}}}}); err != nil { diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesets.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesets.go index 64101688f..8e1705619 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesets.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesets.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. @@ -50,19 +50,6 @@ func NewVirtualMachineScaleSetsClientWithBaseURI(baseURI string, subscriptionID // resourceGroupName is the name of the resource group. name is the name of the // VM scale set to create or update. parameters is the scale set object. func (client VirtualMachineScaleSetsClient) CreateOrUpdate(resourceGroupName string, name string, parameters VirtualMachineScaleSet, cancel <-chan struct{}) (result autorest.Response, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.VirtualMachineScaleSetProperties", Name: validation.Null, Rule: false, - Chain: []validation.Constraint{{Target: "parameters.VirtualMachineScaleSetProperties.VirtualMachineProfile", Name: validation.Null, Rule: false, - Chain: []validation.Constraint{{Target: "parameters.VirtualMachineScaleSetProperties.VirtualMachineProfile.StorageProfile", Name: validation.Null, Rule: false, - Chain: []validation.Constraint{{Target: "parameters.VirtualMachineScaleSetProperties.VirtualMachineProfile.StorageProfile.OsDisk", Name: validation.Null, Rule: false, - Chain: []validation.Constraint{{Target: "parameters.VirtualMachineScaleSetProperties.VirtualMachineProfile.StorageProfile.OsDisk.Name", Name: validation.Null, Rule: true, Chain: nil}}}, - }}, - }}, - }}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "compute.VirtualMachineScaleSetsClient", "CreateOrUpdate") - } - req, err := client.CreateOrUpdatePreparer(resourceGroupName, name, parameters, cancel) if err != nil { return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "CreateOrUpdate", nil, "Failure preparing request") @@ -867,6 +854,74 @@ func (client VirtualMachineScaleSetsClient) ReimageResponder(resp *http.Response return } +// ReimageAll reimages all the disks ( including data disks ) in the virtual +// machines in a virtual machine scale set. This operation is only supported +// for managed disks. This method may poll for completion. Polling can be +// canceled by passing the cancel channel argument. The channel will be used to +// cancel polling and any outstanding HTTP requests. +// +// resourceGroupName is the name of the resource group. vmScaleSetName is the +// name of the VM scale set. +func (client VirtualMachineScaleSetsClient) ReimageAll(resourceGroupName string, vmScaleSetName string, cancel <-chan struct{}) (result autorest.Response, err error) { + req, err := client.ReimageAllPreparer(resourceGroupName, vmScaleSetName, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ReimageAll", nil, "Failure preparing request") + } + + resp, err := client.ReimageAllSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ReimageAll", resp, "Failure sending request") + } + + result, err = client.ReimageAllResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetsClient", "ReimageAll", resp, "Failure responding to request") + } + + return +} + +// ReimageAllPreparer prepares the ReimageAll request. +func (client VirtualMachineScaleSetsClient) ReimageAllPreparer(resourceGroupName string, vmScaleSetName string, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "vmScaleSetName": autorest.Encode("path", vmScaleSetName), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/reimageall", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// ReimageAllSender sends the ReimageAll request. The method will close the +// http.Response Body if it receives an error. +func (client VirtualMachineScaleSetsClient) ReimageAllSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// ReimageAllResponder handles the response to the ReimageAll request. The method always +// closes the http.Response Body. +func (client VirtualMachineScaleSetsClient) ReimageAllResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + // Restart restarts one or more virtual machines in a VM scale set. This method // may poll for completion. Polling can be canceled by passing the cancel // channel argument. The channel will be used to cancel polling and any diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesetvms.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesetvms.go index de5b4235f..1b9e34177 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesetvms.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinescalesetvms.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. @@ -549,6 +549,76 @@ func (client VirtualMachineScaleSetVMsClient) ReimageResponder(resp *http.Respon return } +// ReimageAll allows you to re-image all the disks ( including data disks ) in +// the a virtual machine scale set instance. This operation is only supported +// for managed disks. This method may poll for completion. Polling can be +// canceled by passing the cancel channel argument. The channel will be used to +// cancel polling and any outstanding HTTP requests. +// +// resourceGroupName is the name of the resource group. vmScaleSetName is the +// name of the VM scale set. instanceID is the instance ID of the virtual +// machine. +func (client VirtualMachineScaleSetVMsClient) ReimageAll(resourceGroupName string, vmScaleSetName string, instanceID string, cancel <-chan struct{}) (result autorest.Response, err error) { + req, err := client.ReimageAllPreparer(resourceGroupName, vmScaleSetName, instanceID, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetVMsClient", "ReimageAll", nil, "Failure preparing request") + } + + resp, err := client.ReimageAllSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetVMsClient", "ReimageAll", resp, "Failure sending request") + } + + result, err = client.ReimageAllResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetVMsClient", "ReimageAll", resp, "Failure responding to request") + } + + return +} + +// ReimageAllPreparer prepares the ReimageAll request. +func (client VirtualMachineScaleSetVMsClient) ReimageAllPreparer(resourceGroupName string, vmScaleSetName string, instanceID string, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "instanceId": autorest.Encode("path", instanceID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "vmScaleSetName": autorest.Encode("path", vmScaleSetName), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/virtualmachines/{instanceId}/reimageall", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// ReimageAllSender sends the ReimageAll request. The method will close the +// http.Response Body if it receives an error. +func (client VirtualMachineScaleSetVMsClient) ReimageAllSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// ReimageAllResponder handles the response to the ReimageAll request. The method always +// closes the http.Response Body. +func (client VirtualMachineScaleSetVMsClient) ReimageAllResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + // Restart restarts a virtual machine in a VM scale set. This method may poll // for completion. Polling can be canceled by passing the cancel channel // argument. The channel will be used to cancel polling and any outstanding diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinesizes.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinesizes.go index 19f4b72e5..169b79286 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinesizes.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/virtualmachinesizes.go @@ -14,7 +14,7 @@ package compute // See the License for the specific language governing permissions and // limitations under the License. // -// Code generated by Microsoft (R) AutoRest Code Generator 1.0.0.0 +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 // Changes may cause incorrect behavior and will be lost if the code is // regenerated. diff --git a/vendor/vendor.json b/vendor/vendor.json index 0b033f90c..5bbfac274 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -23,15 +23,15 @@ "version": "v8.0.1-beta", "versionExact": "v8.0.1-beta" }, - /*{ - "checksumSHA1": "+w9njWehvjvkFK4JHAEtTgvmVgE=", + { + "checksumSHA1": "xOt4xQmO/KFcJYjQ678DL5ynub4=", "comment": "v2.1.1-beta-8-gca4d906", "path": "github.com/Azure/azure-sdk-for-go/arm/compute", - "revision": "8e625d1702a32d01cef05a9252198d231c4af113", - "revisionTime": "2017-02-08T01:01:20Z", - "version": "v8.0.1-beta", - "versionExact": "v8.0.1-beta" - },*/ + "revision": "ecf40e315d5ab0ca6d7b3b7f7fbb5c1577814813", + "revisionTime": "2017-03-02T00:14:02Z", + "version": "v8.1.0-beta", + "versionExact": "v8.1.0-beta" + }, { "checksumSHA1": "JbbZWArn6iqSs+neT5X8AxxH6o0=", "comment": "v2.1.1-beta-8-gca4d906", @@ -2347,14 +2347,6 @@ "path": "github.com/maximilien/softlayer-go/softlayer", "revision": "85659debe44fab5792fc92cf755c04b115b9dc19" }, - { - "checksumSHA1": "MJ2PfEAmNJ0/H+uFcNYKWdiQIiM=", - "path": "github.com/mcardosos/azure-sdk-for-go/arm/compute", - "revision": "a7cd8005acf2eb9ffa8298450616e042370c22bc", - "revisionTime": "2017-02-28T01:51:47Z", - "version": "=v8.1.0-beta", - "versionExact": "v8.1.0-beta" - }, { "checksumSHA1": "GSum+utW01N3KeMdvAPnsW0TemM=", "path": "github.com/michaelklishin/rabbit-hole", From 909976eebeb6b3eaa90351ca42925fd30a4ae8bb Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Wed, 1 Mar 2017 18:30:53 -0800 Subject: [PATCH 006/107] fixed nil check in resourceArmVirtualMachineStorageOsDiskHash --- builtin/providers/azurerm/resource_arm_virtual_machine.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index 9c4fd47ca..2f1fbce77 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -808,8 +808,8 @@ func resourceArmVirtualMachineStorageOsDiskHash(v interface{}) int { if m["vhd_uri"] != nil { buf.WriteString(fmt.Sprintf("%s-", m["vhd_uri"].(string))) } - if m["managed_disk"] != nil { - managedDisk := m["managed_disk"].(map[string]interface{}) + managedDisk := m["managed_disk"].(map[string]interface{}) + if managedDisk["storage_account_type"] != nil { buf.WriteString(fmt.Sprintf("%s-", managedDisk["storage_account_type"].(string))) } return hashcode.String(buf.String()) From 00df2204a25f00801c35bd4ab441d6f289c6bad8 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Wed, 1 Mar 2017 18:32:03 -0800 Subject: [PATCH 007/107] fixed nil check in resourceArmVirtualMachineStorageOsDiskHash --- builtin/providers/azurerm/resource_arm_virtual_machine.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index 2f1fbce77..7cc1d19b3 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -808,9 +808,11 @@ func resourceArmVirtualMachineStorageOsDiskHash(v interface{}) int { if m["vhd_uri"] != nil { buf.WriteString(fmt.Sprintf("%s-", m["vhd_uri"].(string))) } - managedDisk := m["managed_disk"].(map[string]interface{}) - if managedDisk["storage_account_type"] != nil { - buf.WriteString(fmt.Sprintf("%s-", managedDisk["storage_account_type"].(string))) + if m["managed_disk"] != nil { + managedDisk := m["managed_disk"].(map[string]interface{}) + if managedDisk["storage_account_type"] != nil { + buf.WriteString(fmt.Sprintf("%s-", managedDisk["storage_account_type"].(string))) + } } return hashcode.String(buf.String()) } From 5c0b7504664675f6ad982d05ab87bd76edc6243a Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Wed, 1 Mar 2017 18:51:00 -0800 Subject: [PATCH 008/107] acceptance tests for managed disks changed location to West US 2 --- .../import_arm_virtual_machine_test.go | 28 + .../resource_arm_virtual_machine_test.go | 583 ++++++++++++++---- 2 files changed, 505 insertions(+), 106 deletions(-) diff --git a/builtin/providers/azurerm/import_arm_virtual_machine_test.go b/builtin/providers/azurerm/import_arm_virtual_machine_test.go index 806d44987..dad790049 100644 --- a/builtin/providers/azurerm/import_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/import_arm_virtual_machine_test.go @@ -35,3 +35,31 @@ func TestAccAzureRMVirtualMachine_importBasic(t *testing.T) { }, }) } + +func TestAccAzureRMVirtualMachine_importBasic_managedDisk(t *testing.T) { + resourceName := "azurerm_virtual_machine.test" + + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk, ri, ri, ri, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "delete_data_disks_on_termination", + "delete_os_disk_on_termination", + }, + }, + }, + }) +} diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go index b81ca08c0..3593b47e9 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go @@ -31,6 +31,25 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { }) } +func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk(t *testing.T) { + var vm compute.VirtualMachine + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk, 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 TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) { var vm compute.VirtualMachine ri := acctest.RandInt() @@ -72,6 +91,26 @@ func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) { }) } +func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk(t *testing.T) { + var vm compute.VirtualMachine + + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk_managedDisk, 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 TestAccAzureRMVirtualMachine_tags(t *testing.T) { var vm compute.VirtualMachine @@ -143,6 +182,39 @@ func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) { }) } +//This is a regression test around https://github.com/hashicorp/terraform/issues/6517 +//Because we use CreateOrUpdate, we were sending an empty password on update requests +func TestAccAzureRMVirtualMachine_updateMachineSize_managedDisk(t *testing.T) { + var vm compute.VirtualMachine + + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk, ri, ri, ri, ri, ri, ri) + postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updatedLinuxMachine_managedDisk, ri, ri, ri, ri, ri, ri) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineDestroy, + Steps: []resource.TestStep{ + { + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + resource.TestCheckResourceAttr( + "azurerm_virtual_machine.test", "vm_size", "Standard_A0"), + ), + }, + { + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + resource.TestCheckResourceAttr( + "azurerm_virtual_machine.test", "vm_size", "Standard_A1"), + ), + }, + }, + }) +} + func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) { var vm compute.VirtualMachine ri := acctest.RandInt() @@ -583,13 +655,13 @@ func TestAccAzureRMVirtualMachine_windowsLicenseType(t *testing.T) { var testAccAzureRMVirtualMachine_basicLinuxMachine = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -602,7 +674,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -615,7 +687,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -632,7 +704,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -669,16 +741,16 @@ resource "azurerm_virtual_machine" "test" { } ` -var testAccAzureRMVirtualMachine_machineNameBeforeUpdate = ` +var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -691,7 +763,81 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" + 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_virtual_machine" "test" { + name = "acctvm-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_A0" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "14.04.2-LTS" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + disk_size_gb = "45" + + managed_disk { + storage_account_type = "Standard_LRS" + } + } + + os_profile { + computer_name = "hostname%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags { + environment = "Production" + cost-center = "Ops" + } +} +` + +var testAccAzureRMVirtualMachine_machineNameBeforeUpdate = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "West US 2" + 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 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -704,7 +850,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -721,7 +867,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -761,18 +907,18 @@ resource "azurerm_virtual_machine" "test" { var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_resource_group" "test-sa" { name = "acctestRG-sa-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -785,7 +931,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -798,7 +944,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test-sa.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -815,7 +961,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -866,18 +1012,18 @@ resource "azurerm_virtual_machine" "test" { var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_resource_group" "test-sa" { name = "acctestRG-sa-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -890,7 +1036,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -903,7 +1049,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test-sa.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -922,13 +1068,13 @@ resource "azurerm_storage_container" "test" { var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -941,7 +1087,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -954,7 +1100,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -973,13 +1119,13 @@ resource "azurerm_storage_container" "test" { var testAccAzureRMVirtualMachine_withDataDisk = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -992,7 +1138,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1005,7 +1151,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1022,7 +1168,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -1067,16 +1213,16 @@ resource "azurerm_virtual_machine" "test" { } ` -var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = ` +var testAccAzureRMVirtualMachine_withDataDisk_managedDisk = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1089,7 +1235,92 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" + 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_virtual_machine" "test" { + name = "acctvm-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_DS1" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "14.04.2-LTS" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + + managed_disk { + storage_account_type = "Standard_LRS" + } + } + + storage_data_disk { + name = "mydatadisk1" + disk_size_gb = "1023" + create_option = "Empty" + caching = "ReadWrite" + lun = 0 + + managed_disk { + storage_account_type = "Premium_LRS" + } + } + + os_profile { + computer_name = "hostname%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags { + environment = "Production" + cost-center = "Ops" + } +} +` + +var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "West US 2" + 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 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1102,7 +1333,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1119,7 +1350,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -1154,16 +1385,16 @@ resource "azurerm_virtual_machine" "test" { } ` -var testAccAzureRMVirtualMachine_updatedLinuxMachine = ` +var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated_managedDisk = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1176,7 +1407,79 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" + 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_virtual_machine" "test" { + name = "acctvm-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_DS1" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "14.04.2-LTS" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + + managed_disk { + storage_account_type = "Premium_LRS" + } + } + + os_profile { + computer_name = "hostname%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags { + environment = "Production" + } +} +` + +var testAccAzureRMVirtualMachine_updatedLinuxMachine = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "West US 2" + 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 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1189,7 +1492,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1206,7 +1509,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A1" @@ -1237,16 +1540,16 @@ resource "azurerm_virtual_machine" "test" { } ` -var testAccAzureRMVirtualMachine_basicWindowsMachine = ` +var testAccAzureRMVirtualMachine_updatedLinuxMachine_managedDisk = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1259,7 +1562,75 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" + 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_virtual_machine" "test" { + name = "acctvm-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_DS1" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "14.04.2-LTS" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + + managed_disk { + storage_account_type = "Premium_LRS" + } + } + + os_profile { + computer_name = "hostname%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } +} +` + +var testAccAzureRMVirtualMachine_basicWindowsMachine = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "West US 2" + 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 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1272,7 +1643,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1289,7 +1660,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -1324,13 +1695,13 @@ resource "azurerm_virtual_machine" "test" { var testAccAzureRMVirtualMachine_windowsUnattendedConfig = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1343,7 +1714,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1356,7 +1727,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1373,7 +1744,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -1414,13 +1785,13 @@ resource "azurerm_virtual_machine" "test" { var testAccAzureRMVirtualMachine_diagnosticsProfile = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1433,7 +1804,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1446,7 +1817,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1463,7 +1834,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -1505,13 +1876,13 @@ resource "azurerm_virtual_machine" "test" { var testAccAzureRMVirtualMachine_winRMConfig = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1524,7 +1895,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1537,7 +1908,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1554,7 +1925,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -1590,13 +1961,13 @@ resource "azurerm_virtual_machine" "test" { var testAccAzureRMVirtualMachine_withAvailabilitySet = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1609,7 +1980,7 @@ var testAccAzureRMVirtualMachine_withAvailabilitySet = ` resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1622,7 +1993,7 @@ var testAccAzureRMVirtualMachine_withAvailabilitySet = ` resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1632,7 +2003,7 @@ var testAccAzureRMVirtualMachine_withAvailabilitySet = ` resource "azurerm_availability_set" "test" { name = "availabilityset%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1645,7 +2016,7 @@ var testAccAzureRMVirtualMachine_withAvailabilitySet = ` resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -1681,13 +2052,13 @@ var testAccAzureRMVirtualMachine_withAvailabilitySet = ` var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1700,7 +2071,7 @@ var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1713,7 +2084,7 @@ var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1723,7 +2094,7 @@ var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` resource "azurerm_availability_set" "test" { name = "updatedAvailabilitySet%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1736,7 +2107,7 @@ var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -1772,13 +2143,13 @@ var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` var testAccAzureRMVirtualMachine_updateMachineName = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1791,7 +2162,7 @@ var testAccAzureRMVirtualMachine_updateMachineName = ` resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1804,7 +2175,7 @@ var testAccAzureRMVirtualMachine_updateMachineName = ` resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1821,7 +2192,7 @@ var testAccAzureRMVirtualMachine_updateMachineName = ` resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -1856,13 +2227,13 @@ var testAccAzureRMVirtualMachine_updateMachineName = ` var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1875,7 +2246,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1888,7 +2259,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1905,7 +2276,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -1946,13 +2317,13 @@ resource "azurerm_virtual_machine" "test" { var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -1965,7 +2336,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -1978,7 +2349,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -1995,7 +2366,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -2036,13 +2407,13 @@ resource "azurerm_virtual_machine" "test" { var testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -2055,7 +2426,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -2068,7 +2439,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -2085,7 +2456,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -2125,13 +2496,13 @@ resource "azurerm_virtual_machine" "test" { var testAccAzureRMVirtualMachine_windowsLicenseType = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -2144,7 +2515,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -2157,7 +2528,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -2174,7 +2545,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_A0" @@ -2210,13 +2581,13 @@ resource "azurerm_virtual_machine" "test" { var testAccAzureRMVirtualMachine_plan = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West US 2" } resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" } @@ -2229,7 +2600,7 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" ip_configuration { @@ -2242,7 +2613,7 @@ resource "azurerm_network_interface" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "westus" + location = "West US 2" account_type = "Standard_LRS" tags { @@ -2259,7 +2630,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "West US" + location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] vm_size = "Standard_DS1_v2" From e7613747381969c43ecd29c5b83d16022f127323 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Wed, 1 Mar 2017 19:00:15 -0800 Subject: [PATCH 009/107] fixed postConfig check to verify the corrent vm size --- builtin/providers/azurerm/resource_arm_virtual_machine_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go index 3593b47e9..6bd4e2cc1 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go @@ -208,7 +208,7 @@ func TestAccAzureRMVirtualMachine_updateMachineSize_managedDisk(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), resource.TestCheckResourceAttr( - "azurerm_virtual_machine.test", "vm_size", "Standard_A1"), + "azurerm_virtual_machine.test", "vm_size", "Standard_DS1"), ), }, }, From b7df7d4fd2e1b77666aa4ebf767f48b9b73e9770 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Wed, 1 Mar 2017 19:01:04 -0800 Subject: [PATCH 010/107] changed DS1 to DS1_v2 --- .../azurerm/resource_arm_virtual_machine_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go index 6bd4e2cc1..3fbfc2c97 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go @@ -208,7 +208,7 @@ func TestAccAzureRMVirtualMachine_updateMachineSize_managedDisk(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), resource.TestCheckResourceAttr( - "azurerm_virtual_machine.test", "vm_size", "Standard_DS1"), + "azurerm_virtual_machine.test", "vm_size", "Standard_DS1_v2"), ), }, }, @@ -1250,7 +1250,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_DS1" + vm_size = "Standard_DS1_v2" storage_image_reference { publisher = "Canonical" @@ -1422,7 +1422,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_DS1" + vm_size = "Standard_DS1_v2" storage_image_reference { publisher = "Canonical" @@ -1577,7 +1577,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_DS1" + vm_size = "Standard_DS1_v2" storage_image_reference { publisher = "Canonical" @@ -2633,7 +2633,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_DS1_v2" + vm_size = "Standard_DS1_v2_v2" storage_image_reference { publisher = "kemptech" From 0a07c14377f743fac4c56bda8b7eec1cbcad1b66 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Fri, 3 Mar 2017 12:12:00 -0800 Subject: [PATCH 011/107] [WIP] arm/disk implementation --- builtin/providers/azurerm/config.go | 3 + .../providers/azurerm/import_arm_disk_test.go | 39 +++ .../providers/azurerm/resource_arm_disk.go | 242 ++++++++++++++++++ .../azurerm/resource_arm_disk_test.go | 1 + .../azurerm/resource_arm_virtual_machine.go | 10 +- vendor/vendor.json | 8 + 6 files changed, 294 insertions(+), 9 deletions(-) create mode 100644 builtin/providers/azurerm/import_arm_disk_test.go create mode 100644 builtin/providers/azurerm/resource_arm_disk.go create mode 100644 builtin/providers/azurerm/resource_arm_disk_test.go diff --git a/builtin/providers/azurerm/config.go b/builtin/providers/azurerm/config.go index bbf15712f..d5c3503df 100644 --- a/builtin/providers/azurerm/config.go +++ b/builtin/providers/azurerm/config.go @@ -25,6 +25,7 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/hashicorp/terraform/terraform" riviera "github.com/jen20/riviera/azure" + "github.com/Azure/azure-sdk-for-go/arm/disk" ) // ArmClient contains the handles to all the specific Azure Resource Manager @@ -47,6 +48,8 @@ type ArmClient struct { vmImageClient compute.VirtualMachineImagesClient vmClient compute.VirtualMachinesClient + diskClient disk.DisksClient + appGatewayClient network.ApplicationGatewaysClient ifaceClient network.InterfacesClient loadBalancerClient network.LoadBalancersClient diff --git a/builtin/providers/azurerm/import_arm_disk_test.go b/builtin/providers/azurerm/import_arm_disk_test.go new file mode 100644 index 000000000..35c52c008 --- /dev/null +++ b/builtin/providers/azurerm/import_arm_disk_test.go @@ -0,0 +1,39 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAzureRMDisk_importEmpty(t *testing.T) { + runTestAzureRMDisk_import(t, "azurerm_disk.test", testAccAzureRMDisk_emptyDisk) +} + +func TestAccAzureRMDisk_importBlob(t *testing.T) { + runTestAzureRMDisk_import(t, "azurerm_disk.test", testAccAzureRMDisk_blob) +} + +func runTestAzureRMDisk_import(t *testing.T, resourceName string, configSource string) { + ri := acctest.RandInt() + config := fmt.Sprintf(configSource, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t)}, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDiskDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} \ No newline at end of file diff --git a/builtin/providers/azurerm/resource_arm_disk.go b/builtin/providers/azurerm/resource_arm_disk.go new file mode 100644 index 000000000..1bf1fdf73 --- /dev/null +++ b/builtin/providers/azurerm/resource_arm_disk.go @@ -0,0 +1,242 @@ +package azurerm + +import ( + "github.com/Azure/azure-sdk-for-go/arm/disk" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + "fmt" + "log" + "strings" + "net/http" +) + +func resourceArmDisk() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDiskCreate, + Read: resourceArmDiskRead, + Update: resourceArmDiskCreate, + Delete: resourceArmDiskDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "location": locationSchema(), + + "resource_group_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "storage_account_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(disk.PremiumLRS), + string(disk.StandardLRS), + }, true), + }, + + "create_option": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(disk.Import), + string(disk.Empty), + }, true), + }, + + "vhd_uri": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + + "os_type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + string(disk.Windows), + string(disk.Linux), + }, true), + }, + + "disk_size_gb": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validateDiskSizeGB, + }, + + "tags": tagsSchema(), + }, + } +} + +func validateDiskSizeGB(v interface{}, k string) (ws []string, errors []error) { + value := v.(int) + if value < 1 || value > 1023 { + errors = append(errors, fmt.Errorf( + "The `disk_size_gb` can only be between 1 and 1023")) + } + return +} + +func resourceArmDiskCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient) + diskClient := client.diskClient + + log.Printf("[INFO] preparing arguments for Azure ARM Disk creation.") + + name := d.Get("name").(string) + location := d.Get("location").(string) + resGroup := d.Get("resource_group_name").(string) + tags := d.Get("tags").(map[string]interface{}) + expandedTags := expandTags(tags) + + createDisk := &disk.Model { + Name: &name, + Location: &location, + Tags: expandedTags, + } + + storageAccountType := d.Get("storage_account_type").(string) + osType := d.Get("os_type").(string) + diskSize := d.Get("disk_size_db").(int) + + createDisk.Properties = &disk.Properties { + AccountType: &storageAccountType, + OsType: &osType, + DiskSizeGB: &diskSize, + } + + createOption := d.Get("create_option").(string) + + creationData := &disk.CreationData{ + CreateOption: disk.CreateOption(createOption), + } + + if strings.EqualFold(createOption, disk.Import) { + if vhdUri := d.Get("vhd_uri").(string); vhdUri != "" { + creationData.SourceURI = vhdUri; + } else { + return nil, fmt.Errorf("[ERROR] vhd_uri must be specified when create_option is `%s`", disk.Import) + } + } + + createDisk.CreationData = creationData + + _, diskErr := diskClient.CreateOrUpdate(resGroup, name, createDisk, make(chan struct{})) + if diskErr != nil { + return diskErr + } + + read, err := diskClient.Get(resGroup, name) + if err != nil{ + return err + } + if read.ID == nil { + return fmt.Errorf("[ERROR] Cannot read Disk %s (resource group %s) ID", name, resGroup) + } + + d.SetId(*read.ID) + + return resourceArmDiskRead(d, meta) +} + +func resourceArmDiskRead(d *schema.ResourceData, meta interface{}) error { + diskClient := meta.(*ArmClient).diskClient + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["disks"] + + resp, err := diskClient.Get(resGroup, name) + if err != nil { + if resp.StatusCode == http.StatusNotFound { + d.SetId("") + return nil + } + return fmt.Errorf("[ERROR] Error making Read request on Azure Disk %s (resource group %s): %s", name, resGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resGroup) + d.Set("location", resp.Location) + + if resp.Properties != nil { + if m, err := flattenAzureRmDiskProperties(resp.Properties); err != nil { + return fmt.Errorf("[DEBUG] Error setting disk properties: %#v", err) + } else { + d.Set("storage_account_type", m["storage_account_type"]) + d.Set("disk_size_gb", m["disk_size_gb"]) + if m["os_type"] != nil { + d.Set("os_type", m["os_type"]) + } + + } + } + + if resp.CreationData != nil { + if m, err := flattenAzureRmDiskCreationData(resp.CreationData); err != nil { + return fmt.Errorf("[DEBUG] Error setting disk creation data: %#v", err) + } else { + d.Set("create_option", m["create_option"]) + if m["vhd_uri"] != nil { + d.Set("vhd_uri", m["vhd_uri"]) + } + } + } + + flattenAndSetTags(d, resp.Tags) + + return nil +} + +func resourceArmDiskDelete(d *schema.ResourceData, meta interface{}) error { + diskClient := meta.(*ArmClient).diskClient + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["disks"] + + if _, err = diskClient.Delete(resGroup, name, make(chan struct{})); err != nil { + return err + } + + return nil +} + +func flattenAzureRmDiskProperties(properties *disk.Properties) (map[string]interface{}, error) { + result := make(map[string]interface{}) + result["storage_account_type"] = *properties.AccountType + result["disk_size_gb"] = *properties.DiskSizeGB + if properties.OsType != nil { + result["os_type"] = *properties.OsType + } + + return result, nil +} + +func flattenAzureRmDiskCreationData(creationData *disk.CreationData) (map[string]interface{}, error) { + result := make(map[string]interface{}) + result["create_option"] = *creationData.CreateOption + if creationData.SourceURI != nil { + result["vhd_uri"] = *creationData.SourceURI + } + + return result, nil +} \ No newline at end of file diff --git a/builtin/providers/azurerm/resource_arm_disk_test.go b/builtin/providers/azurerm/resource_arm_disk_test.go new file mode 100644 index 000000000..96f5b5587 --- /dev/null +++ b/builtin/providers/azurerm/resource_arm_disk_test.go @@ -0,0 +1 @@ +package azurerm diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index 7cc1d19b3..d12c9f70c 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -243,6 +243,7 @@ func resourceArmVirtualMachine() *schema.Resource { Type: schema.TypeInt, Optional: true, Computed: true, + ValidateFunc: validateDiskSizeGB, }, "lun": { @@ -483,15 +484,6 @@ func validateLicenseType(v interface{}, k string) (ws []string, errors []error) return } -func validateDiskSizeGB(v interface{}, k string) (ws []string, errors []error) { - value := v.(int) - if value < 1 || value > 1023 { - errors = append(errors, fmt.Errorf( - "The `disk_size_gb` can only be between 1 and 1023")) - } - return -} - func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient) vmClient := client.vmClient diff --git a/vendor/vendor.json b/vendor/vendor.json index 388236970..05e8a5b87 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -48,6 +48,14 @@ "revision": "8e625d1702a32d01cef05a9252198d231c4af113", "revisionTime": "2017-02-08T01:01:20Z" }, + { + "checksumSHA1": "iAZi+Mh1Tivk3bdBbAEz+bd5nPg=", + "path": "github.com/Azure/azure-sdk-for-go/arm/disk", + "revision": "ecf40e315d5ab0ca6d7b3b7f7fbb5c1577814813", + "revisionTime": "2017-03-02T00:14:02Z", + "version": "v8.1.0-beta", + "versionExact": "v8.1.0-beta" + }, { "checksumSHA1": "Amd1JuJVsI9wU3+KI4Ba4jBbxps=", "comment": "v2.1.1-beta-8-gca4d906", From 2df44e0779f21603dfce9e302965a8d763dac6fc Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Fri, 3 Mar 2017 14:31:40 -0800 Subject: [PATCH 012/107] [WIP] arm/disk implementation --- builtin/providers/azurerm/config.go | 8 +- .../providers/azurerm/import_arm_disk_test.go | 18 +- builtin/providers/azurerm/provider.go | 2 + .../providers/azurerm/resource_arm_disk.go | 49 +- .../azurerm/resource_arm_disk_test.go | 104 +++ .../azure-sdk-for-go/arm/compute/images.go | 421 ++++++++++++ .../Azure/azure-sdk-for-go/arm/disk/client.go | 58 ++ .../Azure/azure-sdk-for-go/arm/disk/disks.go | 638 +++++++++++++++++ .../Azure/azure-sdk-for-go/arm/disk/models.go | 278 ++++++++ .../azure-sdk-for-go/arm/disk/snapshots.go | 643 ++++++++++++++++++ .../azure-sdk-for-go/arm/disk/version.go | 60 ++ 11 files changed, 2245 insertions(+), 34 deletions(-) create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/compute/images.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/disk/client.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/disk/disks.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/disk/models.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/disk/snapshots.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/disk/version.go diff --git a/builtin/providers/azurerm/config.go b/builtin/providers/azurerm/config.go index d5c3503df..8535b67c7 100644 --- a/builtin/providers/azurerm/config.go +++ b/builtin/providers/azurerm/config.go @@ -11,6 +11,7 @@ import ( "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/arm/containerregistry" "github.com/Azure/azure-sdk-for-go/arm/containerservice" + "github.com/Azure/azure-sdk-for-go/arm/disk" "github.com/Azure/azure-sdk-for-go/arm/eventhub" "github.com/Azure/azure-sdk-for-go/arm/keyvault" "github.com/Azure/azure-sdk-for-go/arm/network" @@ -25,7 +26,6 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/hashicorp/terraform/terraform" riviera "github.com/jen20/riviera/azure" - "github.com/Azure/azure-sdk-for-go/arm/disk" ) // ArmClient contains the handles to all the specific Azure Resource Manager @@ -248,6 +248,12 @@ func (c *Config) getArmClient() (*ArmClient, error) { csc.Sender = autorest.CreateSender(withRequestLogging()) client.containerServicesClient = csc + dkc := disk.NewDisksClientWithBaseURI(endpoint, c.SubscriptionID) + setUserAgent(&dkc.Client) + dkc.Authorizer = spt + dkc.Sender = autorest.CreateSender(withRequestLogging()) + client.diskClient = dkc + ehc := eventhub.NewEventHubsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&ehc.Client) ehc.Authorizer = spt diff --git a/builtin/providers/azurerm/import_arm_disk_test.go b/builtin/providers/azurerm/import_arm_disk_test.go index 35c52c008..9887cffda 100644 --- a/builtin/providers/azurerm/import_arm_disk_test.go +++ b/builtin/providers/azurerm/import_arm_disk_test.go @@ -9,20 +9,20 @@ import ( ) func TestAccAzureRMDisk_importEmpty(t *testing.T) { - runTestAzureRMDisk_import(t, "azurerm_disk.test", testAccAzureRMDisk_emptyDisk) + runTestAzureRMDisk_import(t, "azurerm_disk.test", testAccAzureRMDisk_empty) } -func TestAccAzureRMDisk_importBlob(t *testing.T) { +/*func TestAccAzureRMDisk_importBlob(t *testing.T) { runTestAzureRMDisk_import(t, "azurerm_disk.test", testAccAzureRMDisk_blob) -} +}*/ func runTestAzureRMDisk_import(t *testing.T, resourceName string, configSource string) { ri := acctest.RandInt() - config := fmt.Sprintf(configSource, ri, ri, ri) + config := fmt.Sprintf(configSource, ri, ri) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t)}, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, CheckDestroy: testCheckAzureRMDiskDestroy, Steps: []resource.TestStep{ resource.TestStep{ @@ -30,10 +30,10 @@ func runTestAzureRMDisk_import(t *testing.T, resourceName string, configSource s }, resource.TestStep{ - ResourceName: resourceName, - ImportState: true, + ResourceName: resourceName, + ImportState: true, ImportStateVerify: true, }, }, }) -} \ No newline at end of file +} diff --git a/builtin/providers/azurerm/provider.go b/builtin/providers/azurerm/provider.go index bf02ab83a..a5c37e12a 100644 --- a/builtin/providers/azurerm/provider.go +++ b/builtin/providers/azurerm/provider.go @@ -70,6 +70,8 @@ func Provider() terraform.ResourceProvider { "azurerm_container_registry": resourceArmContainerRegistry(), "azurerm_container_service": resourceArmContainerService(), + "azurerm_disk": resourceArmDisk(), + "azurerm_eventhub": resourceArmEventHub(), "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), diff --git a/builtin/providers/azurerm/resource_arm_disk.go b/builtin/providers/azurerm/resource_arm_disk.go index 1bf1fdf73..dd1065eda 100644 --- a/builtin/providers/azurerm/resource_arm_disk.go +++ b/builtin/providers/azurerm/resource_arm_disk.go @@ -1,13 +1,13 @@ package azurerm import ( + "fmt" "github.com/Azure/azure-sdk-for-go/arm/disk" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" - "fmt" "log" - "strings" "net/http" + "strings" ) func resourceArmDisk() *schema.Resource { @@ -22,7 +22,7 @@ func resourceArmDisk() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, + Type: schema.TypeString, Required: true, ForceNew: true, }, @@ -36,7 +36,7 @@ func resourceArmDisk() *schema.Resource { }, "storage_account_type": { - Type: schema.TypeString, + Type: schema.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{ string(disk.PremiumLRS), @@ -45,7 +45,7 @@ func resourceArmDisk() *schema.Resource { }, "create_option": { - Type: schema.TypeString, + Type: schema.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{ string(disk.Import), @@ -60,7 +60,7 @@ func resourceArmDisk() *schema.Resource { }, "os_type": { - Type: schema.TypeString, + Type: schema.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ string(disk.Windows), @@ -69,9 +69,8 @@ func resourceArmDisk() *schema.Resource { }, "disk_size_gb": { - Type: schema.TypeInt, - Optional: true, - Computed: true, + Type: schema.TypeInt, + Required: true, ValidateFunc: validateDiskSizeGB, }, @@ -101,7 +100,7 @@ func resourceArmDiskCreate(d *schema.ResourceData, meta interface{}) error { tags := d.Get("tags").(map[string]interface{}) expandedTags := expandTags(tags) - createDisk := &disk.Model { + createDisk := disk.Model{ Name: &name, Location: &location, Tags: expandedTags, @@ -109,25 +108,27 @@ func resourceArmDiskCreate(d *schema.ResourceData, meta interface{}) error { storageAccountType := d.Get("storage_account_type").(string) osType := d.Get("os_type").(string) - diskSize := d.Get("disk_size_db").(int) - createDisk.Properties = &disk.Properties { - AccountType: &storageAccountType, - OsType: &osType, - DiskSizeGB: &diskSize, + createDisk.Properties = &disk.Properties{ + AccountType: disk.StorageAccountTypes(storageAccountType), + OsType: disk.OperatingSystemTypes(osType), } + if v := d.Get("disk_size_gb"); v != nil { + diskSize := int32(v.(int)) + createDisk.Properties.DiskSizeGB = &diskSize + } createOption := d.Get("create_option").(string) creationData := &disk.CreationData{ CreateOption: disk.CreateOption(createOption), } - if strings.EqualFold(createOption, disk.Import) { + if strings.EqualFold(createOption, string(disk.Import)) { if vhdUri := d.Get("vhd_uri").(string); vhdUri != "" { - creationData.SourceURI = vhdUri; + creationData.SourceURI = &vhdUri } else { - return nil, fmt.Errorf("[ERROR] vhd_uri must be specified when create_option is `%s`", disk.Import) + return fmt.Errorf("[ERROR] vhd_uri must be specified when create_option is `%s`", disk.Import) } } @@ -139,7 +140,7 @@ func resourceArmDiskCreate(d *schema.ResourceData, meta interface{}) error { } read, err := diskClient.Get(resGroup, name) - if err != nil{ + if err != nil { return err } if read.ID == nil { @@ -222,10 +223,10 @@ func resourceArmDiskDelete(d *schema.ResourceData, meta interface{}) error { func flattenAzureRmDiskProperties(properties *disk.Properties) (map[string]interface{}, error) { result := make(map[string]interface{}) - result["storage_account_type"] = *properties.AccountType + result["storage_account_type"] = string(properties.AccountType) result["disk_size_gb"] = *properties.DiskSizeGB - if properties.OsType != nil { - result["os_type"] = *properties.OsType + if properties.OsType != "" { + result["os_type"] = string(properties.OsType) } return result, nil @@ -233,10 +234,10 @@ func flattenAzureRmDiskProperties(properties *disk.Properties) (map[string]inter func flattenAzureRmDiskCreationData(creationData *disk.CreationData) (map[string]interface{}, error) { result := make(map[string]interface{}) - result["create_option"] = *creationData.CreateOption + result["create_option"] = string(creationData.CreateOption) if creationData.SourceURI != nil { result["vhd_uri"] = *creationData.SourceURI } return result, nil -} \ No newline at end of file +} diff --git a/builtin/providers/azurerm/resource_arm_disk_test.go b/builtin/providers/azurerm/resource_arm_disk_test.go index 96f5b5587..12060ddaf 100644 --- a/builtin/providers/azurerm/resource_arm_disk_test.go +++ b/builtin/providers/azurerm/resource_arm_disk_test.go @@ -1 +1,105 @@ package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/Azure/azure-sdk-for-go/arm/disk" + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMDisk_empty(t *testing.T) { + var d disk.Model + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMDisk_empty, ri, ri) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDiskDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDiskExists("azurerm_disk.test", &d), + ), + }, + }, + }) +} + +func testCheckAzureRMDiskExists(name string, d *disk.Model) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + dName := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for disk: %s", dName) + } + + conn := testAccProvider.Meta().(*ArmClient).diskClient + + resp, err := conn.Get(resourceGroup, dName) + if err != nil { + return fmt.Errorf("Bad: Get on diskClient: %s", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: VirtualMachine %q (resource group %q) does not exist", dName, resourceGroup) + } + + *d = resp + + return nil + } +} + +func testCheckAzureRMDiskDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*ArmClient).diskClient + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_disk" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(resourceGroup, name) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Disk still exists: \n%#v", resp.Properties) + } + } + + return nil +} + +var testAccAzureRMDisk_empty = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_disk" "test" { + name = "acctestd-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "20" + + tags { + environment = "acctest" + } +}` diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/images.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/images.go new file mode 100644 index 000000000..b585467cd --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/compute/images.go @@ -0,0 +1,421 @@ +package compute + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// ImagesClient is the the Compute Management Client. +type ImagesClient struct { + ManagementClient +} + +// NewImagesClient creates an instance of the ImagesClient client. +func NewImagesClient(subscriptionID string) ImagesClient { + return NewImagesClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewImagesClientWithBaseURI creates an instance of the ImagesClient client. +func NewImagesClientWithBaseURI(baseURI string, subscriptionID string) ImagesClient { + return ImagesClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate create or update an image. This method may poll for +// completion. Polling can be canceled by passing the cancel channel argument. +// The channel will be used to cancel polling and any outstanding HTTP +// requests. +// +// resourceGroupName is the name of the resource group. imageName is the name +// of the image. parameters is parameters supplied to the Create Image +// operation. +func (client ImagesClient) CreateOrUpdate(resourceGroupName string, imageName string, parameters Image, cancel <-chan struct{}) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.ImageProperties", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "parameters.ImageProperties.StorageProfile", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "parameters.ImageProperties.StorageProfile.OsDisk", Name: validation.Null, Rule: true, Chain: nil}}}, + }}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "compute.ImagesClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(resourceGroupName, imageName, parameters, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "CreateOrUpdate", nil, "Failure preparing request") + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "CreateOrUpdate", resp, "Failure sending request") + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "compute.ImagesClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ImagesClient) CreateOrUpdatePreparer(resourceGroupName string, imageName string, parameters Image, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "imageName": autorest.Encode("path", imageName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client ImagesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ImagesClient) CreateOrUpdateResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByClosing()) + result.Response = resp + return +} + +// Delete deletes an Image. This method may poll for completion. Polling can be +// canceled by passing the cancel channel argument. The channel will be used to +// cancel polling and any outstanding HTTP requests. +// +// resourceGroupName is the name of the resource group. imageName is the name +// of the image. +func (client ImagesClient) Delete(resourceGroupName string, imageName string, cancel <-chan struct{}) (result autorest.Response, err error) { + req, err := client.DeletePreparer(resourceGroupName, imageName, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "Delete", nil, "Failure preparing request") + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "Delete", resp, "Failure sending request") + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "compute.ImagesClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ImagesClient) DeletePreparer(resourceGroupName string, imageName string, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "imageName": autorest.Encode("path", imageName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client ImagesClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ImagesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets an image. +// +// resourceGroupName is the name of the resource group. imageName is the name +// of the image. expand is the expand expression to apply on the operation. +func (client ImagesClient) Get(resourceGroupName string, imageName string, expand string) (result Image, err error) { + req, err := client.GetPreparer(resourceGroupName, imageName, expand) + if err != nil { + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "Get", nil, "Failure preparing request") + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "Get", resp, "Failure sending request") + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "compute.ImagesClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client ImagesClient) GetPreparer(resourceGroupName string, imageName string, expand string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "imageName": autorest.Encode("path", imageName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ImagesClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ImagesClient) GetResponder(resp *http.Response) (result Image, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List gets the list of Images in the subscription. Use nextLink property in +// the response to get the next page of Images. Do this till nextLink is not +// null to fetch all the Images. +func (client ImagesClient) List() (result ImageListResult, err error) { + req, err := client.ListPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "List", nil, "Failure preparing request") + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "List", resp, "Failure sending request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "compute.ImagesClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client ImagesClient) ListPreparer() (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/images", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client ImagesClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client ImagesClient) ListResponder(resp *http.Response) (result ImageListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListNextResults retrieves the next set of results, if any. +func (client ImagesClient) ListNextResults(lastResults ImageListResult) (result ImageListResult, err error) { + req, err := lastResults.ImageListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "List", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "List", resp, "Failure sending next results request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "compute.ImagesClient", "List", resp, "Failure responding to next results request") + } + + return +} + +// ListByResourceGroup gets the list of images under a resource group. +// +// resourceGroupName is the name of the resource group. +func (client ImagesClient) ListByResourceGroup(resourceGroupName string) (result ImageListResult, err error) { + req, err := client.ListByResourceGroupPreparer(resourceGroupName) + if err != nil { + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "ListByResourceGroup", nil, "Failure preparing request") + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "ListByResourceGroup", resp, "Failure sending request") + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "compute.ImagesClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client ImagesClient) ListByResourceGroupPreparer(resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client ImagesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client ImagesClient) ListByResourceGroupResponder(resp *http.Response) (result ImageListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroupNextResults retrieves the next set of results, if any. +func (client ImagesClient) ListByResourceGroupNextResults(lastResults ImageListResult) (result ImageListResult, err error) { + req, err := lastResults.ImageListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "ListByResourceGroup", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "ListByResourceGroup", resp, "Failure sending next results request") + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "compute.ImagesClient", "ListByResourceGroup", resp, "Failure responding to next results request") + } + + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/client.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/client.go new file mode 100644 index 000000000..d64eb2287 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/client.go @@ -0,0 +1,58 @@ +// Package disk implements the Azure ARM Disk service API version +// 2016-04-30-preview. +// +// The Disk Resource Provider Client. +package disk + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // APIVersion is the version of the Disk + APIVersion = "2016-04-30-preview" + + // DefaultBaseURI is the default URI used for the service Disk + DefaultBaseURI = "https://management.azure.com" +) + +// ManagementClient is the base client for Disk. +type ManagementClient struct { + autorest.Client + BaseURI string + APIVersion string + SubscriptionID string +} + +// New creates an instance of the ManagementClient client. +func New(subscriptionID string) ManagementClient { + return NewWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewWithBaseURI creates an instance of the ManagementClient client. +func NewWithBaseURI(baseURI string, subscriptionID string) ManagementClient { + return ManagementClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + APIVersion: APIVersion, + SubscriptionID: subscriptionID, + } +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/disks.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/disks.go new file mode 100644 index 000000000..6fb03876f --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/disks.go @@ -0,0 +1,638 @@ +package disk + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// DisksClient is the the Disk Resource Provider Client. +type DisksClient struct { + ManagementClient +} + +// NewDisksClient creates an instance of the DisksClient client. +func NewDisksClient(subscriptionID string) DisksClient { + return NewDisksClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewDisksClientWithBaseURI creates an instance of the DisksClient client. +func NewDisksClientWithBaseURI(baseURI string, subscriptionID string) DisksClient { + return DisksClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates or updates a disk. This method may poll for +// completion. Polling can be canceled by passing the cancel channel argument. +// The channel will be used to cancel polling and any outstanding HTTP +// requests. +// +// resourceGroupName is the name of the resource group. diskName is the name of +// the disk within the given subscription and resource group. diskParameter is +// disk object supplied in the body of the Put disk operation. +func (client DisksClient) CreateOrUpdate(resourceGroupName string, diskName string, diskParameter Model, cancel <-chan struct{}) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: diskParameter, + Constraints: []validation.Constraint{{Target: "diskParameter.Properties", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "diskParameter.Properties.CreationData", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "diskParameter.Properties.CreationData.ImageReference", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "diskParameter.Properties.CreationData.ImageReference.ID", Name: validation.Null, Rule: true, Chain: nil}}}, + }}, + {Target: "diskParameter.Properties.EncryptionSettings", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "diskParameter.Properties.EncryptionSettings.DiskEncryptionKey", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "diskParameter.Properties.EncryptionSettings.DiskEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "diskParameter.Properties.EncryptionSettings.DiskEncryptionKey.SecretURL", Name: validation.Null, Rule: true, Chain: nil}, + }}, + {Target: "diskParameter.Properties.EncryptionSettings.KeyEncryptionKey", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "diskParameter.Properties.EncryptionSettings.KeyEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "diskParameter.Properties.EncryptionSettings.KeyEncryptionKey.KeyURL", Name: validation.Null, Rule: true, Chain: nil}, + }}, + }}, + }}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "disk.DisksClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(resourceGroupName, diskName, diskParameter, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "CreateOrUpdate", nil, "Failure preparing request") + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "CreateOrUpdate", resp, "Failure sending request") + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.DisksClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client DisksClient) CreateOrUpdatePreparer(resourceGroupName string, diskName string, diskParameter Model, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "diskName": autorest.Encode("path", diskName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters), + autorest.WithJSON(diskParameter), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client DisksClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client DisksClient) CreateOrUpdateResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// Delete deletes a disk. This method may poll for completion. Polling can be +// canceled by passing the cancel channel argument. The channel will be used to +// cancel polling and any outstanding HTTP requests. +// +// resourceGroupName is the name of the resource group. diskName is the name of +// the disk within the given subscription and resource group. +func (client DisksClient) Delete(resourceGroupName string, diskName string, cancel <-chan struct{}) (result autorest.Response, err error) { + req, err := client.DeletePreparer(resourceGroupName, diskName, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "Delete", nil, "Failure preparing request") + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "Delete", resp, "Failure sending request") + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.DisksClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client DisksClient) DeletePreparer(resourceGroupName string, diskName string, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "diskName": autorest.Encode("path", diskName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client DisksClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client DisksClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets information about a disk. +// +// resourceGroupName is the name of the resource group. diskName is the name of +// the disk within the given subscription and resource group. +func (client DisksClient) Get(resourceGroupName string, diskName string) (result Model, err error) { + req, err := client.GetPreparer(resourceGroupName, diskName) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "Get", nil, "Failure preparing request") + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "Get", resp, "Failure sending request") + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.DisksClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client DisksClient) GetPreparer(resourceGroupName string, diskName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "diskName": autorest.Encode("path", diskName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client DisksClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client DisksClient) GetResponder(resp *http.Response) (result Model, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GrantAccess grants access to a disk. This method may poll for completion. +// Polling can be canceled by passing the cancel channel argument. The channel +// will be used to cancel polling and any outstanding HTTP requests. +// +// resourceGroupName is the name of the resource group. diskName is the name of +// the disk within the given subscription and resource group. grantAccessData +// is access data object supplied in the body of the get disk access operation. +func (client DisksClient) GrantAccess(resourceGroupName string, diskName string, grantAccessData GrantAccessData, cancel <-chan struct{}) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: grantAccessData, + Constraints: []validation.Constraint{{Target: "grantAccessData.DurationInSeconds", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "disk.DisksClient", "GrantAccess") + } + + req, err := client.GrantAccessPreparer(resourceGroupName, diskName, grantAccessData, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "GrantAccess", nil, "Failure preparing request") + } + + resp, err := client.GrantAccessSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "GrantAccess", resp, "Failure sending request") + } + + result, err = client.GrantAccessResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.DisksClient", "GrantAccess", resp, "Failure responding to request") + } + + return +} + +// GrantAccessPreparer prepares the GrantAccess request. +func (client DisksClient) GrantAccessPreparer(resourceGroupName string, diskName string, grantAccessData GrantAccessData, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "diskName": autorest.Encode("path", diskName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}/beginGetAccess", pathParameters), + autorest.WithJSON(grantAccessData), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// GrantAccessSender sends the GrantAccess request. The method will close the +// http.Response Body if it receives an error. +func (client DisksClient) GrantAccessSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// GrantAccessResponder handles the response to the GrantAccess request. The method always +// closes the http.Response Body. +func (client DisksClient) GrantAccessResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// List lists all the disks under a subscription. +func (client DisksClient) List() (result ListType, err error) { + req, err := client.ListPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "List", nil, "Failure preparing request") + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "List", resp, "Failure sending request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.DisksClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client DisksClient) ListPreparer() (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/disks", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client DisksClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client DisksClient) ListResponder(resp *http.Response) (result ListType, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListNextResults retrieves the next set of results, if any. +func (client DisksClient) ListNextResults(lastResults ListType) (result ListType, err error) { + req, err := lastResults.ListTypePreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "List", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "List", resp, "Failure sending next results request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.DisksClient", "List", resp, "Failure responding to next results request") + } + + return +} + +// ListByResourceGroup lists all the disks under a resource group. +// +// resourceGroupName is the name of the resource group. +func (client DisksClient) ListByResourceGroup(resourceGroupName string) (result ListType, err error) { + req, err := client.ListByResourceGroupPreparer(resourceGroupName) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "ListByResourceGroup", nil, "Failure preparing request") + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "ListByResourceGroup", resp, "Failure sending request") + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.DisksClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client DisksClient) ListByResourceGroupPreparer(resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client DisksClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client DisksClient) ListByResourceGroupResponder(resp *http.Response) (result ListType, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroupNextResults retrieves the next set of results, if any. +func (client DisksClient) ListByResourceGroupNextResults(lastResults ListType) (result ListType, err error) { + req, err := lastResults.ListTypePreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "ListByResourceGroup", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "ListByResourceGroup", resp, "Failure sending next results request") + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.DisksClient", "ListByResourceGroup", resp, "Failure responding to next results request") + } + + return +} + +// RevokeAccess revokes access to a disk. This method may poll for completion. +// Polling can be canceled by passing the cancel channel argument. The channel +// will be used to cancel polling and any outstanding HTTP requests. +// +// resourceGroupName is the name of the resource group. diskName is the name of +// the disk within the given subscription and resource group. +func (client DisksClient) RevokeAccess(resourceGroupName string, diskName string, cancel <-chan struct{}) (result autorest.Response, err error) { + req, err := client.RevokeAccessPreparer(resourceGroupName, diskName, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "RevokeAccess", nil, "Failure preparing request") + } + + resp, err := client.RevokeAccessSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "RevokeAccess", resp, "Failure sending request") + } + + result, err = client.RevokeAccessResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.DisksClient", "RevokeAccess", resp, "Failure responding to request") + } + + return +} + +// RevokeAccessPreparer prepares the RevokeAccess request. +func (client DisksClient) RevokeAccessPreparer(resourceGroupName string, diskName string, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "diskName": autorest.Encode("path", diskName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}/endGetAccess", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// RevokeAccessSender sends the RevokeAccess request. The method will close the +// http.Response Body if it receives an error. +func (client DisksClient) RevokeAccessSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// RevokeAccessResponder handles the response to the RevokeAccess request. The method always +// closes the http.Response Body. +func (client DisksClient) RevokeAccessResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update updates (patches) a disk. This method may poll for completion. +// Polling can be canceled by passing the cancel channel argument. The channel +// will be used to cancel polling and any outstanding HTTP requests. +// +// resourceGroupName is the name of the resource group. diskName is the name of +// the disk within the given subscription and resource group. diskParameter is +// disk object supplied in the body of the Patch disk operation. +func (client DisksClient) Update(resourceGroupName string, diskName string, diskParameter UpdateType, cancel <-chan struct{}) (result autorest.Response, err error) { + req, err := client.UpdatePreparer(resourceGroupName, diskName, diskParameter, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "Update", nil, "Failure preparing request") + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "disk.DisksClient", "Update", resp, "Failure sending request") + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.DisksClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client DisksClient) UpdatePreparer(resourceGroupName string, diskName string, diskParameter UpdateType, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "diskName": autorest.Encode("path", diskName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters), + autorest.WithJSON(diskParameter), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client DisksClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client DisksClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/models.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/models.go new file mode 100644 index 000000000..e8118696a --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/models.go @@ -0,0 +1,278 @@ +package disk + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/to" + "net/http" +) + +// AccessLevel enumerates the values for access level. +type AccessLevel string + +const ( + // None specifies the none state for access level. + None AccessLevel = "None" + // Read specifies the read state for access level. + Read AccessLevel = "Read" +) + +// CreateOption enumerates the values for create option. +type CreateOption string + +const ( + // Attach specifies the attach state for create option. + Attach CreateOption = "Attach" + // Copy specifies the copy state for create option. + Copy CreateOption = "Copy" + // Empty specifies the empty state for create option. + Empty CreateOption = "Empty" + // FromImage specifies the from image state for create option. + FromImage CreateOption = "FromImage" + // Import specifies the import state for create option. + Import CreateOption = "Import" + // Restore specifies the restore state for create option. + Restore CreateOption = "Restore" +) + +// OperatingSystemTypes enumerates the values for operating system types. +type OperatingSystemTypes string + +const ( + // Linux specifies the linux state for operating system types. + Linux OperatingSystemTypes = "Linux" + // Windows specifies the windows state for operating system types. + Windows OperatingSystemTypes = "Windows" +) + +// StorageAccountTypes enumerates the values for storage account types. +type StorageAccountTypes string + +const ( + // PremiumLRS specifies the premium lrs state for storage account types. + PremiumLRS StorageAccountTypes = "Premium_LRS" + // StandardLRS specifies the standard lrs state for storage account types. + StandardLRS StorageAccountTypes = "Standard_LRS" +) + +// AccessURI is a disk access SAS uri. +type AccessURI struct { + autorest.Response `json:"-"` + *AccessURIOutput `json:"properties,omitempty"` +} + +// AccessURIOutput is azure properties, including output. +type AccessURIOutput struct { + *AccessURIRaw `json:"output,omitempty"` +} + +// AccessURIRaw is this object gets 'bubbled up' through flattening. +type AccessURIRaw struct { + AccessSAS *string `json:"accessSAS,omitempty"` +} + +// APIError is api error. +type APIError struct { + Details *[]APIErrorBase `json:"details,omitempty"` + Innererror *InnerError `json:"innererror,omitempty"` + Code *string `json:"code,omitempty"` + Target *string `json:"target,omitempty"` + Message *string `json:"message,omitempty"` +} + +// APIErrorBase is api error base. +type APIErrorBase struct { + Code *string `json:"code,omitempty"` + Target *string `json:"target,omitempty"` + Message *string `json:"message,omitempty"` +} + +// CreationData is data used when creating a disk. +type CreationData struct { + CreateOption CreateOption `json:"createOption,omitempty"` + StorageAccountID *string `json:"storageAccountId,omitempty"` + ImageReference *ImageDiskReference `json:"imageReference,omitempty"` + SourceURI *string `json:"sourceUri,omitempty"` + SourceResourceID *string `json:"sourceResourceId,omitempty"` +} + +// EncryptionSettings is encryption settings for disk or snapshot +type EncryptionSettings struct { + Enabled *bool `json:"enabled,omitempty"` + DiskEncryptionKey *KeyVaultAndSecretReference `json:"diskEncryptionKey,omitempty"` + KeyEncryptionKey *KeyVaultAndKeyReference `json:"keyEncryptionKey,omitempty"` +} + +// GrantAccessData is data used for requesting a SAS. +type GrantAccessData struct { + Access AccessLevel `json:"access,omitempty"` + DurationInSeconds *int32 `json:"durationInSeconds,omitempty"` +} + +// ImageDiskReference is the source image used for creating the disk. +type ImageDiskReference struct { + ID *string `json:"id,omitempty"` + Lun *int32 `json:"lun,omitempty"` +} + +// InnerError is inner error details. +type InnerError struct { + Exceptiontype *string `json:"exceptiontype,omitempty"` + Errordetail *string `json:"errordetail,omitempty"` +} + +// KeyVaultAndKeyReference is key Vault Key Url and vault id of KeK, KeK is +// optional and when provided is used to unwrap the encryptionKey +type KeyVaultAndKeyReference struct { + SourceVault *SourceVault `json:"sourceVault,omitempty"` + KeyURL *string `json:"keyUrl,omitempty"` +} + +// KeyVaultAndSecretReference is key Vault Secret Url and vault id of the +// encryption key +type KeyVaultAndSecretReference struct { + SourceVault *SourceVault `json:"sourceVault,omitempty"` + SecretURL *string `json:"secretUrl,omitempty"` +} + +// ListType is the List Disks operation response. +type ListType struct { + autorest.Response `json:"-"` + Value *[]Model `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// ListTypePreparer prepares a request to retrieve the next set of results. It returns +// nil if no more results exist. +func (client ListType) ListTypePreparer() (*http.Request, error) { + if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(client.NextLink))) +} + +// Model is disk resource. +type Model struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` + *Properties `json:"properties,omitempty"` +} + +// OperationStatusResponse is operation status response +type OperationStatusResponse struct { + autorest.Response `json:"-"` + Name *string `json:"name,omitempty"` + Status *string `json:"status,omitempty"` + StartTime *date.Time `json:"startTime,omitempty"` + EndTime *date.Time `json:"endTime,omitempty"` + Error *APIError `json:"error,omitempty"` +} + +// Properties is disk resource properties. +type Properties struct { + AccountType StorageAccountTypes `json:"accountType,omitempty"` + TimeCreated *date.Time `json:"timeCreated,omitempty"` + OsType OperatingSystemTypes `json:"osType,omitempty"` + CreationData *CreationData `json:"creationData,omitempty"` + DiskSizeGB *int32 `json:"diskSizeGB,omitempty"` + EncryptionSettings *EncryptionSettings `json:"encryptionSettings,omitempty"` + OwnerID *string `json:"ownerId,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} + +// Resource is the Resource model definition. +type Resource struct { + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` +} + +// ResourceUpdate is the Resource model definition. +type ResourceUpdate struct { + Tags *map[string]*string `json:"tags,omitempty"` +} + +// Snapshot is snapshot resource. +type Snapshot struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` + *Properties `json:"properties,omitempty"` +} + +// SnapshotList is the List Snapshots operation response. +type SnapshotList struct { + autorest.Response `json:"-"` + Value *[]Snapshot `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// SnapshotListPreparer prepares a request to retrieve the next set of results. It returns +// nil if no more results exist. +func (client SnapshotList) SnapshotListPreparer() (*http.Request, error) { + if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(client.NextLink))) +} + +// SnapshotUpdate is snapshot update resource. +type SnapshotUpdate struct { + Tags *map[string]*string `json:"tags,omitempty"` + *UpdateProperties `json:"properties,omitempty"` +} + +// SourceVault is the vault id is an Azure Resource Manager Resoure id in the +// form +// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName} +type SourceVault struct { + ID *string `json:"id,omitempty"` +} + +// UpdateProperties is disk resource update properties. +type UpdateProperties struct { + AccountType StorageAccountTypes `json:"accountType,omitempty"` + OsType OperatingSystemTypes `json:"osType,omitempty"` + CreationData *CreationData `json:"creationData,omitempty"` + DiskSizeGB *int32 `json:"diskSizeGB,omitempty"` + EncryptionSettings *EncryptionSettings `json:"encryptionSettings,omitempty"` +} + +// UpdateType is disk update resource. +type UpdateType struct { + Tags *map[string]*string `json:"tags,omitempty"` + *UpdateProperties `json:"properties,omitempty"` +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/snapshots.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/snapshots.go new file mode 100644 index 000000000..20e6ec758 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/snapshots.go @@ -0,0 +1,643 @@ +package disk + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// SnapshotsClient is the the Disk Resource Provider Client. +type SnapshotsClient struct { + ManagementClient +} + +// NewSnapshotsClient creates an instance of the SnapshotsClient client. +func NewSnapshotsClient(subscriptionID string) SnapshotsClient { + return NewSnapshotsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewSnapshotsClientWithBaseURI creates an instance of the SnapshotsClient +// client. +func NewSnapshotsClientWithBaseURI(baseURI string, subscriptionID string) SnapshotsClient { + return SnapshotsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates or updates a snapshot. This method may poll for +// completion. Polling can be canceled by passing the cancel channel argument. +// The channel will be used to cancel polling and any outstanding HTTP +// requests. +// +// resourceGroupName is the name of the resource group. snapshotName is the +// name of the snapshot within the given subscription and resource group. +// snapshot is snapshot object supplied in the body of the Put disk operation. +func (client SnapshotsClient) CreateOrUpdate(resourceGroupName string, snapshotName string, snapshot Snapshot, cancel <-chan struct{}) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: snapshot, + Constraints: []validation.Constraint{{Target: "snapshot.Properties", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "snapshot.Properties.CreationData", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "snapshot.Properties.CreationData.ImageReference", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "snapshot.Properties.CreationData.ImageReference.ID", Name: validation.Null, Rule: true, Chain: nil}}}, + }}, + {Target: "snapshot.Properties.EncryptionSettings", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "snapshot.Properties.EncryptionSettings.DiskEncryptionKey", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "snapshot.Properties.EncryptionSettings.DiskEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "snapshot.Properties.EncryptionSettings.DiskEncryptionKey.SecretURL", Name: validation.Null, Rule: true, Chain: nil}, + }}, + {Target: "snapshot.Properties.EncryptionSettings.KeyEncryptionKey", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "snapshot.Properties.EncryptionSettings.KeyEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "snapshot.Properties.EncryptionSettings.KeyEncryptionKey.KeyURL", Name: validation.Null, Rule: true, Chain: nil}, + }}, + }}, + }}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "disk.SnapshotsClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(resourceGroupName, snapshotName, snapshot, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "CreateOrUpdate", nil, "Failure preparing request") + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "CreateOrUpdate", resp, "Failure sending request") + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.SnapshotsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client SnapshotsClient) CreateOrUpdatePreparer(resourceGroupName string, snapshotName string, snapshot Snapshot, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "snapshotName": autorest.Encode("path", snapshotName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), + autorest.WithJSON(snapshot), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client SnapshotsClient) CreateOrUpdateResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// Delete deletes a snapshot. This method may poll for completion. Polling can +// be canceled by passing the cancel channel argument. The channel will be used +// to cancel polling and any outstanding HTTP requests. +// +// resourceGroupName is the name of the resource group. snapshotName is the +// name of the snapshot within the given subscription and resource group. +func (client SnapshotsClient) Delete(resourceGroupName string, snapshotName string, cancel <-chan struct{}) (result autorest.Response, err error) { + req, err := client.DeletePreparer(resourceGroupName, snapshotName, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "Delete", nil, "Failure preparing request") + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "Delete", resp, "Failure sending request") + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.SnapshotsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client SnapshotsClient) DeletePreparer(resourceGroupName string, snapshotName string, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "snapshotName": autorest.Encode("path", snapshotName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client SnapshotsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets information about a snapshot. +// +// resourceGroupName is the name of the resource group. snapshotName is the +// name of the snapshot within the given subscription and resource group. +func (client SnapshotsClient) Get(resourceGroupName string, snapshotName string) (result Snapshot, err error) { + req, err := client.GetPreparer(resourceGroupName, snapshotName) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "Get", nil, "Failure preparing request") + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "Get", resp, "Failure sending request") + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.SnapshotsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client SnapshotsClient) GetPreparer(resourceGroupName string, snapshotName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "snapshotName": autorest.Encode("path", snapshotName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client SnapshotsClient) GetResponder(resp *http.Response) (result Snapshot, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GrantAccess grants access to a snapshot. This method may poll for +// completion. Polling can be canceled by passing the cancel channel argument. +// The channel will be used to cancel polling and any outstanding HTTP +// requests. +// +// resourceGroupName is the name of the resource group. snapshotName is the +// name of the snapshot within the given subscription and resource group. +// grantAccessData is access data object supplied in the body of the get +// snapshot access operation. +func (client SnapshotsClient) GrantAccess(resourceGroupName string, snapshotName string, grantAccessData GrantAccessData, cancel <-chan struct{}) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: grantAccessData, + Constraints: []validation.Constraint{{Target: "grantAccessData.DurationInSeconds", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "disk.SnapshotsClient", "GrantAccess") + } + + req, err := client.GrantAccessPreparer(resourceGroupName, snapshotName, grantAccessData, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "GrantAccess", nil, "Failure preparing request") + } + + resp, err := client.GrantAccessSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "GrantAccess", resp, "Failure sending request") + } + + result, err = client.GrantAccessResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.SnapshotsClient", "GrantAccess", resp, "Failure responding to request") + } + + return +} + +// GrantAccessPreparer prepares the GrantAccess request. +func (client SnapshotsClient) GrantAccessPreparer(resourceGroupName string, snapshotName string, grantAccessData GrantAccessData, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "snapshotName": autorest.Encode("path", snapshotName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}/beginGetAccess", pathParameters), + autorest.WithJSON(grantAccessData), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// GrantAccessSender sends the GrantAccess request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotsClient) GrantAccessSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// GrantAccessResponder handles the response to the GrantAccess request. The method always +// closes the http.Response Body. +func (client SnapshotsClient) GrantAccessResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// List lists snapshots under a subscription. +func (client SnapshotsClient) List() (result SnapshotList, err error) { + req, err := client.ListPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "List", nil, "Failure preparing request") + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "List", resp, "Failure sending request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.SnapshotsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client SnapshotsClient) ListPreparer() (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/snapshots", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client SnapshotsClient) ListResponder(resp *http.Response) (result SnapshotList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListNextResults retrieves the next set of results, if any. +func (client SnapshotsClient) ListNextResults(lastResults SnapshotList) (result SnapshotList, err error) { + req, err := lastResults.SnapshotListPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "List", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "List", resp, "Failure sending next results request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.SnapshotsClient", "List", resp, "Failure responding to next results request") + } + + return +} + +// ListByResourceGroup lists snapshots under a resource group. +// +// resourceGroupName is the name of the resource group. +func (client SnapshotsClient) ListByResourceGroup(resourceGroupName string) (result SnapshotList, err error) { + req, err := client.ListByResourceGroupPreparer(resourceGroupName) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "ListByResourceGroup", nil, "Failure preparing request") + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "ListByResourceGroup", resp, "Failure sending request") + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.SnapshotsClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client SnapshotsClient) ListByResourceGroupPreparer(resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client SnapshotsClient) ListByResourceGroupResponder(resp *http.Response) (result SnapshotList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroupNextResults retrieves the next set of results, if any. +func (client SnapshotsClient) ListByResourceGroupNextResults(lastResults SnapshotList) (result SnapshotList, err error) { + req, err := lastResults.SnapshotListPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "ListByResourceGroup", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "ListByResourceGroup", resp, "Failure sending next results request") + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.SnapshotsClient", "ListByResourceGroup", resp, "Failure responding to next results request") + } + + return +} + +// RevokeAccess revokes access to a snapshot. This method may poll for +// completion. Polling can be canceled by passing the cancel channel argument. +// The channel will be used to cancel polling and any outstanding HTTP +// requests. +// +// resourceGroupName is the name of the resource group. snapshotName is the +// name of the snapshot within the given subscription and resource group. +func (client SnapshotsClient) RevokeAccess(resourceGroupName string, snapshotName string, cancel <-chan struct{}) (result autorest.Response, err error) { + req, err := client.RevokeAccessPreparer(resourceGroupName, snapshotName, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "RevokeAccess", nil, "Failure preparing request") + } + + resp, err := client.RevokeAccessSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "RevokeAccess", resp, "Failure sending request") + } + + result, err = client.RevokeAccessResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.SnapshotsClient", "RevokeAccess", resp, "Failure responding to request") + } + + return +} + +// RevokeAccessPreparer prepares the RevokeAccess request. +func (client SnapshotsClient) RevokeAccessPreparer(resourceGroupName string, snapshotName string, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "snapshotName": autorest.Encode("path", snapshotName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}/endGetAccess", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// RevokeAccessSender sends the RevokeAccess request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotsClient) RevokeAccessSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// RevokeAccessResponder handles the response to the RevokeAccess request. The method always +// closes the http.Response Body. +func (client SnapshotsClient) RevokeAccessResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update updates (patches) a snapshot. This method may poll for completion. +// Polling can be canceled by passing the cancel channel argument. The channel +// will be used to cancel polling and any outstanding HTTP requests. +// +// resourceGroupName is the name of the resource group. snapshotName is the +// name of the snapshot within the given subscription and resource group. +// snapshot is snapshot object supplied in the body of the Patch snapshot +// operation. +func (client SnapshotsClient) Update(resourceGroupName string, snapshotName string, snapshot SnapshotUpdate, cancel <-chan struct{}) (result autorest.Response, err error) { + req, err := client.UpdatePreparer(resourceGroupName, snapshotName, snapshot, cancel) + if err != nil { + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "Update", nil, "Failure preparing request") + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = resp + return result, autorest.NewErrorWithError(err, "disk.SnapshotsClient", "Update", resp, "Failure sending request") + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "disk.SnapshotsClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client SnapshotsClient) UpdatePreparer(resourceGroupName string, snapshotName string, snapshot SnapshotUpdate, cancel <-chan struct{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "snapshotName": autorest.Encode("path", snapshotName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + queryParameters := map[string]interface{}{ + "api-version": client.APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), + autorest.WithJSON(snapshot), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{Cancel: cancel}) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, + req, + azure.DoPollForAsynchronous(client.PollingDelay)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client SnapshotsClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/version.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/version.go new file mode 100644 index 000000000..9b5497d54 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/disk/version.go @@ -0,0 +1,60 @@ +package disk + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "bytes" + "fmt" + "strings" +) + +const ( + major = "8" + minor = "1" + patch = "0" + tag = "beta" + userAgentFormat = "Azure-SDK-For-Go/%s arm-%s/%s" +) + +// cached results of UserAgent and Version to prevent repeated operations. +var ( + userAgent string + version string +) + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + if userAgent == "" { + userAgent = fmt.Sprintf(userAgentFormat, Version(), "disk", "2016-04-30-preview") + } + return userAgent +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + if version == "" { + versionBuilder := bytes.NewBufferString(fmt.Sprintf("%s.%s.%s", major, minor, patch)) + if tag != "" { + versionBuilder.WriteRune('-') + versionBuilder.WriteString(strings.TrimPrefix(tag, "-")) + } + version = string(versionBuilder.Bytes()) + } + return version +} From fc3efec0c9fd195ddab4684e2ff97b5a4b6fef24 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Fri, 3 Mar 2017 14:32:16 -0800 Subject: [PATCH 013/107] fmt --- builtin/providers/azurerm/resource_arm_virtual_machine.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index d12c9f70c..0d79a9285 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -240,9 +240,9 @@ func resourceArmVirtualMachine() *schema.Resource { }, "disk_size_gb": { - Type: schema.TypeInt, - Optional: true, - Computed: true, + Type: schema.TypeInt, + Optional: true, + Computed: true, ValidateFunc: validateDiskSizeGB, }, From ca6bc8823c8fbe4a35aadb51b60f135ccc927f40 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Fri, 3 Mar 2017 14:46:33 -0800 Subject: [PATCH 014/107] renamed arm_disk to arm_managed_disk --- ...est.go => import_arm_managed_disk_test.go} | 12 +++---- builtin/providers/azurerm/provider.go | 4 +-- ...m_disk.go => resource_arm_managed_disk.go} | 34 +++++++++---------- ...t.go => resource_arm_managed_disk_test.go} | 22 ++++++------ 4 files changed, 36 insertions(+), 36 deletions(-) rename builtin/providers/azurerm/{import_arm_disk_test.go => import_arm_managed_disk_test.go} (55%) rename builtin/providers/azurerm/{resource_arm_disk.go => resource_arm_managed_disk.go} (80%) rename builtin/providers/azurerm/{resource_arm_disk_test.go => resource_arm_managed_disk_test.go} (73%) diff --git a/builtin/providers/azurerm/import_arm_disk_test.go b/builtin/providers/azurerm/import_arm_managed_disk_test.go similarity index 55% rename from builtin/providers/azurerm/import_arm_disk_test.go rename to builtin/providers/azurerm/import_arm_managed_disk_test.go index 9887cffda..2dcf72441 100644 --- a/builtin/providers/azurerm/import_arm_disk_test.go +++ b/builtin/providers/azurerm/import_arm_managed_disk_test.go @@ -8,22 +8,22 @@ import ( "github.com/hashicorp/terraform/helper/resource" ) -func TestAccAzureRMDisk_importEmpty(t *testing.T) { - runTestAzureRMDisk_import(t, "azurerm_disk.test", testAccAzureRMDisk_empty) +func TestAccAzureRMManagedDisk_importEmpty(t *testing.T) { + runTestAzureRMManagedDisk_import(t, "azurerm_disk.test", testAccAzureRMManagedDisk_empty) } -/*func TestAccAzureRMDisk_importBlob(t *testing.T) { - runTestAzureRMDisk_import(t, "azurerm_disk.test", testAccAzureRMDisk_blob) +/*func TestAccAzureRMManagedDisk_importBlob(t *testing.T) { + runTestAzureRMManagedDisk_import(t, "azurerm_disk.test", testAccAzureRMManagedDisk_blob) }*/ -func runTestAzureRMDisk_import(t *testing.T, resourceName string, configSource string) { +func runTestAzureRMManagedDisk_import(t *testing.T, resourceName string, configSource string) { ri := acctest.RandInt() config := fmt.Sprintf(configSource, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMDiskDestroy, + CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: config, diff --git a/builtin/providers/azurerm/provider.go b/builtin/providers/azurerm/provider.go index a5c37e12a..5f9e91581 100644 --- a/builtin/providers/azurerm/provider.go +++ b/builtin/providers/azurerm/provider.go @@ -70,8 +70,6 @@ func Provider() terraform.ResourceProvider { "azurerm_container_registry": resourceArmContainerRegistry(), "azurerm_container_service": resourceArmContainerService(), - "azurerm_disk": resourceArmDisk(), - "azurerm_eventhub": resourceArmEventHub(), "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), @@ -84,6 +82,8 @@ func Provider() terraform.ResourceProvider { "azurerm_lb_probe": resourceArmLoadBalancerProbe(), "azurerm_lb_rule": resourceArmLoadBalancerRule(), + "azurerm_managed_disk": resourceArmManagedDisk(), + "azurerm_key_vault": resourceArmKeyVault(), "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), "azurerm_network_interface": resourceArmNetworkInterface(), diff --git a/builtin/providers/azurerm/resource_arm_disk.go b/builtin/providers/azurerm/resource_arm_managed_disk.go similarity index 80% rename from builtin/providers/azurerm/resource_arm_disk.go rename to builtin/providers/azurerm/resource_arm_managed_disk.go index dd1065eda..01fc42782 100644 --- a/builtin/providers/azurerm/resource_arm_disk.go +++ b/builtin/providers/azurerm/resource_arm_managed_disk.go @@ -10,12 +10,12 @@ import ( "strings" ) -func resourceArmDisk() *schema.Resource { +func resourceArmManagedDisk() *schema.Resource { return &schema.Resource{ - Create: resourceArmDiskCreate, - Read: resourceArmDiskRead, - Update: resourceArmDiskCreate, - Delete: resourceArmDiskDelete, + Create: resourceArmManagedDiskCreate, + Read: resourceArmManagedDiskRead, + Update: resourceArmManagedDiskCreate, + Delete: resourceArmManagedDiskDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -88,11 +88,11 @@ func validateDiskSizeGB(v interface{}, k string) (ws []string, errors []error) { return } -func resourceArmDiskCreate(d *schema.ResourceData, meta interface{}) error { +func resourceArmManagedDiskCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient) diskClient := client.diskClient - log.Printf("[INFO] preparing arguments for Azure ARM Disk creation.") + log.Printf("[INFO] preparing arguments for Azure ARM Managed Disk creation.") name := d.Get("name").(string) location := d.Get("location").(string) @@ -144,15 +144,15 @@ func resourceArmDiskCreate(d *schema.ResourceData, meta interface{}) error { return err } if read.ID == nil { - return fmt.Errorf("[ERROR] Cannot read Disk %s (resource group %s) ID", name, resGroup) + return fmt.Errorf("[ERROR] Cannot read Managed Disk %s (resource group %s) ID", name, resGroup) } d.SetId(*read.ID) - return resourceArmDiskRead(d, meta) + return resourceArmManagedDiskRead(d, meta) } -func resourceArmDiskRead(d *schema.ResourceData, meta interface{}) error { +func resourceArmManagedDiskRead(d *schema.ResourceData, meta interface{}) error { diskClient := meta.(*ArmClient).diskClient id, err := parseAzureResourceID(d.Id()) @@ -168,7 +168,7 @@ func resourceArmDiskRead(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } - return fmt.Errorf("[ERROR] Error making Read request on Azure Disk %s (resource group %s): %s", name, resGroup, err) + return fmt.Errorf("[ERROR] Error making Read request on Azure Managed Disk %s (resource group %s): %s", name, resGroup, err) } d.Set("name", resp.Name) @@ -176,7 +176,7 @@ func resourceArmDiskRead(d *schema.ResourceData, meta interface{}) error { d.Set("location", resp.Location) if resp.Properties != nil { - if m, err := flattenAzureRmDiskProperties(resp.Properties); err != nil { + if m, err := flattenAzureRmManagedDiskProperties(resp.Properties); err != nil { return fmt.Errorf("[DEBUG] Error setting disk properties: %#v", err) } else { d.Set("storage_account_type", m["storage_account_type"]) @@ -189,8 +189,8 @@ func resourceArmDiskRead(d *schema.ResourceData, meta interface{}) error { } if resp.CreationData != nil { - if m, err := flattenAzureRmDiskCreationData(resp.CreationData); err != nil { - return fmt.Errorf("[DEBUG] Error setting disk creation data: %#v", err) + if m, err := flattenAzureRmManagedDiskCreationData(resp.CreationData); err != nil { + return fmt.Errorf("[DEBUG] Error setting managed disk creation data: %#v", err) } else { d.Set("create_option", m["create_option"]) if m["vhd_uri"] != nil { @@ -204,7 +204,7 @@ func resourceArmDiskRead(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceArmDiskDelete(d *schema.ResourceData, meta interface{}) error { +func resourceArmManagedDiskDelete(d *schema.ResourceData, meta interface{}) error { diskClient := meta.(*ArmClient).diskClient id, err := parseAzureResourceID(d.Id()) @@ -221,7 +221,7 @@ func resourceArmDiskDelete(d *schema.ResourceData, meta interface{}) error { return nil } -func flattenAzureRmDiskProperties(properties *disk.Properties) (map[string]interface{}, error) { +func flattenAzureRmManagedDiskProperties(properties *disk.Properties) (map[string]interface{}, error) { result := make(map[string]interface{}) result["storage_account_type"] = string(properties.AccountType) result["disk_size_gb"] = *properties.DiskSizeGB @@ -232,7 +232,7 @@ func flattenAzureRmDiskProperties(properties *disk.Properties) (map[string]inter return result, nil } -func flattenAzureRmDiskCreationData(creationData *disk.CreationData) (map[string]interface{}, error) { +func flattenAzureRmManagedDiskCreationData(creationData *disk.CreationData) (map[string]interface{}, error) { result := make(map[string]interface{}) result["create_option"] = string(creationData.CreateOption) if creationData.SourceURI != nil { diff --git a/builtin/providers/azurerm/resource_arm_disk_test.go b/builtin/providers/azurerm/resource_arm_managed_disk_test.go similarity index 73% rename from builtin/providers/azurerm/resource_arm_disk_test.go rename to builtin/providers/azurerm/resource_arm_managed_disk_test.go index 12060ddaf..69472bfae 100644 --- a/builtin/providers/azurerm/resource_arm_disk_test.go +++ b/builtin/providers/azurerm/resource_arm_managed_disk_test.go @@ -11,26 +11,26 @@ import ( "github.com/hashicorp/terraform/terraform" ) -func TestAccAzureRMDisk_empty(t *testing.T) { +func TestAccAzureRMManagedDisk_empty(t *testing.T) { var d disk.Model ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMDisk_empty, ri, ri) + config := fmt.Sprintf(testAccAzureRMManagedDisk_empty, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMDiskDestroy, + CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDiskExists("azurerm_disk.test", &d), + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d), ), }, }, }) } -func testCheckAzureRMDiskExists(name string, d *disk.Model) resource.TestCheckFunc { +func testCheckAzureRMManagedDiskExists(name string, d *disk.Model) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -51,7 +51,7 @@ func testCheckAzureRMDiskExists(name string, d *disk.Model) resource.TestCheckFu } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: VirtualMachine %q (resource group %q) does not exist", dName, resourceGroup) + return fmt.Errorf("Bad: ManagedDisk %q (resource group %q) does not exist", dName, resourceGroup) } *d = resp @@ -60,11 +60,11 @@ func testCheckAzureRMDiskExists(name string, d *disk.Model) resource.TestCheckFu } } -func testCheckAzureRMDiskDestroy(s *terraform.State) error { +func testCheckAzureRMManagedDiskDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*ArmClient).diskClient for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_disk" { + if rs.Type != "azurerm_managed_disk" { continue } @@ -78,20 +78,20 @@ func testCheckAzureRMDiskDestroy(s *terraform.State) error { } if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Disk still exists: \n%#v", resp.Properties) + return fmt.Errorf("Managed Disk still exists: \n%#v", resp.Properties) } } return nil } -var testAccAzureRMDisk_empty = ` +var testAccAzureRMManagedDisk_empty = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US 2" } -resource "azurerm_disk" "test" { +resource "azurerm_managed_disk" "test" { name = "acctestd-%d" location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" From 9158b9573663d2391d7315994924a0543e8a8ef4 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Fri, 3 Mar 2017 18:15:05 -0800 Subject: [PATCH 015/107] managed disk acceptance tests --- .../azurerm/import_arm_managed_disk_test.go | 17 +- .../azurerm/resource_arm_managed_disk.go | 19 ++- .../azurerm/resource_arm_managed_disk_test.go | 158 ++++++++++++++++++ 3 files changed, 172 insertions(+), 22 deletions(-) diff --git a/builtin/providers/azurerm/import_arm_managed_disk_test.go b/builtin/providers/azurerm/import_arm_managed_disk_test.go index 2dcf72441..51eaa6abd 100644 --- a/builtin/providers/azurerm/import_arm_managed_disk_test.go +++ b/builtin/providers/azurerm/import_arm_managed_disk_test.go @@ -9,28 +9,19 @@ import ( ) func TestAccAzureRMManagedDisk_importEmpty(t *testing.T) { - runTestAzureRMManagedDisk_import(t, "azurerm_disk.test", testAccAzureRMManagedDisk_empty) -} - -/*func TestAccAzureRMManagedDisk_importBlob(t *testing.T) { - runTestAzureRMManagedDisk_import(t, "azurerm_disk.test", testAccAzureRMManagedDisk_blob) -}*/ - -func runTestAzureRMManagedDisk_import(t *testing.T, resourceName string, configSource string) { ri := acctest.RandInt() - config := fmt.Sprintf(configSource, ri, ri) + config := fmt.Sprintf(testAccAzureRMManagedDisk_empty, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, }, - - resource.TestStep{ - ResourceName: resourceName, + { + ResourceName: "azurerm_managed_disk.test", ImportState: true, ImportStateVerify: true, }, diff --git a/builtin/providers/azurerm/resource_arm_managed_disk.go b/builtin/providers/azurerm/resource_arm_managed_disk.go index 01fc42782..811ce81e8 100644 --- a/builtin/providers/azurerm/resource_arm_managed_disk.go +++ b/builtin/providers/azurerm/resource_arm_managed_disk.go @@ -50,10 +50,11 @@ func resourceArmManagedDisk() *schema.Resource { ValidateFunc: validation.StringInSlice([]string{ string(disk.Import), string(disk.Empty), + //todo: add support for snapshots as a source (disk.Copy) }, true), }, - "vhd_uri": { + "source_uri": { Type: schema.TypeString, Optional: true, ForceNew: true, @@ -70,7 +71,7 @@ func resourceArmManagedDisk() *schema.Resource { "disk_size_gb": { Type: schema.TypeInt, - Required: true, + Optional: true, ValidateFunc: validateDiskSizeGB, }, @@ -114,7 +115,7 @@ func resourceArmManagedDiskCreate(d *schema.ResourceData, meta interface{}) erro OsType: disk.OperatingSystemTypes(osType), } - if v := d.Get("disk_size_gb"); v != nil { + if v := d.Get("disk_size_gb"); v != 0 { diskSize := int32(v.(int)) createDisk.Properties.DiskSizeGB = &diskSize } @@ -125,10 +126,10 @@ func resourceArmManagedDiskCreate(d *schema.ResourceData, meta interface{}) erro } if strings.EqualFold(createOption, string(disk.Import)) { - if vhdUri := d.Get("vhd_uri").(string); vhdUri != "" { - creationData.SourceURI = &vhdUri + if sourceUri := d.Get("source_uri").(string); sourceUri != "" { + creationData.SourceURI = &sourceUri } else { - return fmt.Errorf("[ERROR] vhd_uri must be specified when create_option is `%s`", disk.Import) + return fmt.Errorf("[ERROR] source_uri must be specified when create_option is `%s` or `%s`", disk.Import, disk.Copy) } } @@ -193,8 +194,8 @@ func resourceArmManagedDiskRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("[DEBUG] Error setting managed disk creation data: %#v", err) } else { d.Set("create_option", m["create_option"]) - if m["vhd_uri"] != nil { - d.Set("vhd_uri", m["vhd_uri"]) + if m["source_uri"] != nil { + d.Set("source_uri", m["source_uri"]) } } } @@ -236,7 +237,7 @@ func flattenAzureRmManagedDiskCreationData(creationData *disk.CreationData) (map result := make(map[string]interface{}) result["create_option"] = string(creationData.CreateOption) if creationData.SourceURI != nil { - result["vhd_uri"] = *creationData.SourceURI + result["source_uri"] = *creationData.SourceURI } return result, nil diff --git a/builtin/providers/azurerm/resource_arm_managed_disk_test.go b/builtin/providers/azurerm/resource_arm_managed_disk_test.go index 69472bfae..c33836761 100644 --- a/builtin/providers/azurerm/resource_arm_managed_disk_test.go +++ b/builtin/providers/azurerm/resource_arm_managed_disk_test.go @@ -5,6 +5,7 @@ import ( "net/http" "testing" + "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/arm/disk" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" @@ -30,6 +31,82 @@ func TestAccAzureRMManagedDisk_empty(t *testing.T) { }) } +func TestAccAzureRMManagedDisk_import(t *testing.T) { + var d disk.Model + var vm compute.VirtualMachine + ri := acctest.RandInt() + vmConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) + config := fmt.Sprintf(testAccAzureRMManagedDisk_import, ri, ri, ri) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMManagedDiskDestroy, + Steps: []resource.TestStep{ + { + //need to create a vm and then delete it so we can use the vhd to test import + Config: vmConfig, + Destroy: false, + ExpectNonEmptyPlan: true, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testDeleteAzureRMVirtualMachine("azurerm_virtual_machine.test"), + ), + }, + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d), + ), + }, + }, + }) +} + +func TestAccAzureRMManagedDisk_update(t *testing.T) { + var d disk.Model + + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAzureRMManagedDisk_empty, ri, ri) + postConfig := fmt.Sprintf(testAccAzureRMManagedDisk_empty_updated, ri, ri) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMManagedDiskDestroy, + Steps: []resource.TestStep{ + { + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d), + resource.TestCheckResourceAttr( + "azurerm_managed_disk.test", "tags.%", "2"), + resource.TestCheckResourceAttr( + "azurerm_managed_disk.test", "tags.environment", "acctest"), + resource.TestCheckResourceAttr( + "azurerm_managed_disk.test", "tags.cost-center", "ops"), + resource.TestCheckResourceAttr( + "azurerm_managed_disk.test", "disk_size_gb", "20"), + resource.TestCheckResourceAttr( + "azurerm_managed_disk.test", "storage_account_type", string(disk.StandardLRS)), + ), + }, + { + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d), + resource.TestCheckResourceAttr( + "azurerm_managed_disk.test", "tags.%", "1"), + resource.TestCheckResourceAttr( + "azurerm_managed_disk.test", "tags.environment", "acctest"), + resource.TestCheckResourceAttr( + "azurerm_managed_disk.test", "disk_size_gb", "30"), + resource.TestCheckResourceAttr( + "azurerm_managed_disk.test", "storage_account_type", string(disk.PremiumLRS)), + ), + }, + }, + }) +} + func testCheckAzureRMManagedDiskExists(name string, d *disk.Model) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] @@ -85,6 +162,30 @@ func testCheckAzureRMManagedDiskDestroy(s *terraform.State) error { return nil } +func testDeleteAzureRMVirtualMachine(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + vmName := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName) + } + + conn := testAccProvider.Meta().(*ArmClient).vmClient + + _, err := conn.Delete(resourceGroup, vmName, make(chan struct{})) + if err != nil { + return fmt.Errorf("Bad: Delete on vmClient: %s", err) + } + + return nil + } +} + var testAccAzureRMManagedDisk_empty = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -99,6 +200,63 @@ resource "azurerm_managed_disk" "test" { create_option = "Empty" disk_size_gb = "20" + tags { + environment = "acctest" + cost-center = "ops" + } +}` + +var testAccAzureRMManagedDisk_empty_updated = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_managed_disk" "test" { + name = "acctestd-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Premium_LRS" + create_option = "Empty" + disk_size_gb = "30" + + tags { + environment = "acctest" + } +}` + +var testAccAzureRMManagedDisk_import = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_storage_account" "test" { + name = "accsa%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "West US 2" + 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_managed_disk" "test" { + name = "acctestd-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Import" + source_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" + tags { environment = "acctest" } From a084aa08c2a1c95eb5429fa3fbb98a06494434a6 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Fri, 3 Mar 2017 19:33:04 -0800 Subject: [PATCH 016/107] implemented copy for managed disks --- .../azurerm/resource_arm_managed_disk.go | 54 ++++++----- .../azurerm/resource_arm_managed_disk_test.go | 92 +++++++++++++++---- .../azurerm/resource_arm_virtual_machine.go | 7 +- 3 files changed, 111 insertions(+), 42 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_managed_disk.go b/builtin/providers/azurerm/resource_arm_managed_disk.go index 811ce81e8..e96506875 100644 --- a/builtin/providers/azurerm/resource_arm_managed_disk.go +++ b/builtin/providers/azurerm/resource_arm_managed_disk.go @@ -47,14 +47,22 @@ func resourceArmManagedDisk() *schema.Resource { "create_option": { Type: schema.TypeString, Required: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ string(disk.Import), string(disk.Empty), - //todo: add support for snapshots as a source (disk.Copy) + string(disk.Copy), }, true), }, "source_uri": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + + "source_resource_id": { Type: schema.TypeString, Optional: true, ForceNew: true, @@ -129,7 +137,13 @@ func resourceArmManagedDiskCreate(d *schema.ResourceData, meta interface{}) erro if sourceUri := d.Get("source_uri").(string); sourceUri != "" { creationData.SourceURI = &sourceUri } else { - return fmt.Errorf("[ERROR] source_uri must be specified when create_option is `%s` or `%s`", disk.Import, disk.Copy) + return fmt.Errorf("[ERROR] source_uri must be specified when create_option is `%s`", disk.Import) + } + } else if strings.EqualFold(createOption, string(disk.Copy)) { + if sourceResourceId := d.Get("source_resource_id").(string); sourceResourceId != "" { + creationData.SourceResourceID = &sourceResourceId + } else { + return fmt.Errorf("[ERROR] source_resource_id must be specified when create_option is `%s`", disk.Copy) } } @@ -177,26 +191,22 @@ func resourceArmManagedDiskRead(d *schema.ResourceData, meta interface{}) error d.Set("location", resp.Location) if resp.Properties != nil { - if m, err := flattenAzureRmManagedDiskProperties(resp.Properties); err != nil { - return fmt.Errorf("[DEBUG] Error setting disk properties: %#v", err) - } else { - d.Set("storage_account_type", m["storage_account_type"]) - d.Set("disk_size_gb", m["disk_size_gb"]) - if m["os_type"] != nil { - d.Set("os_type", m["os_type"]) - } - + m := flattenAzureRmManagedDiskProperties(resp.Properties) + d.Set("storage_account_type", m["storage_account_type"]) + d.Set("disk_size_gb", m["disk_size_gb"]) + if m["os_type"] != nil { + d.Set("os_type", m["os_type"]) } } if resp.CreationData != nil { - if m, err := flattenAzureRmManagedDiskCreationData(resp.CreationData); err != nil { - return fmt.Errorf("[DEBUG] Error setting managed disk creation data: %#v", err) - } else { - d.Set("create_option", m["create_option"]) - if m["source_uri"] != nil { - d.Set("source_uri", m["source_uri"]) - } + m := flattenAzureRmManagedDiskCreationData(resp.CreationData) + d.Set("create_option", m["create_option"]) + if m["source_uri"] != nil { + d.Set("source_uri", m["source_uri"]) + } + if m["source_resource_id"] != nil { + d.Set("source_resource_id", m["source_resource_id"]) } } @@ -222,7 +232,7 @@ func resourceArmManagedDiskDelete(d *schema.ResourceData, meta interface{}) erro return nil } -func flattenAzureRmManagedDiskProperties(properties *disk.Properties) (map[string]interface{}, error) { +func flattenAzureRmManagedDiskProperties(properties *disk.Properties) map[string]interface{} { result := make(map[string]interface{}) result["storage_account_type"] = string(properties.AccountType) result["disk_size_gb"] = *properties.DiskSizeGB @@ -230,15 +240,15 @@ func flattenAzureRmManagedDiskProperties(properties *disk.Properties) (map[strin result["os_type"] = string(properties.OsType) } - return result, nil + return result } -func flattenAzureRmManagedDiskCreationData(creationData *disk.CreationData) (map[string]interface{}, error) { +func flattenAzureRmManagedDiskCreationData(creationData *disk.CreationData) map[string]interface{} { result := make(map[string]interface{}) result["create_option"] = string(creationData.CreateOption) if creationData.SourceURI != nil { result["source_uri"] = *creationData.SourceURI } - return result, nil + return result } diff --git a/builtin/providers/azurerm/resource_arm_managed_disk_test.go b/builtin/providers/azurerm/resource_arm_managed_disk_test.go index c33836761..a5f607af8 100644 --- a/builtin/providers/azurerm/resource_arm_managed_disk_test.go +++ b/builtin/providers/azurerm/resource_arm_managed_disk_test.go @@ -62,6 +62,25 @@ func TestAccAzureRMManagedDisk_import(t *testing.T) { }) } +func TestAccAzureRMManagedDisk_copy(t *testing.T) { + var d disk.Model + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMManagedDisk_copy, ri, ri, ri) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMManagedDiskDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d), + ), + }, + }, + }) +} + func TestAccAzureRMManagedDisk_update(t *testing.T) { var d disk.Model @@ -206,25 +225,6 @@ resource "azurerm_managed_disk" "test" { } }` -var testAccAzureRMManagedDisk_empty_updated = ` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "West US 2" -} - -resource "azurerm_managed_disk" "test" { - name = "acctestd-%d" - location = "West US 2" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_type = "Premium_LRS" - create_option = "Empty" - disk_size_gb = "30" - - tags { - environment = "acctest" - } -}` - var testAccAzureRMManagedDisk_import = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -261,3 +261,57 @@ resource "azurerm_managed_disk" "test" { environment = "acctest" } }` + +var testAccAzureRMManagedDisk_copy = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_managed_disk" "source" { + name = "acctestd1-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "1" + + tags { + environment = "acctest" + cost-center = "ops" + } +} + +resource "azurerm_managed_disk" "test" { + name = "acctestd2-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Copy" + source_resource_id = "${azurerm_managed_disk.source.id}" + disk_size_gb = "1" + + tags { + environment = "acctest" + cost-center = "ops" + } +}` + +var testAccAzureRMManagedDisk_empty_updated = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_managed_disk" "test" { + name = "acctestd-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Premium_LRS" + create_option = "Empty" + disk_size_gb = "30" + + tags { + environment = "acctest" + } +}` diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index 0d79a9285..2d51e4a9a 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -152,9 +152,14 @@ func resourceArmVirtualMachine() *schema.Resource { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "storage_account_type": { Type: schema.TypeString, - Required: true, + Optional: true, ValidateFunc: validation.StringInSlice([]string{ string(compute.PremiumLRS), string(compute.StandardLRS), From ac8eae9eff6f33a3d681439fafda38aa6a2064a5 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Fri, 3 Mar 2017 21:50:32 -0800 Subject: [PATCH 017/107] implemented attaching existing managed disks on vm creation --- .../azurerm/resource_arm_virtual_machine.go | 48 ++++-- .../resource_arm_virtual_machine_test.go | 158 +++++++++++++++--- 2 files changed, 170 insertions(+), 36 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index 2d51e4a9a..ae82cbb8b 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -152,7 +152,7 @@ func resourceArmVirtualMachine() *schema.Resource { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "id": { + "managed_disk_id": { Type: schema.TypeString, Optional: true, ForceNew: true, @@ -221,6 +221,11 @@ func resourceArmVirtualMachine() *schema.Resource { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "managed_disk_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "storage_account_type": { Type: schema.TypeString, Required: true, @@ -810,6 +815,9 @@ func resourceArmVirtualMachineStorageOsDiskHash(v interface{}) int { if managedDisk["storage_account_type"] != nil { buf.WriteString(fmt.Sprintf("%s-", managedDisk["storage_account_type"].(string))) } + if managedDisk["managed_disk_id"] != nil { + buf.WriteString(fmt.Sprintf("%s-", managedDisk["managed_disk_id"].(string))) + } } return hashcode.String(buf.String()) } @@ -1272,16 +1280,18 @@ func expandAzureRmVirtualMachineDataDisk(d *schema.ResourceData) ([]compute.Data Lun: &lun, CreateOption: compute.DiskCreateOptionTypes(createOption), } - if vhd != "" && managedDisk != nil { + if vhd != "" && len(managedDisk) != 0 { return nil, fmt.Errorf("[ERROR] Conflict between `vhd_uri` and `managed_disk` (only one or the other can be used)") } else if vhd != "" { data_disk.Vhd = &compute.VirtualHardDisk{ URI: &vhd, } } else if managedDisk != nil { - data_disk.ManagedDisk = expandAzureRmVirtualMachineManagedDisk(managedDisk) - } else { - return nil, fmt.Errorf("[ERROR] A value must be specified for either `vhd_uri` or `managed_disk`") + managedDisk, err := expandAzureRmVirtualMachineManagedDisk(managedDisk, &data_disk.CreateOption) + if err != nil { + return nil, err + } + data_disk.ManagedDisk = managedDisk } if v := config["caching"].(string); v != "" { @@ -1372,14 +1382,18 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk, CreateOption: compute.DiskCreateOptionTypes(createOption), } - if vhdURI != "" { + if vhdURI != "" && len(managedDisk) != 0 { + return nil, fmt.Errorf("[ERROR] Conflict between `vhd_uri` and `managed_disk` (only one or the other can be used)") + } else if vhdURI != "" { osDisk.Vhd = &compute.VirtualHardDisk{ URI: &vhdURI, } } else if managedDisk != nil { - osDisk.ManagedDisk = expandAzureRmVirtualMachineManagedDisk(managedDisk) - } else { - return nil, fmt.Errorf("[ERROR] must specify value for either vhd_uri or managed_disk") + managedDisk, err := expandAzureRmVirtualMachineManagedDisk(managedDisk, &osDisk.CreateOption) + if err != nil { + return nil, err + } + osDisk.ManagedDisk = managedDisk } if v := disk["image_uri"].(string); v != "" { @@ -1410,11 +1424,19 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk, return osDisk, nil } -func expandAzureRmVirtualMachineManagedDisk(managedDisk map[string]interface{}) *compute.ManagedDiskParameters { - managedDiskParameters := &compute.ManagedDiskParameters{ - StorageAccountType: compute.StorageAccountTypes(managedDisk["storage_account_type"].(string)), +func expandAzureRmVirtualMachineManagedDisk(managedDisk map[string]interface{}, createOption *compute.DiskCreateOptionTypes) (*compute.ManagedDiskParameters, error) { + managedDiskParameters := &compute.ManagedDiskParameters{} + if storageAccountType := managedDisk["storage_account_type"]; storageAccountType != nil { + managedDiskParameters.StorageAccountType = compute.StorageAccountTypes(storageAccountType.(string)) } - return managedDiskParameters + if managedDisk["managed_disk_id"] != nil { + managedDiskId := managedDisk["managed_disk_id"].(string) + managedDiskParameters.ID = &managedDiskId + } + if *createOption == compute.Attach && managedDiskParameters.ID == nil { + return nil, fmt.Errorf("[ERROR] A value is required for `managed_disk_id` when `create_option` is %s", compute.Attach) + } + return managedDiskParameters, nil } func findStorageAccountResourceGroup(meta interface{}, storageAccountName string) (string, error) { diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go index 3fbfc2c97..caa9c5c7b 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go @@ -50,6 +50,25 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk(t *testing.T) { }) } +func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(t *testing.T) { + var vm compute.VirtualMachine + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach, 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 TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) { var vm compute.VirtualMachine ri := acctest.RandInt() @@ -167,7 +186,7 @@ func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), resource.TestCheckResourceAttr( - "azurerm_virtual_machine.test", "vm_size", "Standard_A0"), + "azurerm_virtual_machine.test", "vm_size", "Standard_D1_v2"), ), }, { @@ -175,7 +194,7 @@ func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), resource.TestCheckResourceAttr( - "azurerm_virtual_machine.test", "vm_size", "Standard_A1"), + "azurerm_virtual_machine.test", "vm_size", "Standard_D2_v2"), ), }, }, @@ -200,7 +219,7 @@ func TestAccAzureRMVirtualMachine_updateMachineSize_managedDisk(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), resource.TestCheckResourceAttr( - "azurerm_virtual_machine.test", "vm_size", "Standard_A0"), + "azurerm_virtual_machine.test", "vm_size", "Standard_D1_v2"), ), }, { @@ -707,7 +726,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "Canonical" @@ -778,7 +797,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "Canonical" @@ -815,6 +834,99 @@ resource "azurerm_virtual_machine" "test" { } ` +var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "West US 2" + 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 2" + 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_managed_disk" "test" { + name = "acctmd-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "1" +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_D1_v2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "14.04.2-LTS" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + disk_size_gb = "10" + + managed_disk { + storage_account_type = "Standard_LRS" + } + } + + storage_data_disk { + name = "${azurerm_managed_disk.test.name}" + create_option = "Attach" + disk_size_gb = "1" + lun = 0 + managed_disk = { + managed_disk_id = "${azurerm_managed_disk.test.id}" + } + } + + os_profile { + computer_name = "hostname%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags { + environment = "Production" + cost-center = "Ops" + } +} +` + var testAccAzureRMVirtualMachine_machineNameBeforeUpdate = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -870,7 +982,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" delete_os_disk_on_termination = true storage_image_reference { @@ -964,7 +1076,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "Canonical" @@ -1171,7 +1283,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "Canonical" @@ -1353,7 +1465,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "Canonical" @@ -1512,7 +1624,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A1" + vm_size = "Standard_D2_v2" storage_image_reference { publisher = "Canonical" @@ -1663,7 +1775,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "MicrosoftWindowsServer" @@ -1747,7 +1859,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "MicrosoftWindowsServer" @@ -1837,7 +1949,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "MicrosoftWindowsServer" @@ -1928,7 +2040,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "MicrosoftWindowsServer" @@ -2019,7 +2131,7 @@ var testAccAzureRMVirtualMachine_withAvailabilitySet = ` location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" availability_set_id = "${azurerm_availability_set.test.id}" delete_os_disk_on_termination = true @@ -2110,7 +2222,7 @@ var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" availability_set_id = "${azurerm_availability_set.test.id}" delete_os_disk_on_termination = true @@ -2195,7 +2307,7 @@ var testAccAzureRMVirtualMachine_updateMachineName = ` location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" delete_os_disk_on_termination = true storage_image_reference { @@ -2279,7 +2391,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" delete_os_disk_on_termination = true storage_image_reference { @@ -2369,7 +2481,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" delete_os_disk_on_termination = true storage_image_reference { @@ -2459,7 +2571,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "Canonical" @@ -2548,7 +2660,7 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" license_type = "Windows_Server" storage_image_reference { @@ -2724,7 +2836,7 @@ resource "azurerm_virtual_machine" "test" { location = "southcentralus" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "Canonical" @@ -2808,7 +2920,7 @@ resource "azurerm_virtual_machine" "test" { location = "southcentralus" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_A0" + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "Canonical" From 5d915dd4f5da3cf6d41d4e6ffa8e33750bc98c18 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Sun, 5 Mar 2017 17:48:35 -0800 Subject: [PATCH 018/107] flattened managed disk structure in virtual machine refactored managed disk acceptance tests --- .../import_arm_virtual_machine_test.go | 10 +- .../azurerm/resource_arm_managed_disk_test.go | 25 +- .../azurerm/resource_arm_virtual_machine.go | 247 +++--- .../resource_arm_virtual_machine_test.go | 764 ++++++++++++------ 4 files changed, 682 insertions(+), 364 deletions(-) diff --git a/builtin/providers/azurerm/import_arm_virtual_machine_test.go b/builtin/providers/azurerm/import_arm_virtual_machine_test.go index dad790049..f6b72e208 100644 --- a/builtin/providers/azurerm/import_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/import_arm_virtual_machine_test.go @@ -19,11 +19,11 @@ func TestAccAzureRMVirtualMachine_importBasic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, }, - resource.TestStep{ + { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, @@ -40,18 +40,18 @@ func TestAccAzureRMVirtualMachine_importBasic_managedDisk(t *testing.T) { resourceName := "azurerm_virtual_machine.test" ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk, ri, ri, ri, ri, ri, ri) + config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit, ri, ri, ri, ri, ri, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, }, - resource.TestStep{ + { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, diff --git a/builtin/providers/azurerm/resource_arm_managed_disk_test.go b/builtin/providers/azurerm/resource_arm_managed_disk_test.go index a5f607af8..7d57f78f9 100644 --- a/builtin/providers/azurerm/resource_arm_managed_disk_test.go +++ b/builtin/providers/azurerm/resource_arm_managed_disk_test.go @@ -24,7 +24,7 @@ func TestAccAzureRMManagedDisk_empty(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d), + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true), ), }, }, @@ -55,7 +55,7 @@ func TestAccAzureRMManagedDisk_import(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d), + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true), ), }, }, @@ -74,7 +74,7 @@ func TestAccAzureRMManagedDisk_copy(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d), + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true), ), }, }, @@ -95,7 +95,7 @@ func TestAccAzureRMManagedDisk_update(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d), + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true), resource.TestCheckResourceAttr( "azurerm_managed_disk.test", "tags.%", "2"), resource.TestCheckResourceAttr( @@ -103,7 +103,7 @@ func TestAccAzureRMManagedDisk_update(t *testing.T) { resource.TestCheckResourceAttr( "azurerm_managed_disk.test", "tags.cost-center", "ops"), resource.TestCheckResourceAttr( - "azurerm_managed_disk.test", "disk_size_gb", "20"), + "azurerm_managed_disk.test", "disk_size_gb", "1"), resource.TestCheckResourceAttr( "azurerm_managed_disk.test", "storage_account_type", string(disk.StandardLRS)), ), @@ -111,13 +111,13 @@ func TestAccAzureRMManagedDisk_update(t *testing.T) { { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d), + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true), resource.TestCheckResourceAttr( "azurerm_managed_disk.test", "tags.%", "1"), resource.TestCheckResourceAttr( "azurerm_managed_disk.test", "tags.environment", "acctest"), resource.TestCheckResourceAttr( - "azurerm_managed_disk.test", "disk_size_gb", "30"), + "azurerm_managed_disk.test", "disk_size_gb", "2"), resource.TestCheckResourceAttr( "azurerm_managed_disk.test", "storage_account_type", string(disk.PremiumLRS)), ), @@ -126,7 +126,7 @@ func TestAccAzureRMManagedDisk_update(t *testing.T) { }) } -func testCheckAzureRMManagedDiskExists(name string, d *disk.Model) resource.TestCheckFunc { +func testCheckAzureRMManagedDiskExists(name string, d *disk.Model, shouldExist bool) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -146,9 +146,12 @@ func testCheckAzureRMManagedDiskExists(name string, d *disk.Model) resource.Test return fmt.Errorf("Bad: Get on diskClient: %s", err) } - if resp.StatusCode == http.StatusNotFound { + if resp.StatusCode == http.StatusNotFound && shouldExist { return fmt.Errorf("Bad: ManagedDisk %q (resource group %q) does not exist", dName, resourceGroup) } + if resp.StatusCode != http.StatusNotFound && !shouldExist { + return fmt.Errorf("Bad: ManagedDisk %q (resource group %q) still exists", dName, resourceGroup) + } *d = resp @@ -217,7 +220,7 @@ resource "azurerm_managed_disk" "test" { resource_group_name = "${azurerm_resource_group.test.name}" storage_account_type = "Standard_LRS" create_option = "Empty" - disk_size_gb = "20" + disk_size_gb = "1" tags { environment = "acctest" @@ -309,7 +312,7 @@ resource "azurerm_managed_disk" "test" { resource_group_name = "${azurerm_resource_group.test.name}" storage_account_type = "Premium_LRS" create_option = "Empty" - disk_size_gb = "30" + disk_size_gb = "2" tags { environment = "acctest" diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index ae82cbb8b..0586c8d24 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -147,26 +147,21 @@ func resourceArmVirtualMachine() *schema.Resource { ForceNew: true, }, - "managed_disk": { - Type: schema.TypeMap, + "managed_disk_id": { + Type: schema.TypeString, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "managed_disk_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "storage_account_type": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{ - string(compute.PremiumLRS), - string(compute.StandardLRS), - }, true), - }, - }, - }, + ForceNew: true, + Computed: true, + }, + + "managed_disk_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + string(compute.PremiumLRS), + string(compute.StandardLRS), + }, true), }, "image_uri": { @@ -216,26 +211,21 @@ func resourceArmVirtualMachine() *schema.Resource { Optional: true, }, - "managed_disk": { - Type: schema.TypeMap, + "managed_disk_id": { + Type: schema.TypeString, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "managed_disk_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "storage_account_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - string(compute.PremiumLRS), - string(compute.StandardLRS), - }, true), - }, - }, - }, + ForceNew: true, + Computed: true, + }, + + "managed_disk_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + string(compute.PremiumLRS), + string(compute.StandardLRS), + }, true), }, "create_option": { @@ -708,21 +698,29 @@ func resourceArmVirtualMachineDelete(d *schema.ResourceData, meta interface{}) e // delete OS Disk if opted in if deleteOsDisk := d.Get("delete_os_disk_on_termination").(bool); deleteOsDisk { - log.Printf("[INFO] delete_os_disk_on_termination is enabled, deleting") + log.Printf("[INFO] delete_os_disk_on_termination is enabled, deleting disk from %s", name) osDisk, err := expandAzureRmVirtualMachineOsDisk(d) if err != nil { return fmt.Errorf("Error expanding OS Disk: %s", err) } - if err = resourceArmVirtualMachineDeleteVhd(*osDisk.Vhd.URI, meta); err != nil { - return fmt.Errorf("Error deleting OS Disk VHD: %s", err) + if osDisk.Vhd != nil { + if err = resourceArmVirtualMachineDeleteVhd(*osDisk.Vhd.URI, meta); err != nil { + return fmt.Errorf("Error deleting OS Disk VHD: %s", err) + } + } else if osDisk.ManagedDisk != nil { + if err = resourceArmVirtualMachineDeleteManagedDisk(*osDisk.ManagedDisk.ID, meta); err != nil { + return fmt.Errorf("Error deleting OS Managed Disk: %s", err) + } + } else { + return fmt.Errorf("Unable to locate OS managed disk properties from %s", name) } } // delete Data disks if opted in if deleteDataDisks := d.Get("delete_data_disks_on_termination").(bool); deleteDataDisks { - log.Printf("[INFO] delete_data_disks_on_termination is enabled, deleting each data disk") + log.Printf("[INFO] delete_data_disks_on_termination is enabled, deleting each data disk from %s", name) disks, err := expandAzureRmVirtualMachineDataDisk(d) if err != nil { @@ -730,8 +728,16 @@ func resourceArmVirtualMachineDelete(d *schema.ResourceData, meta interface{}) e } for _, disk := range disks { - if err = resourceArmVirtualMachineDeleteVhd(*disk.Vhd.URI, meta); err != nil { - return fmt.Errorf("Error deleting Data Disk VHD: %s", err) + if disk.Vhd != nil { + if err = resourceArmVirtualMachineDeleteVhd(*disk.Vhd.URI, meta); err != nil { + return fmt.Errorf("Error deleting Data Managed Disk: %s", err) + } + } else if disk.ManagedDisk != nil { + if err = resourceArmVirtualMachineDeleteManagedDisk(*disk.ManagedDisk.ID, meta); err != nil { + return fmt.Errorf("Error deleting Data Managed Disk: %s", err) + } + } else { + return fmt.Errorf("Unable to locate data managed disk properties from %s", name) } } } @@ -775,6 +781,24 @@ func resourceArmVirtualMachineDeleteVhd(uri string, meta interface{}) error { return nil } +func resourceArmVirtualMachineDeleteManagedDisk(managedDiskID string, meta interface{}) error { + diskClient := meta.(*ArmClient).diskClient + + id, err := parseAzureResourceID(managedDiskID) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["disks"] + + _, err = diskClient.Delete(resGroup, name, make(chan struct{})) + if err != nil { + return fmt.Errorf("Error deleting Managed Disk (%s %s) %s", name, resGroup, err) + } + + return nil +} + func resourceArmVirtualMachinePlanHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) @@ -810,15 +834,6 @@ func resourceArmVirtualMachineStorageOsDiskHash(v interface{}) int { if m["vhd_uri"] != nil { buf.WriteString(fmt.Sprintf("%s-", m["vhd_uri"].(string))) } - if m["managed_disk"] != nil { - managedDisk := m["managed_disk"].(map[string]interface{}) - if managedDisk["storage_account_type"] != nil { - buf.WriteString(fmt.Sprintf("%s-", managedDisk["storage_account_type"].(string))) - } - if managedDisk["managed_disk_id"] != nil { - buf.WriteString(fmt.Sprintf("%s-", managedDisk["managed_disk_id"].(string))) - } - } return hashcode.String(buf.String()) } @@ -920,7 +935,8 @@ func flattenAzureRmVirtualMachineDataDisk(disks *[]compute.DataDisk) interface{} l["vhd_uri"] = *disk.Vhd.URI } if disk.ManagedDisk != nil { - l["managed_disk"] = flattenAzureRmVirtualMachineManagedDisk(disk.ManagedDisk) + l["managed_disk_type"] = string(disk.ManagedDisk.StorageAccountType) + l["managed_disk_id"] = *disk.ManagedDisk.ID } l["create_option"] = disk.CreateOption l["caching"] = string(disk.Caching) @@ -1031,7 +1047,8 @@ func flattenAzureRmVirtualMachineOsDisk(disk *compute.OSDisk) []interface{} { result["vhd_uri"] = *disk.Vhd.URI } if disk.ManagedDisk != nil { - result["managed_disk"] = flattenAzureRmVirtualMachineManagedDisk(disk.ManagedDisk) + result["managed_disk_type"] = string(disk.ManagedDisk.StorageAccountType) + result["managed_disk_id"] = *disk.ManagedDisk.ID } result["create_option"] = disk.CreateOption result["caching"] = disk.Caching @@ -1042,12 +1059,6 @@ func flattenAzureRmVirtualMachineOsDisk(disk *compute.OSDisk) []interface{} { return []interface{}{result} } -func flattenAzureRmVirtualMachineManagedDisk(params *compute.ManagedDiskParameters) map[string]interface{} { - managedDisk := make(map[string]interface{}) - managedDisk["storage_account_type"] = string(params.StorageAccountType) - return managedDisk -} - func expandAzureRmVirtualMachinePlan(d *schema.ResourceData) (*compute.Plan, error) { planConfigs := d.Get("plan").(*schema.Set).List() @@ -1218,22 +1229,22 @@ func expandAzureRmVirtualMachineOsProfileWindowsConfig(d *schema.ResourceData) ( if v := osProfileConfig["winrm"]; v != nil { winRm := v.([]interface{}) if len(winRm) > 0 { - winRmListners := make([]compute.WinRMListener, 0, len(winRm)) + winRmListeners := make([]compute.WinRMListener, 0, len(winRm)) for _, winRmConfig := range winRm { config := winRmConfig.(map[string]interface{}) protocol := config["protocol"].(string) - winRmListner := compute.WinRMListener{ + winRmListener := compute.WinRMListener{ Protocol: compute.ProtocolTypes(protocol), } if v := config["certificate_url"].(string); v != "" { - winRmListner.CertificateURL = &v + winRmListener.CertificateURL = &v } - winRmListners = append(winRmListners, winRmListner) + winRmListeners = append(winRmListeners, winRmListener) } config.WinRM = &compute.WinRMConfiguration{ - Listeners: &winRmListners, + Listeners: &winRmListeners, } } } @@ -1270,9 +1281,10 @@ func expandAzureRmVirtualMachineDataDisk(d *schema.ResourceData) ([]compute.Data config := disk_config.(map[string]interface{}) name := config["name"].(string) - vhd := config["vhd_uri"].(string) - managedDisk := config["managed_disk"].(map[string]interface{}) createOption := config["create_option"].(string) + vhdURI := config["vhd_uri"].(string) + managedDiskType := config["managed_disk_type"].(string) + managedDiskID := config["managed_disk_id"].(string) lun := int32(config["lun"].(int)) data_disk := compute.DataDisk{ @@ -1280,20 +1292,35 @@ func expandAzureRmVirtualMachineDataDisk(d *schema.ResourceData) ([]compute.Data Lun: &lun, CreateOption: compute.DiskCreateOptionTypes(createOption), } - if vhd != "" && len(managedDisk) != 0 { - return nil, fmt.Errorf("[ERROR] Conflict between `vhd_uri` and `managed_disk` (only one or the other can be used)") - } else if vhd != "" { + + if vhdURI != "" { data_disk.Vhd = &compute.VirtualHardDisk{ - URI: &vhd, - } - } else if managedDisk != nil { - managedDisk, err := expandAzureRmVirtualMachineManagedDisk(managedDisk, &data_disk.CreateOption) - if err != nil { - return nil, err + URI: &vhdURI, } + } + + managedDisk := &compute.ManagedDiskParameters{} + + if managedDiskType != "" { + managedDisk.StorageAccountType = compute.StorageAccountTypes(managedDiskType) data_disk.ManagedDisk = managedDisk } + if managedDiskID != "" { + managedDisk.ID = &managedDiskID + data_disk.ManagedDisk = managedDisk + } + + if vhdURI != "" && managedDiskID != "" { + return nil, fmt.Errorf("[ERROR] Conflict between `vhd_uri` and `managed_disk_id` (only one or the other can be used)") + } + if vhdURI != "" && managedDiskType != "" { + return nil, fmt.Errorf("[ERROR] Conflict between `vhd_uri` and `managed_disk_type` (only one or the other can be used)") + } + if managedDiskID == "" && strings.EqualFold(string(data_disk.CreateOption), string(compute.Attach)) { + return nil, fmt.Errorf("[ERROR] Must specify which disk to attach") + } + if v := config["caching"].(string); v != "" { data_disk.Caching = compute.CachingTypes(v) } @@ -1369,40 +1396,55 @@ func expandAzureRmVirtualMachineNetworkProfile(d *schema.ResourceData) compute.N func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk, error) { disks := d.Get("storage_os_disk").(*schema.Set).List() - disk := disks[0].(map[string]interface{}) + config := disks[0].(map[string]interface{}) - name := disk["name"].(string) - vhdURI := disk["vhd_uri"].(string) - managedDisk := disk["managed_disk"].(map[string]interface{}) - imageURI := disk["image_uri"].(string) - createOption := disk["create_option"].(string) + name := config["name"].(string) + imageURI := config["image_uri"].(string) + createOption := config["create_option"].(string) + vhdURI := config["vhd_uri"].(string) + managedDiskType := config["managed_disk_type"].(string) + managedDiskID := config["managed_disk_id"].(string) osDisk := &compute.OSDisk{ Name: &name, CreateOption: compute.DiskCreateOptionTypes(createOption), } - if vhdURI != "" && len(managedDisk) != 0 { - return nil, fmt.Errorf("[ERROR] Conflict between `vhd_uri` and `managed_disk` (only one or the other can be used)") - } else if vhdURI != "" { + if vhdURI != "" { osDisk.Vhd = &compute.VirtualHardDisk{ URI: &vhdURI, } - } else if managedDisk != nil { - managedDisk, err := expandAzureRmVirtualMachineManagedDisk(managedDisk, &osDisk.CreateOption) - if err != nil { - return nil, err - } + } + + managedDisk := &compute.ManagedDiskParameters{} + + if managedDiskType != "" { + managedDisk.StorageAccountType = compute.StorageAccountTypes(managedDiskType) osDisk.ManagedDisk = managedDisk } - if v := disk["image_uri"].(string); v != "" { + if managedDiskID != "" { + managedDisk.ID = &managedDiskID + osDisk.ManagedDisk = managedDisk + } + + if vhdURI != "" && managedDiskID != "" { + return nil, fmt.Errorf("[ERROR] Conflict between `vhd_uri` and `managed_disk_id` (only one or the other can be used)") + } + if vhdURI != "" && managedDiskType != "" { + return nil, fmt.Errorf("[ERROR] Conflict between `vhd_uri` and `managed_disk_type` (only one or the other can be used)") + } + if managedDiskID == "" && strings.EqualFold(string(osDisk.CreateOption), string(compute.Attach)) { + return nil, fmt.Errorf("[ERROR] Must specify which disk to attach") + } + + if v := config["image_uri"].(string); v != "" { osDisk.Image = &compute.VirtualHardDisk{ URI: &imageURI, } } - if v := disk["os_type"].(string); v != "" { + if v := config["os_type"].(string); v != "" { if v == "linux" { osDisk.OsType = compute.Linux } else if v == "windows" { @@ -1412,11 +1454,11 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk, } } - if v := disk["caching"].(string); v != "" { + if v := config["caching"].(string); v != "" { osDisk.Caching = compute.CachingTypes(v) } - if v := disk["disk_size_gb"].(int); v != 0 { + if v := config["disk_size_gb"].(int); v != 0 { diskSize := int32(v) osDisk.DiskSizeGB = &diskSize } @@ -1424,21 +1466,6 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk, return osDisk, nil } -func expandAzureRmVirtualMachineManagedDisk(managedDisk map[string]interface{}, createOption *compute.DiskCreateOptionTypes) (*compute.ManagedDiskParameters, error) { - managedDiskParameters := &compute.ManagedDiskParameters{} - if storageAccountType := managedDisk["storage_account_type"]; storageAccountType != nil { - managedDiskParameters.StorageAccountType = compute.StorageAccountTypes(storageAccountType.(string)) - } - if managedDisk["managed_disk_id"] != nil { - managedDiskId := managedDisk["managed_disk_id"].(string) - managedDiskParameters.ID = &managedDiskId - } - if *createOption == compute.Attach && managedDiskParameters.ID == nil { - return nil, fmt.Errorf("[ERROR] A value is required for `managed_disk_id` when `create_option` is %s", compute.Attach) - } - return managedDiskParameters, nil -} - func findStorageAccountResourceGroup(meta interface{}, storageAccountName string) (string, error) { client := meta.(*ArmClient).resourceFindClient filter := fmt.Sprintf("name eq '%s' and resourceType eq 'Microsoft.Storage/storageAccounts'", storageAccountName) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go index caa9c5c7b..72984afd5 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go @@ -10,6 +10,8 @@ import ( "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" + "os" + "github.com/Azure/azure-sdk-for-go/arm/disk" ) func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { @@ -31,10 +33,29 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { }) } -func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk(t *testing.T) { +func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(t *testing.T) { var vm compute.VirtualMachine ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk, ri, ri, ri, ri, ri, ri) + config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit, 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 TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit(t *testing.T) { + var vm compute.VirtualMachine + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit, ri, ri, ri, ri, ri, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -53,7 +74,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk(t *testing.T) { func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(t *testing.T) { var vm compute.VirtualMachine ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach, ri, ri, ri, ri, ri, ri, ri) + config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach, ri, ri, ri, ri, ri, ri, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -82,7 +103,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), - testCheckAzureRMVirtualMachineDisappears("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineDisappears("azurerm_virtual_machine.test"), ), ExpectNonEmptyPlan: true, }, @@ -110,11 +131,31 @@ func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) { }) } -func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk(t *testing.T) { +func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit(t *testing.T) { var vm compute.VirtualMachine ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk_managedDisk, ri, ri, ri, ri, ri, ri) + config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit, ri, 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 TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(t *testing.T) { + var vm compute.VirtualMachine + + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit, ri, ri, ri, ri, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -172,7 +213,6 @@ func TestAccAzureRMVirtualMachine_tags(t *testing.T) { //Because we use CreateOrUpdate, we were sending an empty password on update requests func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) { var vm compute.VirtualMachine - ri := acctest.RandInt() preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updatedLinuxMachine, ri, ri, ri, ri, ri, ri, ri) @@ -201,39 +241,6 @@ func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) { }) } -//This is a regression test around https://github.com/hashicorp/terraform/issues/6517 -//Because we use CreateOrUpdate, we were sending an empty password on update requests -func TestAccAzureRMVirtualMachine_updateMachineSize_managedDisk(t *testing.T) { - var vm compute.VirtualMachine - - ri := acctest.RandInt() - preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk, ri, ri, ri, ri, ri, ri) - postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updatedLinuxMachine_managedDisk, ri, ri, ri, ri, ri, ri) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMVirtualMachineDestroy, - Steps: []resource.TestStep{ - { - Config: preConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), - resource.TestCheckResourceAttr( - "azurerm_virtual_machine.test", "vm_size", "Standard_D1_v2"), - ), - }, - { - Config: postConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), - resource.TestCheckResourceAttr( - "azurerm_virtual_machine.test", "vm_size", "Standard_DS1_v2"), - ), - }, - }, - }) -} - func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) { var vm compute.VirtualMachine ri := acctest.RandInt() @@ -329,8 +336,40 @@ func TestAccAzureRMVirtualMachine_deleteVHDOptOut(t *testing.T) { { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineVHDExistance("myosdisk1.vhd", true), - testCheckAzureRMVirtualMachineVHDExistance("mydatadisk1.vhd", true), + testCheckAzureRMVirtualMachineVHDExistence("myosdisk1.vhd", true), + testCheckAzureRMVirtualMachineVHDExistence("mydatadisk1.vhd", true), + ), + }, + }, + }) +} + +func TestAccAzureRMVirtualMachine_deleteManagedDiskOptOut(t *testing.T) { + var vm compute.VirtualMachine + var osd string + var dtd string + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit, ri, ri, ri, ri, ri, ri) + postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM_managedDisk, ri, ri, ri, ri) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineDestroy, + Steps: []resource.TestStep{ + { + Destroy: false, + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testLookupAzureRMVirtualMachineManagedDiskID(&vm, "myosdisk1", &osd), + testLookupAzureRMVirtualMachineManagedDiskID(&vm, "mydatadisk1", &dtd), + ), + }, + { + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineManagedDiskExists(&osd, true), + testCheckAzureRMVirtualMachineManagedDiskExists(&dtd, true), ), }, }, @@ -356,8 +395,41 @@ func TestAccAzureRMVirtualMachine_deleteVHDOptIn(t *testing.T) { { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineVHDExistance("myosdisk1.vhd", false), - testCheckAzureRMVirtualMachineVHDExistance("mydatadisk1.vhd", false), + testCheckAzureRMVirtualMachineVHDExistence("myosdisk1.vhd", false), + testCheckAzureRMVirtualMachineVHDExistence("mydatadisk1.vhd", false), + ), + }, + }, + }) +} + +func TestAccAzureRMVirtualMachine_deleteManagedDiskOptIn(t *testing.T) { + os.Setenv("TF_ACC", "1") + var vm compute.VirtualMachine + var osd string + var dtd string + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksBefore, ri, ri, ri, ri, ri, ri) + postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksAfter, ri, ri, ri, ri) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineDestroy, + Steps: []resource.TestStep{ + { + Destroy: false, + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testLookupAzureRMVirtualMachineManagedDiskID(&vm, "myosdisk1", &osd), + testLookupAzureRMVirtualMachineManagedDiskID(&vm, "mydatadisk1", &dtd), + ), + }, + { + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineManagedDiskExists(&osd, false), + testCheckAzureRMVirtualMachineManagedDiskExists(&dtd, false), ), }, }, @@ -375,14 +447,14 @@ func TestAccAzureRMVirtualMachine_ChangeComputerName(t *testing.T) { Providers: testAccProviders, CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: preConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), ), }, - resource.TestStep{ + { Config: postConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), @@ -394,7 +466,7 @@ func TestAccAzureRMVirtualMachine_ChangeComputerName(t *testing.T) { }) } -func TestAccAzureRMVirtualMachine_ChangeAvailbilitySet(t *testing.T) { +func TestAccAzureRMVirtualMachine_ChangeAvailabilitySet(t *testing.T) { var afterCreate, afterUpdate compute.VirtualMachine ri := acctest.RandInt() @@ -405,14 +477,14 @@ func TestAccAzureRMVirtualMachine_ChangeAvailbilitySet(t *testing.T) { Providers: testAccProviders, CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: preConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), ), }, - resource.TestStep{ + { Config: postConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), @@ -435,14 +507,14 @@ func TestAccAzureRMVirtualMachine_changeStorageImageReference(t *testing.T) { Providers: testAccProviders, CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: preConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), ), }, - resource.TestStep{ + { Config: postConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), @@ -465,14 +537,14 @@ func TestAccAzureRMVirtualMachine_changeOSDiskVhdUri(t *testing.T) { Providers: testAccProviders, CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: preConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), ), }, - resource.TestStep{ + { Config: postConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), @@ -560,6 +632,23 @@ func testCheckAzureRMVirtualMachineExists(name string, vm *compute.VirtualMachin } } +func testCheckAzureRMVirtualMachineManagedDiskExists(managedDiskID *string, shouldExist bool) resource.TestCheckFunc { + return func(s *terraform.State) error { + d, err := testGetAzureRMVirtualMachineManagedDisk(managedDiskID) + if err != nil { + return fmt.Errorf("Error trying to retrieve Managed Disk %s, %s", *managedDiskID, err) + } + if d.StatusCode == http.StatusNotFound && shouldExist { + return fmt.Errorf("Unable to find Managed Disk %s", *managedDiskID) + } + if d.StatusCode != http.StatusNotFound && !shouldExist { + return fmt.Errorf("Found unexpected Managed Disk %s", *managedDiskID) + } + + return nil + } +} + func testAccCheckVirtualMachineRecreated(t *testing.T, before, after *compute.VirtualMachine) resource.TestCheckFunc { return func(s *terraform.State) error { @@ -595,7 +684,7 @@ func testCheckAzureRMVirtualMachineDestroy(s *terraform.State) error { return nil } -func testCheckAzureRMVirtualMachineVHDExistance(name string, shouldExist bool) resource.TestCheckFunc { +func testCheckAzureRMVirtualMachineVHDExistence(name string, shouldExist bool) resource.TestCheckFunc { return func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "azurerm_storage_container" { @@ -617,9 +706,9 @@ func testCheckAzureRMVirtualMachineVHDExistance(name string, shouldExist bool) r } if exists && !shouldExist { - return fmt.Errorf("Disk VHD Blob still exists") + return fmt.Errorf("Disk VHD Blob still exists %s %s", containerName, name) } else if !exists && shouldExist { - return fmt.Errorf("Disk VHD Blob should exist") + return fmt.Errorf("Disk VHD Blob should exist %s %s", containerName, name) } } @@ -627,7 +716,7 @@ func testCheckAzureRMVirtualMachineVHDExistance(name string, shouldExist bool) r } } -func testCheckAzureRMVirtualMachineDisappears(name string, vm *compute.VirtualMachine) resource.TestCheckFunc { +func testCheckAzureRMVirtualMachineDisappears(name string) resource.TestCheckFunc { return func(s *terraform.State) error { // Ensure we have enough information in state to look up in API rs, ok := s.RootModule().Resources[name] @@ -671,6 +760,66 @@ func TestAccAzureRMVirtualMachine_windowsLicenseType(t *testing.T) { }) } +func testLookupAzureRMVirtualMachineManagedDiskID(vm *compute.VirtualMachine, diskName string, managedDiskID *string) resource.TestCheckFunc { + return func(s *terraform.State) error { + if osd := vm.StorageProfile.OsDisk; osd != nil { + if strings.EqualFold(*osd.Name, diskName) { + if osd.ManagedDisk != nil { + id, err := findAzureRMVirtualMachineManagedDiskID(osd.ManagedDisk) + if err != nil { + return fmt.Errorf("Unable to parse Managed Disk ID for OS Disk %s, %s", diskName, err) + } + *managedDiskID = id + return nil + } + } + } + + for _, dataDisk := range *vm.StorageProfile.DataDisks { + if strings.EqualFold(*dataDisk.Name, diskName) { + if dataDisk.ManagedDisk != nil { + id, err := findAzureRMVirtualMachineManagedDiskID(dataDisk.ManagedDisk) + if err != nil { + return fmt.Errorf("Unable to parse Managed Disk ID for Data Disk %s, %s", diskName, err) + } + *managedDiskID = id + return nil + } + } + } + + return fmt.Errorf("Unable to locate disk %s on vm %s", diskName, vm.Name) + } +} + +func findAzureRMVirtualMachineManagedDiskID(md *compute.ManagedDiskParameters) (string, error) { + _, err := parseAzureResourceID(*md.ID) + if err != nil { + return "", err + } + return *md.ID, nil +} + +func testGetAzureRMVirtualMachineManagedDisk(managedDiskID *string) (*disk.Model, error) { + armID, err := parseAzureResourceID(*managedDiskID) + if err != nil { + return nil, fmt.Errorf("Unable to parse Managed Disk ID %s, %s", *managedDiskID, err) + } + name := armID.Path["disks"] + resourceGroup := armID.ResourceGroup + conn := testAccProvider.Meta().(*ArmClient).diskClient + d, err := conn.Get(resourceGroup, name) + //check status first since sdk client returns error if not 200 + if d.Response.StatusCode == http.StatusNotFound { + return &d, nil + } + if err != nil { + return nil, err + } + + return &d, nil +} + var testAccAzureRMVirtualMachine_basicLinuxMachine = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -744,7 +893,7 @@ resource "azurerm_virtual_machine" "test" { } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -760,7 +909,7 @@ resource "azurerm_virtual_machine" "test" { } ` -var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk = ` +var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US 2" @@ -807,18 +956,85 @@ resource "azurerm_virtual_machine" "test" { } storage_os_disk { - name = "myosdisk1" + name = "osd-%d" caching = "ReadWrite" create_option = "FromImage" - disk_size_gb = "45" - - managed_disk { - storage_account_type = "Standard_LRS" - } + disk_size_gb = "10" + managed_disk_type = "Standard_LRS" } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags { + environment = "Production" + cost-center = "Ops" + } +} +` + +var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "West US 2" + 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 2" + 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_virtual_machine" "test" { + name = "acctvm-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_D1_v2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "14.04.2-LTS" + version = "latest" + } + + storage_os_disk { + name = "osd-%d" + caching = "ReadWrite" + create_option = "FromImage" + disk_size_gb = "10" + } + + os_profile { + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -890,14 +1106,11 @@ resource "azurerm_virtual_machine" "test" { } storage_os_disk { - name = "myosdisk1" + name = "osd-%d" caching = "ReadWrite" create_option = "FromImage" disk_size_gb = "10" - - managed_disk { - storage_account_type = "Standard_LRS" - } + managed_disk_type = "Standard_LRS" } storage_data_disk { @@ -905,13 +1118,11 @@ resource "azurerm_virtual_machine" "test" { create_option = "Attach" disk_size_gb = "1" lun = 0 - managed_disk = { - managed_disk_id = "${azurerm_managed_disk.test.id}" - } + managed_disk_id = "${azurerm_managed_disk.test.id}" } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -1000,7 +1211,7 @@ resource "azurerm_virtual_machine" "test" { } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -1105,7 +1316,87 @@ resource "azurerm_virtual_machine" "test" { delete_data_disks_on_termination = true os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags { + environment = "Production" + cost-center = "Ops" + } +} +` + +var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksBefore = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "West US 2" + 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 2" + 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_virtual_machine" "test" { + name = "acctvm-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_D1_v2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "14.04.2-LTS" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + } + + delete_os_disk_on_termination = true + + storage_data_disk { + name = "mydatadisk1" + disk_size_gb = "1" + create_option = "Empty" + lun = 0 + } + + delete_data_disks_on_termination = true + + os_profile { + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -1177,6 +1468,39 @@ resource "azurerm_storage_container" "test" { } ` +var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksAfter = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "West US 2" + 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 2" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + } +} +` + var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1228,6 +1552,39 @@ resource "azurerm_storage_container" "test" { } ` +var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM_managedDisk = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "West US 2" + 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 2" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + } +} +` + var testAccAzureRMVirtualMachine_withDataDisk = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1309,7 +1666,7 @@ resource "azurerm_virtual_machine" "test" { } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -1325,7 +1682,7 @@ resource "azurerm_virtual_machine" "test" { } ` -var testAccAzureRMVirtualMachine_withDataDisk_managedDisk = ` +var testAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US 2" @@ -1362,7 +1719,86 @@ resource "azurerm_virtual_machine" "test" { location = "West US 2" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_DS1_v2" + vm_size = "Standard_D1_v2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "14.04.2-LTS" + version = "latest" + } + + storage_os_disk { + name = "osd-%d" + caching = "ReadWrite" + create_option = "FromImage" + managed_disk_type = "Standard_LRS" + } + + storage_data_disk { + name = "dtd-%d" + disk_size_gb = "1023" + create_option = "Empty" + caching = "ReadWrite" + lun = 0 + managed_disk_type = "Standard_LRS" + } + + os_profile { + computer_name = "hn%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags { + environment = "Production" + cost-center = "Ops" + } +} +` + +var testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "West US 2" + 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 2" + 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_virtual_machine" "test" { + name = "acctvm-%d" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_D1_v2" storage_image_reference { publisher = "Canonical" @@ -1375,26 +1811,18 @@ resource "azurerm_virtual_machine" "test" { name = "myosdisk1" caching = "ReadWrite" create_option = "FromImage" - - managed_disk { - storage_account_type = "Standard_LRS" - } } storage_data_disk { name = "mydatadisk1" - disk_size_gb = "1023" + disk_size_gb = "1" create_option = "Empty" caching = "ReadWrite" lun = 0 - - managed_disk { - storage_account_type = "Premium_LRS" - } } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -1482,79 +1910,7 @@ resource "azurerm_virtual_machine" "test" { } os_profile { - computer_name = "hostname%d" - admin_username = "testadmin" - admin_password = "Password1234!" - } - - os_profile_linux_config { - disable_password_authentication = false - } - - tags { - environment = "Production" - } -} -` - -var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated_managedDisk = ` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "West US 2" -} - -resource "azurerm_virtual_network" "test" { - name = "acctvn-%d" - address_space = ["10.0.0.0/16"] - location = "West US 2" - 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 2" - 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_virtual_machine" "test" { - name = "acctvm-%d" - location = "West US 2" - 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 = "Canonical" - offer = "UbuntuServer" - sku = "14.04.2-LTS" - version = "latest" - } - - storage_os_disk { - name = "myosdisk1" - caching = "ReadWrite" - create_option = "FromImage" - - managed_disk { - storage_account_type = "Premium_LRS" - } - } - - os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -1641,75 +1997,7 @@ resource "azurerm_virtual_machine" "test" { } os_profile { - computer_name = "hostname%d" - admin_username = "testadmin" - admin_password = "Password1234!" - } - - os_profile_linux_config { - disable_password_authentication = false - } -} -` - -var testAccAzureRMVirtualMachine_updatedLinuxMachine_managedDisk = ` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "West US 2" -} - -resource "azurerm_virtual_network" "test" { - name = "acctvn-%d" - address_space = ["10.0.0.0/16"] - location = "West US 2" - 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 2" - 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_virtual_machine" "test" { - name = "acctvm-%d" - location = "West US 2" - 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 = "Canonical" - offer = "UbuntuServer" - sku = "14.04.2-LTS" - version = "latest" - } - - storage_os_disk { - name = "myosdisk1" - caching = "ReadWrite" - create_option = "FromImage" - - managed_disk { - storage_account_type = "Premium_LRS" - } - } - - os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -2150,7 +2438,7 @@ var testAccAzureRMVirtualMachine_withAvailabilitySet = ` } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -2241,7 +2529,7 @@ var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -2410,7 +2698,7 @@ resource "azurerm_virtual_machine" "test" { } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -2500,7 +2788,7 @@ resource "azurerm_virtual_machine" "test" { } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -2589,7 +2877,7 @@ resource "azurerm_virtual_machine" "test" { } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -2763,7 +3051,7 @@ resource "azurerm_virtual_machine" "test" { } os_profile { - computer_name = "hostname%d" + computer_name = "hn%d" admin_username = "testadmin" admin_password = "Password1234!" } From 8fa69da1c8ce27e0f8af909aac9bd298e279d85a Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Sun, 5 Mar 2017 18:05:36 -0800 Subject: [PATCH 019/107] re-added arm/disk after merge --- vendor/vendor.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vendor/vendor.json b/vendor/vendor.json index d3b3f93c5..ef9ea1821 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -50,6 +50,14 @@ "version": "v8.1.0-beta", "versionExact": "v8.1.0-beta" }, + { + "checksumSHA1": "iAZi+Mh1Tivk3bdBbAEz+bd5nPg=", + "path": "github.com/Azure/azure-sdk-for-go/arm/disk", + "revision": "ecf40e315d5ab0ca6d7b3b7f7fbb5c1577814813", + "revisionTime": "2017-03-02T00:14:02Z", + "version": "v8.1.0-beta", + "versionExact": "v8.1.0-beta" + }, { "checksumSHA1": "ro1i9qoJcSgbWgV7D93wXhBwoL8=", "comment": "v2.1.1-beta-8-gca4d906", From c2565497e6887f6b41c15912fea4ae116b95bcdf Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Sun, 5 Mar 2017 18:07:19 -0800 Subject: [PATCH 020/107] removed TF_ACC setter --- .../azurerm/resource_arm_virtual_machine_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go index 72984afd5..bd1421846 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go @@ -7,11 +7,10 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/arm/compute" + "github.com/Azure/azure-sdk-for-go/arm/disk" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" - "os" - "github.com/Azure/azure-sdk-for-go/arm/disk" ) func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { @@ -358,7 +357,7 @@ func TestAccAzureRMVirtualMachine_deleteManagedDiskOptOut(t *testing.T) { Steps: []resource.TestStep{ { Destroy: false, - Config: preConfig, + Config: preConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), testLookupAzureRMVirtualMachineManagedDiskID(&vm, "myosdisk1", &osd), @@ -404,7 +403,6 @@ func TestAccAzureRMVirtualMachine_deleteVHDOptIn(t *testing.T) { } func TestAccAzureRMVirtualMachine_deleteManagedDiskOptIn(t *testing.T) { - os.Setenv("TF_ACC", "1") var vm compute.VirtualMachine var osd string var dtd string @@ -418,7 +416,7 @@ func TestAccAzureRMVirtualMachine_deleteManagedDiskOptIn(t *testing.T) { Steps: []resource.TestStep{ { Destroy: false, - Config: preConfig, + Config: preConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), testLookupAzureRMVirtualMachineManagedDiskID(&vm, "myosdisk1", &osd), From a17da26edb12cca6a9ca3036f3865ad023819464 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Sun, 5 Mar 2017 23:42:15 -0800 Subject: [PATCH 021/107] added nil check for DiskSizeGB --- builtin/providers/azurerm/resource_arm_managed_disk.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/providers/azurerm/resource_arm_managed_disk.go b/builtin/providers/azurerm/resource_arm_managed_disk.go index e96506875..3cd677252 100644 --- a/builtin/providers/azurerm/resource_arm_managed_disk.go +++ b/builtin/providers/azurerm/resource_arm_managed_disk.go @@ -235,7 +235,9 @@ func resourceArmManagedDiskDelete(d *schema.ResourceData, meta interface{}) erro func flattenAzureRmManagedDiskProperties(properties *disk.Properties) map[string]interface{} { result := make(map[string]interface{}) result["storage_account_type"] = string(properties.AccountType) - result["disk_size_gb"] = *properties.DiskSizeGB + if properties.DiskSizeGB != nil { + result["disk_size_gb"] = *properties.DiskSizeGB + } if properties.OsType != "" { result["os_type"] = string(properties.OsType) } From eb2bef172f4ed3a40bc28965cd1a0bc5251704e1 Mon Sep 17 00:00:00 2001 From: Brandon Tosch Date: Sun, 5 Mar 2017 23:42:44 -0800 Subject: [PATCH 022/107] updated/added documentation for managed disks --- .../azurerm/r/managed_disk.html.markdown | 107 ++++++++++++++++++ .../azurerm/r/virtual_machine.html.markdown | 104 ++++++++++++++++- website/source/layouts/azurerm.erb | 9 ++ 3 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 website/source/docs/providers/azurerm/r/managed_disk.html.markdown diff --git a/website/source/docs/providers/azurerm/r/managed_disk.html.markdown b/website/source/docs/providers/azurerm/r/managed_disk.html.markdown new file mode 100644 index 000000000..e0a7facc9 --- /dev/null +++ b/website/source/docs/providers/azurerm/r/managed_disk.html.markdown @@ -0,0 +1,107 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_managed_disk" +sidebar_current: "docs-azurerm-resource-managed-disk" +description: |- + Create a Managed Disk. +--- + +# azurerm\_managed\_disk + +Create a managed disk. + +## Example Usage with Create Empty + +``` +resource "azurerm_resource_group" "test" { + name = "acctestrg" + location = "West US 2" +} + +resource "azurerm_managed_disk" "test" { + name = "acctestmd" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "1" + + tags { + environment = "staging" + } +} +``` + +## Example Usage with Create Copy + +``` +resource "azurerm_resource_group" "test" { + name = "acctestrg" + location = "West US 2" +} + +resource "azurerm_managed_disk" "source" { + name = "acctestmd1" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "1" + + tags { + environment = "staging" + } +} + +resource "azurerm_managed_disk" "copy" { + name = "acctestmd2" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Copy" + source_resource_id = "${azurerm_managed_disk.source.id}" + disk_size_gb = "1" + + tags { + environment = "staging" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the managed disk. Changing this forces a + new resource to be created. +* `resource_group_name` - (Required) The name of the resource group in which to create + the managed disk. +* `location` - (Required) Specified the supported Azure location where the resource exists. + Changing this forces a new resource to be created. +* `storage_account_type` - (Required) The type of storage to use for the managed disk. + Allowable values are `Standard_LRS` or `Premium_LRS`. +* `create_option` - (Required) The method to use when creating the managed disk. + * `Import` - Import a VHD file in to the managed disk (VHD specified with `source_uri`). + * `Empty` - Create an empty managed disk. + * `Copy` - Copy an existing managed disk or snapshot (specified with `source_resource_id`). +* `source_uri` - (Optional) URI to a valid VHD file to be used when `create_option` is `Import`. +* `source_resource_id` - (Optional) ID of an existing managed disk to copy when `create_option` is `Copy`. +* `os_type` - (Optional) Specify a value when the source of an `Import` or `Copy` + operation targets a source that contains an operating system. Valid values are `Linux` or `Windows` +* `disk_size_gb` - (Required) Specifies the size of the managed disk to create in gigabytes. + If `create_option` is `Copy`, then the value must be equal to or greater than the source's size. +* `tags` - (Optional) A mapping of tags to assign to the resource. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The managed disk ID. + +## Import + +Managed Disks can be imported using the `resource id`, e.g. + +``` +terraform import azurerm_managed_disk.test /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.compute/disks/manageddisk1 +``` diff --git a/website/source/docs/providers/azurerm/r/virtual_machine.html.markdown b/website/source/docs/providers/azurerm/r/virtual_machine.html.markdown index baf478bd2..53763254f 100644 --- a/website/source/docs/providers/azurerm/r/virtual_machine.html.markdown +++ b/website/source/docs/providers/azurerm/r/virtual_machine.html.markdown @@ -196,6 +196,102 @@ resource "azurerm_virtual_machine" "test" { } ``` +## Example Usage with Managed Disks + +``` +resource "azurerm_resource_group" "test" { + name = "acctestrg" + location = "West US 2" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn" + address_space = ["10.0.0.0/16"] + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "acctsub" + 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" + location = "West US 2" + 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_managed_disk" "test" { + name = "datadisk_existing" + location = "West US 2" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "1023" +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm" + location = "West US 2" + 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 = "Canonical" + offer = "UbuntuServer" + sku = "14.04.2-LTS" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + managed_disk_type = "Standard_LRS" + } + + storage_data_disk { + name = "datadisk_new" + managed_disk_type = "Standard_LRS" + create_option = "Empty" + lun = 0 + disk_size_gb = "1023" + } + + storage_data_disk { + name = "${azurerm_managed_disk.test.name}" + managed_disk_id = "${azurerm_managed_disk.test.id}" + create_option = "Attach" + lun = 1 + disk_size_gb = "${azurerm_managed_disk.test.disk_size_gb}" + } + + os_profile { + computer_name = "hostname" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags { + environment = "staging" + } +} +``` + ## Argument Reference The following arguments are supported: @@ -245,7 +341,9 @@ For more information on the different example configurations, please check out t `storage_os_disk` supports the following: * `name` - (Required) Specifies the disk name. -* `vhd_uri` - (Required) Specifies the vhd uri. Changing this forces a new resource to be created. +* `vhd_uri` - (Optional) Specifies the vhd uri. Changing this forces a new resource to be created. Cannot be used with managed disks. +* `managed_disk_type` - (Optional) Specifies the type of managed disk to create. Value you must be either `Standard_LRS` or `Premium_LRS`. Cannot be used when `vhd_uri` is specified. +* `managed_disk_id` - (Optional) Specifies an existing managed disk to use by id. Can only be used when `create_option` is `Attach`. Cannot be used when `vhd_uri` is specified. * `create_option` - (Required) Specifies how the virtual machine should be created. Possible values are `attach` and `FromImage`. * `caching` - (Optional) Specifies the caching requirements. * `image_uri` - (Optional) Specifies the image_uri in the form publisherName:offer:skus:version. `image_uri` can also specify the [VHD uri](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-cli-deploy-templates/#create-a-custom-vm-image) of a custom VM image to clone. When cloning a custom disk image the `os_type` documented below becomes required. @@ -255,7 +353,9 @@ For more information on the different example configurations, please check out t `storage_data_disk` supports the following: * `name` - (Required) Specifies the name of the data disk. -* `vhd_uri` - (Required) Specifies the uri of the location in storage where the vhd for the virtual machine should be placed. +* `vhd_uri` - (Optional) Specifies the uri of the location in storage where the vhd for the virtual machine should be placed. Cannot be used with managed disks. +* `managed_disk_type` - (Optional) Specifies the type of managed disk to create. Value you must be either `Standard_LRS` or `Premium_LRS`. Cannot be used when `vhd_uri` is specified. +* `managed_disk_id` - (Optional) Specifies an existing managed disk to use by id. Can only be used when `create_option` is `Attach`. Cannot be used when `vhd_uri` is specified. * `create_option` - (Required) Specifies how the data disk should be created. * `disk_size_gb` - (Required) Specifies the size of the data disk in gigabytes. * `caching` - (Optional) Specifies the caching requirements. diff --git a/website/source/layouts/azurerm.erb b/website/source/layouts/azurerm.erb index e0d2e0541..eeff4ef23 100644 --- a/website/source/layouts/azurerm.erb +++ b/website/source/layouts/azurerm.erb @@ -157,6 +157,15 @@ + > + Managed Disk Resources + + + > Network Resources