-
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
[MS] Added ARM Image resource and made VM managed disks worked with custom images #14588
Conversation
…er items based on review notes
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.
Hi @echuvyrov
Thanks for the work here - left a few comments inline to have a think about before we merge this. It's very close though
Thanks
Paul
.vscode/settings.json
Outdated
@@ -0,0 +1,3 @@ | |||
// Place your settings in this file to overwrite default and user settings. |
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.
Please remove this file
}, | ||
|
||
"os_disk": { | ||
Type: schema.TypeSet, |
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.
As there is only 1 of these allowed, I don't believe this needs to be a Set
|
||
func flattenAzureRmSourceVMProperties(d *schema.ResourceData, properties *compute.SubResource) { | ||
if properties.ID != nil { | ||
d.Set("source_virtual_machine_id", *properties.ID) |
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.
You don't need to dereference - d.Set does this in a safe manner. Right now, if ID was nil, this would panic
osDisk := &compute.ImageOSDisk{} | ||
disks := d.Get("os_disk").(*schema.Set).List() | ||
|
||
if len(disks) > 0 { |
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.
wouldn't a range work here? We could loop over the items in the list - if it's empty then it just passes through
@@ -1370,18 +1394,35 @@ func expandAzureRmVirtualMachineImageReference(d *schema.ResourceData) (*compute | |||
storageImageRefs := d.Get("storage_image_reference").(*schema.Set).List() | |||
|
|||
storageImageRef := storageImageRefs[0].(map[string]interface{}) | |||
imageReference := compute.ImageReference{} | |||
imageID := "" |
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 don't think imageID and publisher need to be initialised here
Version: &version, | ||
}, nil | ||
//BEGIN: code to be removed after GH-13016 is merged | ||
if imageID != "" && publisher != "" { |
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.
Can this ever be true? You are setting publisher and imageID to "" - then using an if / else to hydrate the struct.
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccAzureRMManagedImage_standaloneImage(t *testing.T) { |
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'd like to see an Import test to show that functionality works as expected
@stack72 I made the changes requested and updated the docs. Note that the import test still relies on a pre-existing .vhd, which I made available publicly but that test would still fail for subscriptions other than mine. Not sure how I can work around this: per this doc, the image can only be created "using the specified blob, snapshot, managed disk, or existing virtual machine." |
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.
Hi @echuvyrov
Thanks for pushing those updates - I've reviewed and left some comments in-line - but this is looking good :)
Regarding the image - given we need these tests to pass in any subscription, rather than relying on long-running resources I'd suggest it'd be better to spin up a VM and generalise it as part of the test - what do you think?
Thanks!
@@ -88,6 +88,7 @@ func Provider() terraform.ResourceProvider { | |||
"azurerm_lb_rule": resourceArmLoadBalancerRule(), | |||
|
|||
"azurerm_managed_disk": resourceArmManagedDisk(), | |||
"azurerm_image": resourceArmManagedImage(), |
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.
minor given this is an image
and not an managed image
could we rename the class to match?
return &schema.Resource{ | ||
Create: resourceArmManagedImageCreate, | ||
Read: resourceArmManagedImageRead, | ||
Update: resourceArmManagedImageCreate, |
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.
minor: given this is both Creating and Updating - we normally name this CreateUpdate
ValidateFunc: validation.StringInSlice([]string{ | ||
string(compute.Linux), | ||
string(compute.Windows), | ||
}, true), |
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.
given this is true
(for case insensitivity) I believe this wants a DiffSuppressFunc
here to ignore the casing?
string(compute.None), | ||
string(compute.ReadOnly), | ||
string(compute.ReadWrite), | ||
}, true), |
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.
given this is true
(for case insensitivity) I believe this wants a DiffSuppressFunc
here to ignore the casing?
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.
(same question about default value here)
osDisk.OsType = osType | ||
} | ||
|
||
if v := d.Get("os_disk_os_state").(string); v != "" { |
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.
minor: given there's validation on this - I believe we can make this simpler:
if v, ok := d.Get("os_disk_os_state").(string); ok {
@@ -121,6 +121,7 @@ To make a resource importable, please see the | |||
* azurerm_sql_firewall_rule | |||
* azurerm_storage_account | |||
* azurerm_virtual_network | |||
* azurerm_image |
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.
minor: these are currently sorted alphabetically for easier reading - could we re-order this? :)
* `os_disk_managed_disk_id` - (Optional) Specifies the ID of the managed disk resource that you want to use to create the image. | ||
* `os_disk_blob_uri` - (Optional) Specifies the URI in Azure storage of the blob that you want to use to create the image. | ||
* `os_disk_caching` - (Optional) Specifies the caching mode as 'readonly', 'readwrite', or 'none'. The default is none. | ||
* `os_disk_size_gb` - (Optional) Specifies the size of the image to be created. The target size can't be smaller than the source size. |
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.
rather than prefixing all of these with os_disk
- would it make more sense to put them in an os_disk
block/hash?
<li<%= sidebar_current("docs-azurerm-resource-managed-image") %>> | ||
<a href="#">Managed Image Resources</a> | ||
<ul class="nav nav-visible"> | ||
<li<%= sidebar_current("docs-azurerm-resource-managed-image") %>> |
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.
minor can we remove the word managed
from this section?
Create a custom virtual machine image that can be used to create virtual machines. | ||
--- | ||
|
||
# azurerm\_managed\_image |
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 think this should be azurerm_image
?
--- | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_image" | ||
sidebar_current: "docs-azurerm-resource-managed-image" |
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.
minor can we remove the word managed
from this?
@tombuildsstuff I made the changes requested, and the tests should now be fully self contained as per your suggestion (I stand up a VM, deprovision/generalize it, then grab the .vhd or simply point to that VM). Regarding making "os_disk" a separate block - I went that route during the initial implementation, but @stack72 pointed out that since there will always be just one "os_disk" resource, it should be at the root level. Let me know if I misunderstood and thanks for your timely and thorough reviews. |
Moved here per 0.10 guidelines |
Thanks so much @echuvyrov :) |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
The code includes a new ARM Image resource, which enables users to create VMs from custom image supplied in a storage account or from an existing VM (VM must be deprovisioned and generalized). Note that two acceptance tests currently require subscription-specific information (VHD has to be in a user account or VM must be generalized). This information would need to be provided by the person running the tests - open to ideas on improving this.