Skip to content

Commit

Permalink
Merge pull request #161 from terraform-providers/vmss-plan
Browse files Browse the repository at this point in the history
`azurerm_virtual_machine_scale_set`: adding a `plan` block for Marketplace images
  • Loading branch information
tombuildsstuff authored Jul 17, 2017
2 parents 9b9971a + 27b638f commit b9ef45c
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 3 deletions.
66 changes: 66 additions & 0 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,30 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
Set: resourceArmVirtualMachineScaleSetStorageProfileImageReferenceHash,
},

"plan": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},

"publisher": {
Type: schema.TypeString,
Required: true,
},

"product": {
Type: schema.TypeString,
Required: true,
},
},
},
},

"extension": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -545,6 +569,16 @@ func resourceArmVirtualMachineScaleSetCreate(d *schema.ResourceData, meta interf
Sku: sku,
VirtualMachineScaleSetProperties: &scaleSetProps,
}

if _, ok := d.GetOk("plan"); ok {
plan, err := expandAzureRmVirtualMachineScaleSetPlan(d)
if err != nil {
return err
}

scaleSetParams.Plan = plan
}

_, vmError := vmScaleSetClient.CreateOrUpdate(resGroup, name, scaleSetParams, make(chan struct{}))
vmErr := <-vmError
if vmErr != nil {
Expand Down Expand Up @@ -653,6 +687,12 @@ func resourceArmVirtualMachineScaleSetRead(d *schema.ResourceData, meta interfac
d.Set("extension", extension)
}

if resp.Plan != nil {
if err := d.Set("plan", flattenAzureRmVirtualMachineScaleSetPlan(resp.Plan)); err != nil {
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Scale Set Plan. Error: %#v", err)
}
}

flattenAndSetTags(d, resp.Tags)

return nil
Expand Down Expand Up @@ -1475,3 +1515,29 @@ func expandAzureRMVirtualMachineScaleSetExtensions(d *schema.ResourceData) (*com
Extensions: &resources,
}, nil
}

func expandAzureRmVirtualMachineScaleSetPlan(d *schema.ResourceData) (*compute.Plan, error) {
planConfigs := d.Get("plan").(*schema.Set).List()

planConfig := planConfigs[0].(map[string]interface{})

publisher := planConfig["publisher"].(string)
name := planConfig["name"].(string)
product := planConfig["product"].(string)

return &compute.Plan{
Publisher: &publisher,
Name: &name,
Product: &product,
}, nil
}

func flattenAzureRmVirtualMachineScaleSetPlan(plan *compute.Plan) []interface{} {
result := make(map[string]interface{})

result["name"] = *plan.Name
result["publisher"] = *plan.Publisher
result["product"] = *plan.Product

return []interface{}{result}
}
88 changes: 88 additions & 0 deletions azurerm/resource_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ func TestAccAzureRMVirtualMachineScaleSet_basicLinux_disappears(t *testing.T) {
})
}

func TestAccAzureRMVirtualMachineScaleSet_planManagedDisk(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMVirtualMachineScaleSet_planManagedDisk(ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
),
},
},
})
}

func TestAccAzureRMVirtualMachineScaleSet_loadBalancer(t *testing.T) {
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSetLoadbalancerTemplate, ri, ri, ri, ri, ri, ri, ri)
Expand Down Expand Up @@ -1607,3 +1625,73 @@ resource "azurerm_virtual_machine_scale_set" "test" {
}
`, ri, ri, ri, ri, ri, ri, ri, ri)
}

func testAccAzureRMVirtualMachineScaleSet_planManagedDisk(rInt int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US 2"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctvmss-%d"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
sku {
name = "Standard_D1_v2"
tier = "Standard"
capacity = 2
}
os_profile {
computer_name_prefix = "testvm-%d"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
network_profile {
name = "TestNetworkProfile-%d"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
}
}
plan {
name = "os"
product = "rancheros"
publisher = "rancher"
}
storage_profile_os_disk {
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
storage_profile_image_reference {
publisher = "rancher"
offer = "rancheros"
sku = "os"
version = "latest"
}
}
`, rInt, rInt, rInt, rInt, rInt, rInt)
}
4 changes: 2 additions & 2 deletions website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ For more information on the different example configurations, please check out t
`Plan` supports the following:

* `name` - (Required) Specifies the name of the image from the marketplace.
* `publisher` - (Optional) Specifies the publisher of the image.
* `product` - (Optional) Specifies the product of the image from the marketplace.
* `publisher` - (Required) Specifies the publisher of the image.
* `product` - (Required) Specifies the product of the image from the marketplace.

`boot_diagnostics` supports the following:

Expand Down
9 changes: 8 additions & 1 deletion website/docs/r/virtual_machine_scale_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
lun = 0
caching = "ReadWrite"
create_option = "Empty"
disk_size_gb = 10
disk_size_gb = 10
}
os_profile {
Expand Down Expand Up @@ -256,6 +256,7 @@ The following arguments are supported:
* `storage_profile_data_disk` - (Optional) A storage profile data disk block as documented below
* `storage_profile_image_reference` - (Optional) A storage profile image reference block as documented below.
* `extension` - (Optional) Can be specified multiple times to add extension profiles to the scale set. Each `extension` block supports the fields documented below.
* `plan` - (Optional) A plan block as documented below.
* `tags` - (Optional) A mapping of tags to assign to the resource.


Expand Down Expand Up @@ -360,6 +361,12 @@ The following arguments are supported:
* `settings` - (Required) The settings passed to the extension, these are specified as a JSON object in a string.
* `protected_settings` - (Optional) The protected_settings passed to the extension, like settings, these are specified as a JSON object in a string.

`plan` supports the following:

* `name` - (Required) Specifies the name of the image from the marketplace.
* `publisher` - (Required) Specifies the publisher of the image.
* `product` - (Required) Specifies the product of the image from the marketplace.

## Attributes Reference

The following attributes are exported:
Expand Down

0 comments on commit b9ef45c

Please sign in to comment.