-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Terraform is not keeping azurerm_virtual_machine.storage_os_disk.image_uri properly #838
Comments
I am also seeing this behavior. |
Observed also in 0.11.5 with azurerm v1.3.0 |
I'm also experiencing this behaviour, which is annoying and complicates my life big time. |
You can just mark the property as ignored: resource "azurerm_virtual_machine" "virtual_machine" {
...
lifecycle {
ignore_changes = [
"storage_os_disk" // Terraform tries to change empty storage_os_disk.0.image_uri on every provisioning.
// To avoid this we just ignore the changes to this attribute when diffing.
]
}
}
|
Amazing. Thanks for the quick answer, this is the type of the hack I was expected. |
But then I experienced the following limitation: Haha, Now my journey with Packer can be over very soon. |
In our current setup we reprovision all VMs whenever the golden image changes. AFAIK there's no way to do that without destroying the VMs. We use a script like this for rolling update: #!/usr/bin/env bash
set -eu
setup-remote-state.sh prod
VM_COUNT=${1:-20}
echo "Number of VMs in the cluster: $VM_COUNT"
# Bump number of VMs temporarily so number of available VMs is the same
# This is to avoid affecting currently running jobs
BUMPED_VM_COUNT=$(($VM_COUNT+1))
terraform apply -var-file=env-prod.tfvars -var vm_count=$BUMPED_VM_COUNT
LAST_VM_INDEX=$(($VM_COUNT-1))
for i in `seq 0 ${LAST_VM_INDEX}`
do
echo "azurerm_virtual_machine.virtual_machine.$i"
terraform taint "azurerm_virtual_machine.virtual_machine.$i"
terraform apply -var-file=env-prod.tfvars -var vm_count=${VM_COUNT}
done
# decrease number of VMs back to original
terraform apply -var-file=env-prod.tfvars -var vm_count=${VM_COUNT}
echo "Done."
It can be modified obviously to taint and reprovision VMs in batches if you have a lot of machines. |
That's fine. |
Sorry, I haven't read the link properly. We currently copy golden image between accounts and try to keep its size to minimum. |
An alternative would be to use standard image and install everything via custom script extension. A better approach would be to use Docker containers, but that depends on your use-case, obviously. |
Yea, copying is not the worst (and 100x better than standard image and custom script / ansible). Also I'm quite new to Azure. Do you have a single storage account for subscription? Or per resource group? I'm asking how you logically keep things isolated (if there's a need for that). |
Hi Jakub. In my case i have one golden image per subscription/storage account. We do not have needs to have all vm's on same level as Dmitry mentioned, so periodically I am creating a new image (just to shorten deploys). |
@jakubigla In our case we structure things like this:
In our case one team owns all the clusters, so there's no requirement to have separate storage accounts per team. |
Thanks guys, this was very very helpful. |
@dstori is this still an issue for you? |
@metacpp to be honest the project requirements changed (as usual) so we are not using azure for now, I will return to this subject later. |
* Add repro test for bug #838 * Set image_uri back to schema * Add image_uri check in test case
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks! |
Terraform Version
Terraform v0.11.3
Affected Resource(s)
Terraform Configuration Files
Expected Behavior
When you execute
terraform apply
terraform previews correctly the storage_os_disk.0.image_uri state:Then you confirm with
yes
and all the resources are properly created.When you execute
terraform show
storage_os_disk.0.image_uri should be listed with the desired state.Actual Behavior
When you execute
terraform show
storage_os_disk.0.image_uri is empty:This implies that future executions of
terraform apply
will try to update the state, even we don't have anything to update.Steps to Reproduce
Create a terraform file as the example above
terraform apply
terraform show
The text was updated successfully, but these errors were encountered: