Terraform: [0.12] cannot taint indexed resource: Error Attribute name required

Created on 10 May 2019  ยท  9Comments  ยท  Source: hashicorp/terraform


Attempting to taint a single resource from a list of resources errors with Error: Attribute name required

Terraform Version

v0.12.0-dev (compiled from master today)

Terraform Configuration Files

resource "test_resource" "multiple" {
  count = 2
  required = "foo"
  required_map = {
    foo = "bar"
  }
}

Debug Output

Crash Output

Expected Behavior

terraform taint test_resource.multiple.1
The resource test_resource.multiple.1 in the module root has been marked as tainted!

Actual Behavior

terraform taint test_resource.multiple.1

Error: Attribute name required

  on  line 1:
  (source code not available)

Dot must be followed by attribute name.

Steps to Reproduce

  1. terraform init
  2. terraform apply
  3. terraform taint test_resource.multiple.1

Additional Context


terraform 0.11.10 works

References

cli documentation

Most helpful comment

this helped me find a better workaround with the zsh error:
https://thoughtbot.com/blog/how-to-use-arguments-in-a-rake-task

added to my .zshrc

unsetopt nomatch

All 9 comments

Hi @sjwl,

Thanks for pointing this out.
The address syntax in 0.12 has been made more consistent, and indexing is now always done with the [] index operator. The proper syntax for this command would be

terraform taint test_resource.multiple[1]

I'll see if we can point this out a little better in the cli or the docs.

@jbardin interesting...here's what I get

terraform taint test_resource.multiple[1]
zsh: no matches found: test_resource.multiple[1]

But this error doesn't seem to be from terraform, so I wrap the resource in quotes

terraform taint "test_resource.multiple[1]"
Resource instance test_resource.multiple[1] has been marked as tainted.

this helped me find a better workaround with the zsh error:
https://thoughtbot.com/blog/how-to-use-arguments-in-a-rake-task

added to my .zshrc

unsetopt nomatch

Ah yes, the square brackets take precedence in zsh. In bash it's not a factor, but it's usually good practice to properly quote arguments to prevent misinterpreting them.

How to taint all indexes in resource?
Let say I want taint
aws_instance.bar[*]
Is it posible?

I'm on Terraform v0.12.26 and have hit this with string indexes. I am definitely passing through the correct syntax, but TF is refusing to understand it's a string:

> echo azurerm_key_vault_secret.organization_google_credentials["something"]
azurerm_key_vault_secret.organization_google_credentials["something"]
> terraform untaint azurerm_key_vault_secret.organization_google_credentials["something"]

Error: Index value required

  on  line 1:
  (source code not available)

Index brackets must contain either a literal number or a literal string.

Any help appreciated!

Hi @kentcb

If you haven't got a solution to this already, I think you need to escape the double quotes per here: https://www.terraform.io/docs/commands/taint.html#example-tainting-a-single-resource-created-with-for_each

I am going to close this issue due to inactivity; it seems the questions in here have been answered and there is not a bug.

If there is still a question, I recommend the the community forum, where there are far more people available to help. If there is a bug or you would like to make a feature request, please open a new issue and fill out the template.
Thanks!

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings