0

I have 10 virtual machines to be re-created. I want to do it in 2 groups, first 5 machines [0-4] and second 5 machines [5-9]

terraform apply -replace=module.ci.azurerm_windows_virtual_machine.vm[0-4]

But it does not work, says:

│ Index key must be followed by a closing bracket.

Is there any way to use a wildcard, or point a group of machines in general in command above?

1 Answer 1

1

I don't know that you can specify ranges. On Linux, you can add a bash function such as from here.

A slight modification should work,

terraform-replace () {
    sed 's/\x1b\[[0-9;]*m//g' | grep -o '# [^( ]* ' | grep '\.' | sed " s/^# /-replace '/; s/ $/'/; "
}

Then use it like this,

terraform plan | terraform-replace | grep 'azurerm_windows_virtual_machine.vm\[[0-4]\]' | xargs -r terraform apply -auto-approve
3
  • Yes, it looks like you can pass a list of machines with single index value in each, separated by space. I suppose it is what it is.
    – Wojtas.Zet
    Apr 14, 2022 at 12:13
  • Right, this is what my answer does Apr 14, 2022 at 12:54
  • It is not necessary for you, I just find it useful to list targets, (if you would use the original from github). Apr 14, 2022 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.