Skip to content

Commit 79113fb

Browse files
authored
azurerm_dedicated_host - remove None from the license_type property in 5.0 (#32642)
1 parent 466c6ad commit 79113fb

3 files changed

Lines changed: 77 additions & 11 deletions

File tree

internal/services/compute/dedicated_host_resource.go

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2020
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
2121
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
22+
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
2223
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
2324
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate"
2425
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
@@ -29,7 +30,7 @@ import (
2930
//go:generate go run ../../tools/generator-tests resourceidentity -resource-name dedicated_host -service-package-name compute -properties "name" -compare-values "subscription_id:dedicated_host_group_id,resource_group_name:dedicated_host_group_id,host_group_name:dedicated_host_group_id"
3031

3132
func resourceDedicatedHost() *pluginsdk.Resource {
32-
return &pluginsdk.Resource{
33+
resource := &pluginsdk.Resource{
3334
Create: resourceDedicatedHostCreate,
3435
Read: resourceDedicatedHostRead,
3536
Update: resourceDedicatedHostUpdate,
@@ -134,17 +135,29 @@ func resourceDedicatedHost() *pluginsdk.Resource {
134135
Type: pluginsdk.TypeString,
135136
Optional: true,
136137
ValidateFunc: validation.StringInSlice([]string{
137-
// TODO: remove `None` in 4.0 in favour of this field being set to an empty string (since it's optional)
138-
string(dedicatedhosts.DedicatedHostLicenseTypesNone),
139138
string(dedicatedhosts.DedicatedHostLicenseTypesWindowsServerHybrid),
140139
string(dedicatedhosts.DedicatedHostLicenseTypesWindowsServerPerpetual),
141140
}, false),
142-
Default: string(dedicatedhosts.DedicatedHostLicenseTypesNone),
143141
},
144142

145143
"tags": commonschema.Tags(),
146144
},
147145
}
146+
147+
if !features.FivePointOh() {
148+
resource.Schema["license_type"] = &pluginsdk.Schema{
149+
Type: pluginsdk.TypeString,
150+
Optional: true,
151+
ValidateFunc: validation.StringInSlice([]string{
152+
string(dedicatedhosts.DedicatedHostLicenseTypesNone),
153+
string(dedicatedhosts.DedicatedHostLicenseTypesWindowsServerHybrid),
154+
string(dedicatedhosts.DedicatedHostLicenseTypesWindowsServerPerpetual),
155+
}, false),
156+
Default: string(dedicatedhosts.DedicatedHostLicenseTypesNone),
157+
}
158+
}
159+
160+
return resource
148161
}
149162

150163
func resourceDedicatedHostCreate(d *pluginsdk.ResourceData, meta interface{}) error {
@@ -170,12 +183,11 @@ func resourceDedicatedHostCreate(d *pluginsdk.ResourceData, meta interface{}) er
170183
}
171184
}
172185

173-
licenseType := dedicatedhosts.DedicatedHostLicenseTypes(d.Get("license_type").(string))
174186
payload := dedicatedhosts.DedicatedHost{
175187
Location: location.Normalize(d.Get("location").(string)),
176188
Properties: &dedicatedhosts.DedicatedHostProperties{
177189
AutoReplaceOnFailure: pointer.To(d.Get("auto_replace_on_failure").(bool)),
178-
LicenseType: &licenseType,
190+
LicenseType: pointer.To(dedicatedhosts.DedicatedHostLicenseTypesNone),
179191
PlatformFaultDomain: pointer.To(int64(d.Get("platform_fault_domain").(int))),
180192
},
181193
Sku: dedicatedhosts.Sku{
@@ -184,6 +196,10 @@ func resourceDedicatedHostCreate(d *pluginsdk.ResourceData, meta interface{}) er
184196
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
185197
}
186198

199+
if v := d.Get("license_type").(string); v != "" {
200+
payload.Properties.LicenseType = pointer.ToEnum[dedicatedhosts.DedicatedHostLicenseTypes](v)
201+
}
202+
187203
if err := client.CreateOrUpdateCallbackThenPoll(ctx, id, payload, sdk.SetIDAndIdentityCallback(meta, &id, d)); err != nil {
188204
return fmt.Errorf("creating %s: %+v", id, err)
189205
}
@@ -225,7 +241,16 @@ func resourceDedicatedHostRead(d *pluginsdk.ResourceData, meta interface{}) erro
225241
d.Set("sku_name", model.Sku.Name)
226242
if props := model.Properties; props != nil {
227243
d.Set("auto_replace_on_failure", props.AutoReplaceOnFailure)
228-
d.Set("license_type", string(pointer.From(props.LicenseType)))
244+
245+
if !features.FivePointOh() {
246+
d.Set("license_type", pointer.FromEnum(props.LicenseType))
247+
} else {
248+
licenseType := pointer.FromEnum(props.LicenseType)
249+
if licenseType == string(dedicatedhosts.DedicatedHostLicenseTypesNone) {
250+
licenseType = ""
251+
}
252+
d.Set("license_type", licenseType)
253+
}
229254

230255
platformFaultDomain := 0
231256
if props.PlatformFaultDomain != nil {
@@ -260,8 +285,11 @@ func resourceDedicatedHostUpdate(d *pluginsdk.ResourceData, meta interface{}) er
260285
payload.Properties.AutoReplaceOnFailure = pointer.To(d.Get("auto_replace_on_failure").(bool))
261286
}
262287
if d.HasChange("license_type") {
263-
licenseType := dedicatedhosts.DedicatedHostLicenseTypes(d.Get("license_type").(string))
264-
payload.Properties.LicenseType = &licenseType
288+
licenseType := dedicatedhosts.DedicatedHostLicenseTypesNone
289+
if v := d.Get("license_type").(string); v != "" {
290+
licenseType = dedicatedhosts.DedicatedHostLicenseTypes(v)
291+
}
292+
payload.Properties.LicenseType = pointer.To(licenseType)
265293
}
266294
}
267295

internal/services/compute/dedicated_host_resource_test.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
1515
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
1616
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
17+
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
1718
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
1819
)
1920

@@ -87,7 +88,7 @@ func TestAccDedicatedHost_licenseType(t *testing.T) {
8788

8889
data.ResourceTest(t, r, []acceptance.TestStep{
8990
{
90-
Config: r.licenceType(data, "None"),
91+
Config: r.noLicenceType(data),
9192
Check: acceptance.ComposeTestCheckFunc(
9293
check.That(data.ResourceName).ExistsInAzure(r),
9394
),
@@ -107,6 +108,25 @@ func TestAccDedicatedHost_licenseType(t *testing.T) {
107108
),
108109
},
109110
data.ImportStep(),
111+
{
112+
Config: r.noLicenceType(data),
113+
Check: acceptance.ComposeTestCheckFunc(
114+
check.That(data.ResourceName).ExistsInAzure(r),
115+
),
116+
},
117+
data.ImportStep(),
118+
})
119+
}
120+
121+
func TestAccDedicatedHost_licenseTypeNone(t *testing.T) {
122+
if features.FivePointOh() {
123+
t.Skip("`license_type` no longer accepts `None` as a value in 5.0")
124+
}
125+
126+
data := acceptance.BuildTestData(t, "azurerm_dedicated_host", "test")
127+
r := DedicatedHostResource{}
128+
129+
data.ResourceTest(t, r, []acceptance.TestStep{
110130
{
111131
Config: r.licenceType(data, "None"),
112132
Check: acceptance.ComposeTestCheckFunc(
@@ -169,7 +189,7 @@ func TestAccDedicatedHost_requiresImport(t *testing.T) {
169189
})
170190
}
171191

172-
func (t DedicatedHostResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
192+
func (r DedicatedHostResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
173193
id, err := commonids.ParseDedicatedHostID(state.ID)
174194
if err != nil {
175195
return nil, err
@@ -241,6 +261,20 @@ resource "azurerm_dedicated_host" "test" {
241261
`, r.template(data), data.RandomInteger, licenseType)
242262
}
243263

264+
func (r DedicatedHostResource) noLicenceType(data acceptance.TestData) string {
265+
return fmt.Sprintf(`
266+
%[1]s
267+
268+
resource "azurerm_dedicated_host" "test" {
269+
name = "acctest-DH-%[2]d"
270+
location = azurerm_resource_group.test.location
271+
dedicated_host_group_id = azurerm_dedicated_host_group.test.id
272+
sku_name = "FSv2-Type2"
273+
platform_fault_domain = 1
274+
}
275+
`, r.template(data), data.RandomInteger)
276+
}
277+
244278
func (r DedicatedHostResource) complete(data acceptance.TestData) string {
245279
return fmt.Sprintf(`
246280
%s

website/docs/5.0-upgrade-guide.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ Please follow the format in the example below for listing breaking changes in re
463463

464464
* Validation for `rbac_authorization.resource_id` has been changed to validate for an integration runtime resource ID (case-sensitive) rather than validating for a non-empty string.
465465

466+
### `azurerm_dedicated_host`
467+
468+
* The `license_type` property no longer accepts `None` as a value. Omitting the property sets `None` in the request.
469+
466470
### `azurerm_disk_encryption_set`
467471

468472
* The deprecated `managed_hsm_key_id` property has been removed in favour of the `key_vault_key_id` property.

0 commit comments

Comments
 (0)