Merge pull request #12455 from brandontosch/brandontosch/GH-11874
AzureRM Managed Disks
This commit is contained in:
commit
6f2551ec33
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -245,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
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAccAzureRMManagedDisk_importEmpty(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
config := fmt.Sprintf(testAccAzureRMManagedDisk_empty, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: config,
|
||||
},
|
||||
{
|
||||
ResourceName: "azurerm_managed_disk.test",
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -19,11 +19,39 @@ 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,
|
||||
ImportStateVerifyIgnore: []string{
|
||||
"delete_data_disks_on_termination",
|
||||
"delete_os_disk_on_termination",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMVirtualMachine_importBasic_managedDisk(t *testing.T) {
|
||||
resourceName := "azurerm_virtual_machine.test"
|
||||
|
||||
ri := acctest.RandInt()
|
||||
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,
|
||||
},
|
||||
|
||||
{
|
||||
ResourceName: resourceName,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
|
|
|
@ -85,6 +85,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(),
|
||||
|
|
|
@ -0,0 +1,238 @@
|
|||
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"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func resourceArmManagedDisk() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceArmManagedDiskCreate,
|
||||
Read: resourceArmManagedDiskRead,
|
||||
Update: resourceArmManagedDiskCreate,
|
||||
Delete: resourceArmManagedDiskDelete,
|
||||
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,
|
||||
ForceNew: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{
|
||||
string(disk.Import),
|
||||
string(disk.Empty),
|
||||
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,
|
||||
},
|
||||
|
||||
"os_type": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{
|
||||
string(disk.Windows),
|
||||
string(disk.Linux),
|
||||
}, true),
|
||||
},
|
||||
|
||||
"disk_size_gb": {
|
||||
Type: schema.TypeInt,
|
||||
Required: 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 resourceArmManagedDiskCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
diskClient := client.diskClient
|
||||
|
||||
log.Printf("[INFO] preparing arguments for Azure ARM Managed 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)
|
||||
|
||||
createDisk.Properties = &disk.Properties{
|
||||
AccountType: disk.StorageAccountTypes(storageAccountType),
|
||||
OsType: disk.OperatingSystemTypes(osType),
|
||||
}
|
||||
|
||||
if v := d.Get("disk_size_gb"); v != 0 {
|
||||
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, string(disk.Import)) {
|
||||
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`", 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)
|
||||
}
|
||||
}
|
||||
|
||||
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 Managed Disk %s (resource group %s) ID", name, resGroup)
|
||||
}
|
||||
|
||||
d.SetId(*read.ID)
|
||||
|
||||
return resourceArmManagedDiskRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceArmManagedDiskRead(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 Managed 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 {
|
||||
flattenAzureRmManagedDiskProperties(d, resp.Properties)
|
||||
}
|
||||
|
||||
if resp.CreationData != nil {
|
||||
flattenAzureRmManagedDiskCreationData(d, resp.CreationData)
|
||||
}
|
||||
|
||||
flattenAndSetTags(d, resp.Tags)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceArmManagedDiskDelete(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 flattenAzureRmManagedDiskProperties(d *schema.ResourceData, properties *disk.Properties) {
|
||||
d.Set("storage_account_type", string(properties.AccountType))
|
||||
if properties.DiskSizeGB != nil {
|
||||
d.Set("disk_size_gb", *properties.DiskSizeGB)
|
||||
}
|
||||
if properties.OsType != "" {
|
||||
d.Set("os_type", string(properties.OsType))
|
||||
}
|
||||
}
|
||||
|
||||
func flattenAzureRmManagedDiskCreationData(d *schema.ResourceData, creationData *disk.CreationData) {
|
||||
d.Set("create_option", string(creationData.CreateOption))
|
||||
if creationData.SourceURI != nil {
|
||||
d.Set("source_uri", *creationData.SourceURI)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,321 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAzureRMManagedDisk_empty(t *testing.T) {
|
||||
var d disk.Model
|
||||
ri := acctest.RandInt()
|
||||
config := fmt.Sprintf(testAccAzureRMManagedDisk_empty, 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, true),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
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, true),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
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, true),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
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, true),
|
||||
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", "1"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_managed_disk.test", "storage_account_type", string(disk.StandardLRS)),
|
||||
),
|
||||
},
|
||||
{
|
||||
Config: postConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
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", "2"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_managed_disk.test", "storage_account_type", string(disk.PremiumLRS)),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
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 {
|
||||
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 && 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
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testCheckAzureRMManagedDiskDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*ArmClient).diskClient
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "azurerm_managed_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("Managed Disk still exists: \n%#v", resp.Properties)
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
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 = "Standard_LRS"
|
||||
create_option = "Empty"
|
||||
disk_size_gb = "1"
|
||||
|
||||
tags {
|
||||
environment = "acctest"
|
||||
cost-center = "ops"
|
||||
}
|
||||
}`
|
||||
|
||||
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"
|
||||
disk_size_gb = "45"
|
||||
|
||||
tags {
|
||||
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 = "2"
|
||||
|
||||
tags {
|
||||
environment = "acctest"
|
||||
}
|
||||
}`
|
|
@ -1,7 +1,6 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -188,10 +187,8 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
|
|||
}
|
||||
|
||||
// Create
|
||||
cancelCtx, cancelFunc := context.WithTimeout(client.StopContext, 1*time.Hour)
|
||||
_, createErr := storageClient.Create(
|
||||
resourceGroupName, storageAccountName, opts, cancelCtx.Done())
|
||||
cancelFunc()
|
||||
resourceGroupName, storageAccountName, opts, make(chan struct{}))
|
||||
|
||||
// The only way to get the ID back apparently is to read the resource again
|
||||
read, err := storageClient.GetProperties(resourceGroupName, storageAccountName)
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/Azure/azure-sdk-for-go/arm/compute"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/helper/validation"
|
||||
riviera "github.com/jen20/riviera/azure"
|
||||
)
|
||||
|
||||
|
@ -141,10 +142,29 @@ func resourceArmVirtualMachine() *schema.Resource {
|
|||
|
||||
"vhd_uri": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"managed_disk_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Computed: true,
|
||||
ConflictsWith: []string{"storage_os_disk.vhd_uri"},
|
||||
},
|
||||
|
||||
"managed_disk_type": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ConflictsWith: []string{"storage_os_disk.vhd_uri"},
|
||||
ValidateFunc: validation.StringInSlice([]string{
|
||||
string(compute.PremiumLRS),
|
||||
string(compute.StandardLRS),
|
||||
}, true),
|
||||
},
|
||||
|
||||
"image_uri": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -189,7 +209,26 @@ func resourceArmVirtualMachine() *schema.Resource {
|
|||
|
||||
"vhd_uri": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"managed_disk_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Computed: true,
|
||||
ConflictsWith: []string{"storage_data_disk.vhd_uri"},
|
||||
},
|
||||
|
||||
"managed_disk_type": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ConflictsWith: []string{"storage_data_disk.vhd_uri"},
|
||||
ValidateFunc: validation.StringInSlice([]string{
|
||||
string(compute.PremiumLRS),
|
||||
string(compute.StandardLRS),
|
||||
}, true),
|
||||
},
|
||||
|
||||
"create_option": {
|
||||
|
@ -204,9 +243,10 @@ func resourceArmVirtualMachine() *schema.Resource {
|
|||
},
|
||||
|
||||
"disk_size_gb": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ValidateFunc: validateDiskSizeGB,
|
||||
},
|
||||
|
||||
"lun": {
|
||||
|
@ -453,15 +493,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
|
||||
|
@ -685,21 +716,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 {
|
||||
|
@ -707,8 +746,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 Disk VHD: %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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -752,6 +799,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{})
|
||||
|
@ -784,8 +849,9 @@ 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)))
|
||||
}
|
||||
return hashcode.String(buf.String())
|
||||
}
|
||||
|
||||
|
@ -883,7 +949,13 @@ 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_type"] = string(disk.ManagedDisk.StorageAccountType)
|
||||
l["managed_disk_id"] = *disk.ManagedDisk.ID
|
||||
}
|
||||
l["create_option"] = disk.CreateOption
|
||||
l["caching"] = string(disk.Caching)
|
||||
if disk.DiskSizeGB != nil {
|
||||
|
@ -982,7 +1054,13 @@ 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_type"] = string(disk.ManagedDisk.StorageAccountType)
|
||||
result["managed_disk_id"] = *disk.ManagedDisk.ID
|
||||
}
|
||||
result["create_option"] = disk.CreateOption
|
||||
result["caching"] = disk.Caching
|
||||
if disk.DiskSizeGB != nil {
|
||||
|
@ -1157,22 +1235,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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1209,19 +1287,48 @@ func expandAzureRmVirtualMachineDataDisk(d *schema.ResourceData) ([]compute.Data
|
|||
config := disk_config.(map[string]interface{})
|
||||
|
||||
name := config["name"].(string)
|
||||
vhd := config["vhd_uri"].(string)
|
||||
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{
|
||||
Name: &name,
|
||||
Vhd: &compute.VirtualHardDisk{
|
||||
URI: &vhd,
|
||||
},
|
||||
Name: &name,
|
||||
Lun: &lun,
|
||||
CreateOption: compute.DiskCreateOptionTypes(createOption),
|
||||
}
|
||||
|
||||
if vhdURI != "" {
|
||||
data_disk.Vhd = &compute.VirtualHardDisk{
|
||||
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
|
||||
}
|
||||
|
||||
//BEGIN: code to be removed after GH-13016 is merged
|
||||
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)")
|
||||
}
|
||||
//END: code to be removed after GH-13016 is merged
|
||||
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)
|
||||
}
|
||||
|
@ -1303,28 +1410,57 @@ 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)
|
||||
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,
|
||||
Vhd: &compute.VirtualHardDisk{
|
||||
URI: &vhdURI,
|
||||
},
|
||||
Name: &name,
|
||||
CreateOption: compute.DiskCreateOptionTypes(createOption),
|
||||
}
|
||||
|
||||
if v := disk["image_uri"].(string); v != "" {
|
||||
if vhdURI != "" {
|
||||
osDisk.Vhd = &compute.VirtualHardDisk{
|
||||
URI: &vhdURI,
|
||||
}
|
||||
}
|
||||
|
||||
managedDisk := &compute.ManagedDiskParameters{}
|
||||
|
||||
if managedDiskType != "" {
|
||||
managedDisk.StorageAccountType = compute.StorageAccountTypes(managedDiskType)
|
||||
osDisk.ManagedDisk = managedDisk
|
||||
}
|
||||
|
||||
if managedDiskID != "" {
|
||||
managedDisk.ID = &managedDiskID
|
||||
osDisk.ManagedDisk = managedDisk
|
||||
}
|
||||
|
||||
//BEGIN: code to be removed after GH-13016 is merged
|
||||
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)")
|
||||
}
|
||||
//END: code to be removed after GH-13016 is merged
|
||||
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" {
|
||||
|
@ -1334,11 +1470,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
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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,
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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"`
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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",
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
---
|
||||
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.
|
||||
|
||||
For more information on managed disks, such as sizing options and pricing, please check out the
|
||||
[azure documentation](https://docs.microsoft.com/en-us/azure/storage/storage-managed-disks-overview).
|
||||
|
||||
## 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
|
||||
```
|
|
@ -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:
|
||||
|
@ -246,7 +342,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.
|
||||
|
@ -256,7 +354,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.
|
||||
|
|
|
@ -157,6 +157,15 @@
|
|||
</ul>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current(/^docs-azurerm-resource-managed-disk/) %>>
|
||||
<a href="#">Managed Disk Resources</a>
|
||||
<ul class="nav nav-visible">
|
||||
<li<%= sidebar_current("docs-azurerm-resource-managed-disk") %>>
|
||||
<a href="/docs/providers/azurerm/r/managed_disk.html">azurerm_managed_disk</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current(/^docs-azurerm-resource-network/) %>>
|
||||
<a href="#">Network Resources</a>
|
||||
<ul class="nav nav-visible">
|
||||
|
|
Loading…
Reference in New Issue