-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AzureRM Managed Disks #12455
Merged
tombuildsstuff
merged 43 commits into
hashicorp:master
from
brandontosch:brandontosch/GH-11874
Apr 6, 2017
Merged
AzureRM Managed Disks #12455
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
a6d8b45
mcardosos/azure-for-go-sdk/arm/compute@v8.1.0-beta
brandontosch 9f6a7dc
compute managed disk support
brandontosch a3a2c38
make fmt
brandontosch d1bca91
updated other arm/compute references to mcardosos
brandontosch 6379153
provider/azurerm: Bumped AzureRM/compute SDK to v8.1.0-beta
brandontosch 909976e
fixed nil check in resourceArmVirtualMachineStorageOsDiskHash
brandontosch 00df220
fixed nil check in resourceArmVirtualMachineStorageOsDiskHash
brandontosch 5c0b750
acceptance tests for managed disks
brandontosch e761374
fixed postConfig check to verify the corrent vm size
brandontosch b7df7d4
changed DS1 to DS1_v2
brandontosch e3dbe47
Merge branch 'master' into brandontosch/GH-11874
brandontosch 0a07c14
[WIP] arm/disk implementation
brandontosch 2df44e0
[WIP] arm/disk implementation
brandontosch fc3efec
fmt
brandontosch ca6bc88
renamed arm_disk to arm_managed_disk
brandontosch 9158b95
managed disk acceptance tests
brandontosch a084aa0
implemented copy for managed disks
brandontosch ac8eae9
implemented attaching existing managed disks on vm creation
brandontosch 5d915dd
flattened managed disk structure in virtual machine
brandontosch 193c257
Merge branch 'master' into brandontosch/GH-11874
brandontosch 8fa69da
re-added arm/disk after merge
brandontosch c256549
removed TF_ACC setter
brandontosch a17da26
added nil check for DiskSizeGB
brandontosch eb2bef1
updated/added documentation for managed disks
brandontosch fa56000
Merge branch 'master' into brandontosch/GH-11874
brandontosch 972bc08
Removed context timeout due "request cancelled" to acc test failures …
brandontosch a2716f7
Lowered data disk size to decrease provisioning time and cost
brandontosch 91db3e1
Corrected variable reference
edevil 34c0dd7
fixed typo in vm_size
brandontosch 58325b9
Merge pull request #1 from edevil/patch-1
brandontosch dbb4daa
disk_size_gb is required
brandontosch 8f2d2ed
refactored flatten methods to also set values
brandontosch e94c1f7
Added link to official azure documentation
brandontosch 4294754
Corrected error message
brandontosch 7703d6c
Added supported for ConflictsWith for fields within lists/sets
brandontosch 03b8f05
Implemented ConflictsWith for vhd_uri and managed_disk fields
brandontosch 808a9f0
removed commented import
brandontosch a327648
Reverted ConflictsWith fix (moved to separate PR: GH-13019)
brandontosch 0168829
Merge branch 'master' into brandontosch/GH-11874
brandontosch 2ac79c3
trigger ci
brandontosch eb6f36f
Re-added custom conflict validation for managed disks
brandontosch fedb170
added disk_size_gb to config for TestAccAzureRMManagedDisk_import
brandontosch 380f55b
Merge branch 'master' into brandontosch/GH-11874
brandontosch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From looking at the docs it seems the valid disk dizes are:
Shouldn't this be checked here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had actually just moved that function over from the vm resource (was pre-existing, just figured it made more sense to be based out of the new disk resource).
Also, according to some of the Microsoft folks I've been working with, the max size will be increasing to 4TB at some point hopefully soon.. Not sure when exactly, but I'll try and keep an eye out for when that happens and update this accordingly.