microsoft / terraform-provider-azuredevops

Terraform Azure DevOps provider
https://www.terraform.io/docs/providers/azuredevops/
MIT License
372 stars 260 forks source link

Make possible to get "data.azuredevops_environment" by name #1050

Open Boltairex opened 1 month ago

Boltairex commented 1 month ago

Community Note

Description

For now, we can only get existing ADO environment by giving the ID of the environment. In most cases we couldn't get the enviroment ID, becasue it's dynamic. The environment could be destroyed and recreated, so it's not a good way to, for example, manually assign the Identifier. Sometimes also we don't want to destroy the environment.

Affected Resource

Add new behaviour in data source: data "azuredevops_environment"

Scenario:

To access a created earlier environment, instead of recreating it or using tricks, we could use this:

data "azuredevops_environment" "env" {
  count      = length(data.azuredevops_project.main)
  project_id = data.azuredevops_project.main[count.index].id
  name       = data.azuredevops_project.main[count.index].environment_name
}

This is my suggestion to solve it.

References

PR: azuredevops_environment Another Issue