hashicorp / hashicorp/packer-plugin-azure
Setting "managed_image_zone_resilient": "false" for a Azure Image is not setting properly.
- Dominant language
- Go
- Stars
- 63
- Forks
- 103
- PR merge metrics
- No merged PRs in 30d
Description
_This issue was originally opened by @danmanrique as hashicorp/packer#10526. It was migrated here as a result of the [Packer plugin split](https://github.com/hashicorp/packer/issues/8610#issuecomment-770034737). The original body of the issue is below._
When filing a bug, please include the following headings if possible. Any
example text in this template can be deleted.
#### Overview of the Issue
Setting the property in the builders part of the json file for "managed_image_zone_resilient": "false" for a Azure Image is not setting properly. I am building a WindowsClient image in Packer. After the build, I import the image via Terraform to subsequently store the image in a Gallery. When I run Terraform Plan after the import for the rest of the deployment, I get "+zone_resilient = false # forces replacement". In Azure, the state on the Image shows "ZONE RESILIENCY: Disabled."
I checked the Terraform State file and the property is null. I think the issue is in the Terraform import process of this property or the interrupt between the two.
I did find a workaround. I ignored the zone-resilient attribute, and I am able to move forward with the workaround.
```hcl
lifecycle {
ignore_changes = [
zone_resilient,
source_virtual_machine_id,
]
}
```
#### Reproduction Steps
Create a deployment.json.
In the deployment json:
First, without setting the property.
Second, setting the managed_image_zone_resilient = false property
On an outer script in Powershell:
Create RG
Run Packer
Import the RG
Import the Image
Run Terraform Plan
Notice Destroy Message
### Packer version
Packer v1.6.6
### Simplified Packer Buildfile
```json
{
"variables": {
"tenant_id": "{{env `tenant_id`}}",
"subscription_id": "{{env `subscription_id`}}",
"client_id": "{{env `client_id`}}",
"client_secret": "{{env `client_secret`}}",
"resource_group_name": "{{env `resource_group_name`}}",
"vm-size": "{{env `vm-size`}}",
"gitpath": "{{env `gitpath`}}",
"global_image_name": "{{env `global_image_name`}}"
},
"builders": [
{
"type": "azure-arm",
"client_id": "{{user `client_id`}}",
"client_secret": "{{user `client_secret`}}",
"subscription_id": "{{user `subscription_id`}}",
"build_resource_group_name": "{{user `resource_group_name`}}",
"managed_image_resource_group_name": "{{user `resource_group_name`}}",
"managed_image_name": "{{user `global_image_name`}}",
"managed_image_zone_resilient": "false",
"os_type": "Windows",
"image_publisher": "MicrosoftWindowsDesktop",
"image_offer": "Windows-10",
"image_sku": "20h2-pro",
"communicator": "winrm",
"winrm_use_ssl": "true",
"winrm_insecure": "true",
"winrm_timeout": "3m",
"winrm_username": "packeradmin",
"vm_size": "{{user `vm-size`}}"
}
],
"provisioners": [
{
"type": "powershell",
"inline": [
" while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }",
" while ((Get-Service WindowsAzureTelemetryService) -and ((Get-Service WindowsAzureTelemetryService).Status -ne 'Running')) { Start-Sleep -s 5 }",
" while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }",
" & $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit",
" while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }"
]
}
]
}
```
### Operating system and Environment details
Windows 10 Enterprise
### Log Fragments and crash.log files
```
2021/01/25 21:27:02 packer.exe plugin: Azure request body="{\"location\":\"eastus\",\"properties\":{\"sourceVirtualMachine\":{\"id\":\"/subscriptions/f8d440ed-264b-4a91-8ab9-0b1694914abf/resourceGroups/central-services/providers/Microsoft.Compute/virtualMachines/pkrvm25tuzfeo88\"},\"storageProfile\":{\"zoneResilient\":false}},\"tags\":{}}" method="PUT" request="https://management.azure.com/subscriptions/f8d440ed-264b-4a91-8ab9-0b1694914abf/resourceGroups/central-services/providers/Microsoft.Compute/images/VMSSImage?api-version=2018-04-01"
2021/01/25 21:27:04 packer.exe plugin: Azure response status="201 Created" method="PUT" request="https://management.azure.com/subscriptions/f8d440ed-264b-4a91-8ab9-0b1694914abf/resourceGroups/central-services/providers/Microsoft.Compute/images/VMSSImage?api-version=2018-04-01" x-ms-request-id="4fb61c46-8fe2-4ec2-8e6b-9cee91cd1ce4" body="{\r\n \"name\": \"VMSSImage\",\r\n \"id\": \"/subscriptions/f8d440ed-264b-4a91-8ab9-0b1694914abf/resourceGroups/central-services/providers/Microsoft.Compute/images/VMSSImage\",\r\n \"type\": \"Microsoft.Compute/images\",\r\n \"location\": \"eastus\",\r\n \"tags\": {},\r\n \"properties\": {\r\n \"sourceVirtualMachine\": {\r\n \"id\": \"/subscriptions/f8d440ed-264b-4a91-8ab9-0b1694914abf/resourceGroups/central-services/providers/Microsoft.Compute/virtualMachines/pkrvm25tuzfeo88\"\r\n },\r\n \"storageProfile\": {\r\n \"osDisk\": {\r\n \"osType\": \"Windows\",\r\n \"osState\": \"Generalized\",\r\n \"managedDisk\": {\r\n \"id\": \"/subscriptions/f8d440ed-264b-4a91-8ab9-0b1694914abf/resourceGroups/central-services/providers/Microsoft.Compute/disks/pkros25tuzfeo88\"\r\n },\r\n \"caching\": \"ReadWrite\",\r\n \"storageAccountType\": \"Standard_LRS\"\r\n },\r\n \"dataDisks\": [],\r\n \"zoneResilient\": false\r\n },\r\n \"provisioningState\": \"Creating\"\r\n }\r\n}"
2021/01/25 21:27:04 packer.exe plugin: Azure request method="GET" request="https://management.azure.com/subscriptions/f8d440ed-264b-4a91-8ab9-0b1694914abf/providers/Microsoft.Compute/locations/eastus/operations/4fb61c46-8fe2-4ec2-8e6b-9cee91cd1ce4?api-version=2018-04-01" body=""
2021/01/25 21:27:04 packer.exe plugin: Azure response method="GET" request="https://management.azure.com/subscriptions/f8d440ed-264b-4a91-8ab9-0b1694914abf/providers/Microsoft.Compute/locations/eastus/operations/4fb61c46-8fe2-4ec2-8e6b-9cee91cd1ce4?api-version=2018-04-01" x-ms-request-id="af35ae29-17a8-4610-88b9-cfe5193785dd" body="{\r\n \"startTime\": \"2021-01-26T02:27:08.2734903+00:00\",\r\n \"status\": \"InProgress\",\r\n \"name\": \"4fb61c46-8fe2-4ec2-8e6b-9cee91cd1ce4\"\r\n}" status="200 OK"
2021/01/25 21:28:04 packer.exe plugin: Azure request method="GET" request="https://management.azure.com/subscriptions/f8d440ed-264b-4a91-8ab9-0b1694914abf/providers/Microsoft.Compute/locations/eastus/operations/4fb61c46-8fe2-4ec2-8e6b-9cee91cd1ce4?api-version=2018-04-01" body=""
2021/01/25 21:28:04 packer.exe plugin: Azure response status="200 OK" method="GET" request="https://management.azure.com/subscriptions/f8d440ed-264b-4a91-8ab9-0b1694914abf/providers/Microsoft.Compute/locations/eastus/operations/4fb61c46-8fe2-4ec2-8e6b-9cee91cd1ce4?api-version=2018-04-01" x-ms-request-id="7ff66f4e-2ddd-4ef2-a3b0-7216c26c1ab6" body="{\r\n \"startTime\": \"2021-01-26T02:27:08.2734903+00:00\",\r\n \"endTime\": \"2021-01-26T02:27:13.4297193+00:00\",\r\n \"status\": \"Succeeded\",\r\n \"name\": \"4fb61c46-8fe2-4ec2-8e6b-9cee91cd1ce4\"\r\n}"
```
Contributor guide
Research direction
Start by tracing the managed_image_zone_resilient entry point through Azure image creation and the Terraform import boundary. Compare the request and response logs with the null value observed in Terraform state, then reproduce the two deployment.json cases and Terraform plan. Done means false remains represented consistently and no replacement is proposed for the disabled zone-resilient image.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, go, terraform
- Domain
- cloud, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100