Skip to content

Instantly share code, notes, and snippets.

@diogoaurelio
Forked from clstokes/iam.tf
Created December 3, 2017 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogoaurelio/4a3426721928c1e19c61963d19177399 to your computer and use it in GitHub Desktop.
Save diogoaurelio/4a3426721928c1e19c61963d19177399 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