Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate resource errors when using indexed resources #303

Open
bamhm182 opened this issue Nov 13, 2024 · 1 comment
Open

Duplicate resource errors when using indexed resources #303

bamhm182 opened this issue Nov 13, 2024 · 1 comment

Comments

@bamhm182
Copy link

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
@matifali matifali transferred this issue from coder/coder Nov 13, 2024
@coder-labeler coder-labeler bot added duplicate This issue or pull request already exists help wanted labels Nov 13, 2024
@ethanndickson ethanndickson removed the duplicate This issue or pull request already exists label Nov 13, 2024
@ethanndickson
Copy link
Member

Yeah, this is an unfortunate limitation of the current design. We'd need ConvertState to intercept resources that use count and then append whatever index it is to the resource label. I'm not sure if/when this will get prioritised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants