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

Add license_type to linux_virtual_machine #10776

Merged
merged 11 commits into from
Mar 4, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ func resourceLinuxVirtualMachine() *schema.Resource {

"identity": virtualMachineIdentitySchema(),

"license_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"RHEL_BYOS",
"SLES_BYOS",
}, false),
},

"max_bid_price": {
Type: schema.TypeFloat,
Optional: true,
Expand Down Expand Up @@ -401,6 +410,10 @@ func resourceLinuxVirtualMachineCreate(d *schema.ResourceData, meta interface{})
Tags: tags.Expand(t),
}

if v, ok := d.GetOk("license_type"); ok {
params.VirtualMachineProperties.LicenseType = utils.String(v.(string))
}

if encryptionAtHostEnabled, ok := d.GetOk("encryption_at_host_enabled"); ok {
params.VirtualMachineProperties.SecurityProfile = &compute.SecurityProfile{
EncryptionAtHost: utils.Bool(encryptionAtHostEnabled.(bool)),
Expand Down Expand Up @@ -556,6 +569,12 @@ func resourceLinuxVirtualMachineRead(d *schema.ResourceData, meta interface{}) e
}
d.Set("availability_set_id", availabilitySetId)

licenseType := ""
if props.LicenseType != nil {
licenseType = *props.LicenseType
}
d.Set("license_type", licenseType)

if err := d.Set("boot_diagnostics", flattenBootDiagnostics(props.DiagnosticsProfile)); err != nil {
return fmt.Errorf("setting `boot_diagnostics`: %+v", err)
}
Expand Down Expand Up @@ -759,6 +778,14 @@ func resourceLinuxVirtualMachineUpdate(d *schema.ResourceData, meta interface{})
update.Identity = identity
}

if d.HasChange("license_type") {
shouldUpdate = true

if v, ok := d.GetOk("license_type"); ok {
update.LicenseType = utils.String(v.(string))
}
}

if d.HasChange("dedicated_host_id") {
shouldUpdate = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ func TestAccLinuxVirtualMachine_otherCustomData(t *testing.T) {
})
}

func TestAccLinuxVirtualMachine_otherLicenseType(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test")
r := LinuxVirtualMachineResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.otherLicenseType(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("license_type").HasValue("SLES_BYOS"),
),
},
data.ImportStep(),
})
}

func TestAccLinuxVirtualMachine_otherPrioritySpot(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test")
r := LinuxVirtualMachineResource{}
Expand Down Expand Up @@ -979,6 +995,41 @@ resource "azurerm_linux_virtual_machine" "test" {
`, r.template(data), data.RandomInteger)
}

func (r LinuxVirtualMachineResource) otherLicenseType(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_linux_virtual_machine" "test" {
name = "acctestVM-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
size = "Standard_F2"
admin_username = "adminuser"
license_type = "SLES_BYOS"
network_interface_ids = [
azurerm_network_interface.test.id,
]
admin_ssh_key {
username = "adminuser"
public_key = local.first_public_key
}
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}
`, r.template(data), data.RandomInteger)
}

func (r LinuxVirtualMachineResource) otherPrioritySpot(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/linux_virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ The following arguments are supported:

* `location` - (Required) The Azure location where the Linux Virtual Machine should exist. Changing this forces a new resource to be created.

* `license_type` - (Optional) Specifies the BYOL Type for this Virtual Machine. Possible values are `RHEL_BYOS` and `SLES_BYOS`.

* `name` - (Required) The name of the Linux Virtual Machine. Changing this forces a new resource to be created.

* `network_interface_ids` - (Required). A list of Network Interface ID's which should be attached to this Virtual Machine. The first Network Interface ID in this list will be the Primary Network Interface on the Virtual Machine.
Expand Down