Skip to content

Instantly share code, notes, and snippets.

@clstokes
Last active December 3, 2017 15:31
Show Gist options
  • Save clstokes/83b37413147bfcc5b213 to your computer and use it in GitHub Desktop.
Save clstokes/83b37413147bfcc5b213 to your computer and use it in GitHub Desktop.
variable "role_name" {}
variable "role_policy_file" {}
resource "aws_iam_role" "role" {
name = "${var.role_name}"
assume_role_policy = "${file("${path.module}/policies/${var.role_policy_file}")}"
}
output "role_arn" {
value = "${aws_iam_role.role.arn}"
}
/*
* Directory structure
* .
* ├── main.tf
* ├── modules
* │   └── iam_role
* │   ├── iam.tf
* │   └── policies
* │   ├── differentname_policy.json
* │   └── exampleroles_policy.json
*/
module "role_exampleroles" {
source = "./modules/iam_role"
role_name = "exampleroles"
role_policy_file = "exampleroles_policy.json"
}
module "role_differentname" {
source = "./modules/iam_role"
role_name = "differentname"
role_policy_file = "differentname_policy.json"
}
output "role_exampleroles_arn" {
value = "${module.role_exampleroles.role_arn}"
}
output "role_differentname_arn" {
value = "${module.role_differentname.role_arn}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment