Skip to content

Commit

Permalink
added iam modules
Browse files Browse the repository at this point in the history
  • Loading branch information
pmn3232 authored Dec 11, 2021
0 parents commit 6dc6298
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
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`
41 changes: 41 additions & 0 deletions main.tf
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
}
4 changes: 4 additions & 0 deletions outputs.tf
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
}
17 changes: 17 additions & 0 deletions variables.tf
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)
}

0 comments on commit 6dc6298

Please sign in to comment.