Skip to content

Duplicate resource errors when using indexed resources #303

@bamhm182

Description

@bamhm182

Problem

When creating multiple resources within a count or for_each loop, you end up with multiple resources using the same label as seen in the terraform graph output. The ConvertState function within providers/terraform/resources.go sees references to these resources as a problem since they share the same label and fails to let you use them.

Use Case

Below is a simple example which creates 5 random passwords and attempts to make coder_metadata resources for them. While this instance uses coder_metadata, a similar result also occurs with many of the other coder_* resource types.

terraform {
  required_providers {
    coder = { source = "coder/coder" }
    random = { source = "hashicorp/random" }
  }
}

resource "random_password" "passwords" {
  count = 5
  length = 20
}

resource "coder_metadata" "meta_passwords" {
  count = length(random_password.passwords)
  resource_id = random_password.passwords[count.index].id
}

What I Want

5 coder_metadata resources, one for each of the generated random_password resources.

What I Get

Error during the build
template import provision for start: duplicate metadata resource: random_password.passwords

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy