profile
viewpoint
Jean-Pierre Huynh jphuynh @cloudnc

startedmozilla-iot/docs

started time in 6 days

issue openedterraform-providers/terraform-provider-aws

Import resource with ["INDEX"] is rejected

<!--- Please keep this note for the community --->

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

<!--- Thank you for keeping this note for the community --->

Terraform Version

0.12.18

Provider version

2.43.0

Affected Resource(s)

  • aws_iam_user

Terraform Configuration Files

<!--- Information about code formatting: https://help.github.com/articles/basic-writing-and-formatting-syntax/#quoting-code --->

locals {
  api_users = [
    "foo",
    "bar",
  ]
}

resource "aws_iam_user" "api_users" {
  for_each = toset(local.api_users)

  name = each.key
}

Expected Behavior

Successful import of the resource

Actual Behavior

$ terraform import aws_iam_user.api_users["foo"] foo

Error: Index value required

  on <import-address> line 1:
   1: aws_iam_user.api_users[foo]

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

For information on valid syntax, see:
https://www.terraform.io/docs/internals/resource-addressing.html

I think it might be an issue with the provider stripping the double quotes in aws_iam_user.api_users["foo"] ?

Steps to Reproduce

  1. terraform plan
  # aws_iam_user.api_users["bar"] will be created
  + resource "aws_iam_user" "api_users" {
      + arn           = (known after apply)
      + force_destroy = false
      + id            = (known after apply)
      + name          = "bar"
      + path          = "/"
      + unique_id     = (known after apply)
    }

  # aws_iam_user.api_users["foo"] will be created
  + resource "aws_iam_user" "api_users" {
      + arn           = (known after apply)
      + force_destroy = false
      + id            = (known after apply)
      + name          = "foo"
      + path          = "/"
      + unique_id     = (known after apply)
    }
  1. terraform import aws_iam_user.api_users["foo"] foo

References

https://www.terraform.io/docs/internals/resource-addressing.html#for_each-example

created time in 8 days

startedaws/aws-node-termination-handler

started time in 2 months

startedaws-samples/amazon-k8s-node-drainer

started time in 2 months

startedopen62541/open62541

started time in 2 months

startednombreinvicto/HaasMTConnect

started time in 3 months

startedmtconnect/cppagent

started time in 4 months

more