hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.77k stars 9.13k forks source link

[Enhancement]: Provide a data source for discovering the directory_id of an AWS Directory Services directory #30803

Open rschaefer-m1 opened 1 year ago

rschaefer-m1 commented 1 year ago

Description

Presently, the aws_directory_service_directory data source can retrieve all the relevant data about an AWS Directory service, but it can only do so when provided with a directory_id. This becomes a chicken/egg issue and couples code more tightly. For instance, I need to know the directory_id in order to join an MSSQL RDS database to the AD domain, but I cannot use this data source to retrieve this information. So I have the options of either statically setting the directory_id in configuration, doing a remote state lookup, or running an AWS CLI command to retrieve the ID. None of these are as loosely coupled or as robust as I'd like.

There is "describe-directories" action in the directory services API available. It seems that if a specific directory_id isn't provided to it, it returns all directories, which would allow terraform to implement the filtering on its side.

If the aws_directory_service_directory was enhanced (or another data source created) which allowed filter-based selection of the correct directory similar to other data sources such as aws_subnets or aws_db_instances or aws_ami, then we could then simply use that filtering to pick a directory based on the name or any other attribute and get the id back.

Affected Resource(s) and/or Data Source(s)

aws_directory_service_directory

Potential Terraform Configuration

data "aws_directory_service_directory" "my_corp_ad" {
  filter {
    name   = "name"
    values = ["mycorpad.mycompany.com"]
  }
}

References

https://docs.aws.amazon.com/directoryservice/latest/devguide/API_DescribeDirectories.html

Would you like to implement a fix?

No

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue