-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6dc6298
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# terraform-aws-iam_instance_profile | ||
This module creates an `iam_instance_profile` based on provided allowed actions and resources. The module is built for Terraform version 0.12 | ||
|
||
## Examples | ||
See also [/examples/default] a complete working example. | ||
|
||
|
||
## Usages | ||
``` | ||
module "iam_instance_profile" { | ||
name = var.name | ||
actions = [ | ||
"s3:*", | ||
"rds:*", | ||
"logs:*", | ||
] | ||
} | ||
## | ||
``` | ||
|
||
## Outputs: | ||
The name of the iam_instance_profile: `module.iam_instance_profile.name` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
terraform { | ||
required_version = ">= 0.12.0" | ||
} | ||
|
||
resource "aws_iam_role" "iam_role" { | ||
name = var.name | ||
|
||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "ec2.amazonaws.com" | ||
}, | ||
"Effect": "Allow" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_iam_instance_profile" "iam_instance_profile" { | ||
name = var.name | ||
role = aws_iam_role.iam_role.name | ||
} | ||
|
||
data "aws_iam_policy_document" "iam_policy_document" { | ||
statement { | ||
effect = "Allow" | ||
actions = var.actions | ||
resources = var.resources | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy" "iam_role_policy" { | ||
name = var.name | ||
role = aws_iam_role.iam_role.name | ||
policy = data.aws_iam_policy_document.iam_policy_document.json | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "name" { | ||
description = "Name of create instance profile" | ||
value = aws_iam_instance_profile.iam_instance_profile.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
variable "name" { | ||
description = "Name used for created resources." | ||
default = null | ||
type = string | ||
} | ||
|
||
variable "actions" { | ||
description = "Actions allowed for this instance profile." | ||
default = ["logs:*"] | ||
type = list(string) | ||
} | ||
|
||
variable "resources" { | ||
description = "Resources allowed to access by this instance profile." | ||
default = ["*"] | ||
type = list(string) | ||
} |