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

[Enhancement] - Add os_disk.storage_type and data_disk.storage_type to azurerm_image #26936

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
753389b
add storage account type prop
bruceharrison1984 Aug 5, 2024
b949e92
rename property, update docs
bruceharrison1984 Aug 5, 2024
547cb08
formatting
bruceharrison1984 Aug 5, 2024
a9b0b14
update tests to use new property
bruceharrison1984 Aug 5, 2024
66a4580
grammar
bruceharrison1984 Aug 5, 2024
30b162a
add description to properties
bruceharrison1984 Aug 5, 2024
ac3b07a
move description to correct property
bruceharrison1984 Aug 5, 2024
00ff06a
hide behind beta4 feature flag
bruceharrison1984 Aug 6, 2024
acbd14d
Update website/docs/r/image.html.markdown
bruceharrison1984 Aug 7, 2024
8351a9c
Update website/docs/r/image.html.markdown
bruceharrison1984 Aug 7, 2024
67e67f2
Update internal/services/compute/image_resource.go
bruceharrison1984 Aug 7, 2024
7202bec
refactor
bruceharrison1984 Aug 7, 2024
3d03325
Update internal/services/compute/image_resource.go
bruceharrison1984 Aug 8, 2024
fb40606
Update internal/services/compute/image_resource.go
bruceharrison1984 Aug 8, 2024
c8e2d6b
Update internal/services/compute/image_resource.go
bruceharrison1984 Aug 8, 2024
8395e27
Update internal/services/compute/image_resource.go
bruceharrison1984 Aug 8, 2024
58989de
Update internal/services/compute/image_resource.go
bruceharrison1984 Aug 8, 2024
e762004
Update internal/services/compute/image_resource.go
bruceharrison1984 Aug 8, 2024
832abcf
cleanup from suggestions
bruceharrison1984 Aug 8, 2024
c8de9dc
Merge branch 'hashicorp:main' into compute-image-storage-type
bruceharrison1984 Aug 12, 2024
32439c0
add tests for beta property
bruceharrison1984 Aug 12, 2024
071dc10
Merge branch 'hashicorp:main' into compute-image-storage-type
bruceharrison1984 Aug 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions internal/services/compute/image_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ func resourceImage() *pluginsdk.Resource {
ForceNew: true,
ValidateFunc: validate.DiskEncryptionSetID,
},

"storage_type": {
bruceharrison1984 marked this conversation as resolved.
Show resolved Hide resolved
Type: pluginsdk.TypeString,
Description: "The type of storage disk",
Optional: true,
bruceharrison1984 marked this conversation as resolved.
Show resolved Hide resolved
ForceNew: true,
ValidateFunc: validation.StringInSlice(images.PossibleValuesForStorageAccountTypes(), false),
},
},
},
},
Expand Down Expand Up @@ -188,6 +196,14 @@ func resourceImage() *pluginsdk.Resource {
Computed: true,
ValidateFunc: validation.NoZeroValues,
},

"storage_type": {
Type: pluginsdk.TypeString,
Description: "The type of storage disk",
Optional: true,
bruceharrison1984 marked this conversation as resolved.
Show resolved Hide resolved
ForceNew: true,
ValidateFunc: validation.StringInSlice(images.PossibleValuesForStorageAccountTypes(), false),
},
},
bruceharrison1984 marked this conversation as resolved.
Show resolved Hide resolved
},
},
Expand Down Expand Up @@ -372,6 +388,10 @@ func expandImageOSDisk(input []interface{}) *images.ImageOSDisk {
}
}

if storageAccountType := config["storage_type"].(string); storageAccountType != "" {
out.StorageAccountType = pointer.To(images.StorageAccountTypes(storageAccountType))
}

return out
}

Expand Down Expand Up @@ -403,6 +423,10 @@ func expandImageDataDisks(disks []interface{}) *[]images.ImageDataDisk {
item.ManagedDisk = managedDisk
}

if storageAccountType := config["storage_type"].(string); storageAccountType != "" {
item.StorageAccountType = pointer.To(images.StorageAccountTypes(storageAccountType))
}

output = append(output, item)
}

Expand Down Expand Up @@ -434,6 +458,10 @@ func flattenImageOSDisk(input *images.ImageStorageProfile) []interface{} {
if set := v.DiskEncryptionSet; set != nil && set.Id != nil {
diskEncryptionSetId = *set.Id
}
storageAccountType := ""
if v.StorageAccountType != nil {
storageAccountType = string(*v.StorageAccountType)
}
output = append(output, map[string]interface{}{
"blob_uri": blobUri,
"caching": caching,
Expand All @@ -442,6 +470,7 @@ func flattenImageOSDisk(input *images.ImageStorageProfile) []interface{} {
"os_state": string(v.OsState),
"size_gb": diskSizeGB,
"disk_encryption_set_id": diskEncryptionSetId,
"storage_type": storageAccountType,
})
}
}
Expand Down Expand Up @@ -471,12 +500,17 @@ func flattenImageDataDisks(input *images.ImageStorageProfile) []interface{} {
if disk.ManagedDisk != nil && disk.ManagedDisk.Id != nil {
managedDiskId = *disk.ManagedDisk.Id
}
storageAccountType := ""
if disk.StorageAccountType != nil {
storageAccountType = string(*disk.StorageAccountType)
}
output = append(output, map[string]interface{}{
"blob_uri": blobUri,
"caching": caching,
"lun": int(disk.Lun),
"managed_disk_id": managedDiskId,
"size_gb": diskSizeGb,
"storage_type": storageAccountType,
})
}
}
Expand Down
45 changes: 25 additions & 20 deletions internal/services/compute/image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,12 @@ resource "azurerm_image" "test" {
%s

os_disk {
os_type = "Linux"
os_state = "Generalized"
blob_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
size_gb = 30
caching = "None"
os_type = "Linux"
os_state = "Generalized"
blob_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
size_gb = 30
caching = "None"
storage_type = "StandardSSD_LRS"
}

tags = {
Expand All @@ -553,11 +554,12 @@ resource "azurerm_image" "import" {
resource_group_name = azurerm_image.test.resource_group_name

os_disk {
os_type = "Linux"
os_state = "Generalized"
blob_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
size_gb = 30
caching = "None"
os_type = "Linux"
os_state = "Generalized"
blob_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
size_gb = 30
caching = "None"
storage_type = "StandardSSD_LRS"
}

tags = {
Expand All @@ -579,11 +581,12 @@ resource "azurerm_image" "testdestination" {
resource_group_name = azurerm_resource_group.test.name

os_disk {
os_type = "Linux"
os_state = "Generalized"
blob_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
size_gb = 30
caching = "None"
os_type = "Linux"
os_state = "Generalized"
blob_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
size_gb = 30
caching = "None"
storage_type = "StandardSSD_LRS"
}

tags = {
Expand Down Expand Up @@ -718,11 +721,12 @@ resource "azurerm_image" "testdestination" {
resource_group_name = azurerm_resource_group.test.name

os_disk {
os_type = "Linux"
os_state = "Generalized"
blob_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
size_gb = 30
caching = "None"
os_type = "Linux"
os_state = "Generalized"
blob_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
size_gb = 30
caching = "None"
storage_type = "StandardSSD_LRS"
}

tags = {
Expand Down Expand Up @@ -873,6 +877,7 @@ resource "azurerm_image" "test" {
size_gb = 30
caching = "None"
disk_encryption_set_id = azurerm_disk_encryption_set.test.id
storage_type = "StandardSSD_LRS"
}

tags = {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/functions/parse_resource_id.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ normalise_resource_id(id string) string

## Arguments

1. `id` (String) Azure Resource Manager ID.
1. `id` (String) Azure Resource Manager ID.
2 changes: 2 additions & 0 deletions website/docs/r/image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The `os_disk` block supports the following:
* `caching` - (Optional) Specifies the caching mode as `ReadWrite`, `ReadOnly`, or `None`. The default is `None`.
* `size_gb` - (Optional) Specifies the size of the image to be created. Changing this forces a new resource to be created.
* `disk_encryption_set_id` - (Optional) The ID of the Disk Encryption Set which should be used to encrypt this image. Changing this forces a new resource to be created.
* `storage_type` - (Optional) The type of storage disk to use. See [Azure API Docs](https://learn.microsoft.com/en-us/rest/api/compute/images/create-or-update?view=rest-compute-2024-03-02&tabs=HTTP#storageaccounttypes) for valid values.
bruceharrison1984 marked this conversation as resolved.
Show resolved Hide resolved

---

Expand All @@ -65,6 +66,7 @@ The `data_disk` block supports the following:
* `blob_uri` - (Optional) Specifies the URI in Azure storage of the blob that you want to use to create the image.
* `caching` - (Optional) Specifies the caching mode as `ReadWrite`, `ReadOnly`, or `None`. Defaults to `None`.
* `size_gb` - (Optional) Specifies the size of the image to be created. The target size can't be smaller than the source size.
* `storage_type` - (Optional) The type of storage disk to use. See [Azure API Docs](https://learn.microsoft.com/en-us/rest/api/compute/images/create-or-update?view=rest-compute-2024-03-02&tabs=HTTP#storageaccounttypes) for valid values.
bruceharrison1984 marked this conversation as resolved.
Show resolved Hide resolved

## Attributes Reference

Expand Down
Loading