azure-pipelines-tasks-terraform icon indicating copy to clipboard operation
azure-pipelines-tasks-terraform copied to clipboard

Terraform CLI in Azure Devops does not allow to target a resource with double quotes

Open intoinr opened this issue 2 years ago • 0 comments

Describe the bug Terraform CLI in Azure Devops does not allow to target a resource with double quotes

To Reproduce

Use this task to create a terraform plan:

  • task: TerraformCLI@0 displayName: terraform_plan inputs: command: plan workingDirectory: ${{ parameters.workingDirectory }} environmentServiceName: ${{ parameters.backendServiceArm }} commandOptions: '-out=/home/vsts/work/1/s/terraform.tfplan -detailed-exitcode -target=module.azure.azurerm_resource_group.azure["resource_group1_key"] -target=module.azure.azurerm_resource_group.azure["virtual_network1_key"] -target=module.azure.azurerm_virtual_network.azure["resource_group1_key"] -target=module.azure.azurerm_virtual_network.azure["virtual_network1_key"]'

You will get the following error:

│ Error: Invalid target "module.azure.azurerm_virtual_network.azure[resource_group1_key]" │ │ Index brackets must contain either a literal number or a literal string. ╵ ╷ │ Error: Invalid target "module.azure.azurerm_virtual_network.azure[virtual_network1_key]" │ │ Index brackets must contain either a literal number or a literal string. ╵

For more help on using this command, run: terraform plan -help ##[error]Terraform command 'plan' failed with exit code '1'. ##[error]╷ │ Error: Invalid target "module.azure.azurerm_resource_group.azure[resource_group1_key]" │ │ Index brackets must contain either a literal number or a literal string. ╵ ╷ │ Error: Invalid target "module.azure.azurerm_resource_group.azure[virtual_network1_key]" │ │ Index brackets must contain either a literal number or a literal string. ╵ ╷ │ Error: Invalid target "module.azure.azurerm_virtual_network.azure[resource_group1_key]" │ │ Index brackets must contain either a literal number or a literal string. ╵ ╷ │ Error: Invalid target "module.azure.azurerm_virtual_network.azure[virtual_network1_key]" │ │ Index brackets must contain either a literal number or a literal string. ╵

For more help on using this command, run: terraform plan -help

Finishing: tf plan

Expected behavior The plan should have run without issues.

Agent Configuration

  • OS: ubuntu-latest
  • Hosted
  • Terraform version used (Default for hosted agent is acceptable) 1.4.6
  • AzureCLI version used (Default for hosted agent is acceptable or N/A) N/A

intoinr avatar May 05 '23 13:05 intoinr