Skip to content
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] Adding support for Image Resources and Custom Images with Managed Disks #8

Merged
merged 11 commits into from
Jul 19, 2017
Merged
7 changes: 7 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type ArmClient struct {
vmScaleSetClient compute.VirtualMachineScaleSetsClient
vmImageClient compute.VirtualMachineImagesClient
vmClient compute.VirtualMachinesClient
imageClient compute.ImagesClient

diskClient disk.DisksClient

Expand Down Expand Up @@ -260,6 +261,12 @@ func (c *Config) getArmClient() (*ArmClient, error) {
dkc.Sender = autorest.CreateSender(withRequestLogging())
client.diskClient = dkc

img := compute.NewImagesClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&img.Client)
img.Authorizer = auth
img.Sender = autorest.CreateSender(withRequestLogging())
client.imageClient = img

ehc := eventhub.NewEventHubsClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&ehc.Client)
ehc.Authorizer = auth
Expand Down
48 changes: 48 additions & 0 deletions azurerm/import_arm_image_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMImage_importStandalone(t *testing.T) {
ri := acctest.RandInt()
userName := "testadmin"
password := "Password1234s!"
hostName := fmt.Sprintf("tftestcustomimagesrc%[1]d", ri)
sshPort := "22"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can safely default this field within the testGeneralizeVMImage function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we could. I missed the random seed needed to avoid collisions between host names initially, but now that I put it in, the random seed is needed to generalize the VM since the DNS Name is one of the params to that function now. Open to different ideas here as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, however we should be able to pass in only the username, password, hostname and region - as we can infer the rest from that?

preConfig := testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName)
postConfig := testAccAzureRMImage_standaloneImage_provision(ri, userName, password, hostName)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMImageDestroy,
Steps: []resource.TestStep{
resource.TestStep{
//need to create a vm and then reference it in the image creation
Config: preConfig,
Destroy: false,
Check: resource.ComposeTestCheckFunc(
testCheckAzureVMExists("azurerm_virtual_machine.testsource", true),
testGeneralizeVMImage(fmt.Sprintf("acctestRG-%[1]d", ri), "testsource",
userName, password, hostName, sshPort),
),
},
resource.TestStep{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMImageExists("azurerm_image.test", true),
),
},
resource.TestStep{
ResourceName: "azurerm_image.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_lb_rule": resourceArmLoadBalancerRule(),

"azurerm_managed_disk": resourceArmManagedDisk(),
"azurerm_image": resourceArmImage(),

"azurerm_key_vault": resourceArmKeyVault(),
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
Expand Down
Loading