integrations / terraform-provider-github

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

[FEAT]: data github_repository_environments returns map instead of list so it can be used with lookup #2144

Closed ann8ty closed 7 months ago

ann8ty commented 7 months ago

Describe the need

I would like to use data item to get a single environment that already exists on my repo. However, the data "github_repository_environments" item returns a list [] rather than a map {} so i cant use name to get just the environment i want.

data "github_repository_environments" "deployment_environment" {
    repository = data.github_repository.organization_reponame_repo.name
}

output "github_repository_environments_environments" {
  value = data.github_repository_environments.deployment_environment.environments
}

output "github_repository_environments_environments_one" {
  value = lookup(data.github_repository_environments.deployment_environment.environments, "envname", "na")
}

SDK Version

No response

API Version

No response

Relevant log output

Changes to Outputs:
  + github_repository_environments_environments = [
      + {
          + name    = "dev"
          + node_id = "EN_xxx"
        },
      + {
          + name    = "prod"
          + node_id = "EN_xxx"
        },
      + {
          + name    = "test"
          + node_id = "EN_xxx"
        },
    ]

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.
╷
│ Error: Invalid function argument
│ 
│   on postman_github.tf line 21, in output "github_repository_environments_environments_one":
│   21:   value = lookup(data.github_repository_environments.deployment_environment.environments, "xxx", "na")
│     ├────────────────
│     │ while calling lookup(inputMap, key, default...)
│     │ data.github_repository_environments.deployment_environment.environments is list of object with 3 elements
│ 
│ Invalid value for "inputMap" parameter: lookup() requires a map as the first argument.

Code of Conduct

ann8ty commented 7 months ago

turns out don't need it because the environment variable reference just uses the name.