简体   繁体   中英

Does the Terraform AWS provider data source aws_iam_role required argument "name" require the path to the role?

Documentation for this data source

Let's say I have two roles with the name ssr-lambda in two paths, /path-a/ , and /path-b/

If we declare the data source as such:

data "aws_iam_role" "example" {
  name = "ssr-lambda"
}

How would it know which role it is?

Do I need to include the path in the name of the role, like this: /path-a/ssr-lambda instead?

The documentation states that the path attribute can be referenced, but it's not an argument.

The aws_iam_policy data source does allow you to specify a path prefix, which is why I find this confusing.

IAM role names must be unique in each account, so my example is invalid, two roles would never have the same name.

I arrived at this conclusion by trying to create two roles in one Terraform project with the same name but different paths. It failed.

Error: error creating IAM Role (ssr-lambda): EntityAlreadyExists: Role with name ssr-lambda already exists. status code: 409

Which is why the path is never needed when using a data source for them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM