integrations / terraform-provider-github

Terraform GitHub provider
https://www.terraform.io/docs/providers/github/
MIT License
863 stars 708 forks source link

[BUG]: Argument repository doesn't pass when used with count on module #2270

Open riupie opened 1 month ago

riupie commented 1 month ago

Expected Behavior

Argument repository should be detected.

Actual Behavior

Argument repository is not detected.

Terraform Version

Terraform v1.8.1 on darwin_arm64

Affected Resource(s)

Terraform Configuration Files

No response

Steps to Reproduce

I encounter this issue. So, I create terraform module to import secret from vault to github environment:

data "github_repository" "repo" {
  full_name = "${var.github_owner}/${var.github_repository}"
}

data "vault_generic_secret" "github_env_secret" {
  path = var.vault_secret_path
}
locals {
  secrets_map = jsondecode(data.vault_generic_secret.github_env_secret.data_json)
}
resource "github_repository_environment" "environment" {
  repository  = var.github_repository
  environment = var.github_environment
}

resource "github_actions_environment_secret" "secrets" {
  count           = length(keys(local.secrets_map))
  repository      = data.github_repository.repo.name
  environment     = github_repository_environment.environment.environment
  secret_name     = element(keys(local.secrets_map), count.index)
  plaintext_value = element(values(local.secrets_map), count.index)
}

And then I use the module on my tf script:

module "github_secret" {
  source             = "path/to/module"
  github_environment = "Test"
  github_repository  = "demo-repo"
  vault_secret_path  = "github/myorg/demo-repo/secrets"
}

Debug Output

╷
│ Error: Missing required argument
│ 
│   with module.github_secret.github_actions_environment_secret.secrets[0],
│   on .terraform/modules/github_secret/github-env-vault/main.tf line 25, in resource "github_actions_environment_secret" "secrets":
│   25:   repository      = data.github_repository.repo.name
│ 
│ The argument "repository" is required, but no definition was found.
╵

Panic Output

No response

Code of Conduct