Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from jarden-digital/feature/JSONpolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
rdunn-Hypr authored Mar 30, 2021
2 parents 01a1973 + 76a54f4 commit 9879f45
Show file tree
Hide file tree
Showing 19 changed files with 306 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ These include
* [Policy to Group](./policy-to-group/README.md) - Creates an IAM policy and group and created the attachment between them.
* [Policy to Role](./policy-to-role/README.md) - Creates an IAM policy and attaches it with an existing Role.
* [User to Group](./user-to-group/README.md) - Creates an IAM user and adds user to a list of groups.
* [Managed Role](./managed-role/README.md) - Creates an IAM role and attaches the policy to it.

## ADR's

Expand Down
1 change: 1 addition & 0 deletions examples/managed_role/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform.tfvars
16 changes: 16 additions & 0 deletions examples/managed_role/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module "example" {
source = "../../managed-role"

providers = {
aws = aws
}
policy_name = var.policy_name
policy_description = var.policy_description
policy_document = jsonencode(var.policy_document)
role_name = var.role_name
assume_role_policy_document = jsonencode(var.assume_role_policy_document)
tags = var.tags
}
provider "aws" {
region = var.region
}
32 changes: 32 additions & 0 deletions examples/managed_role/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

variable "region" {
type = string
default = "ap-southeast-2"
}

variable "policy_name" {
description = "The name of the policy to create"
}

variable "policy_description" {
description = "A description of the policy"
default = ""
}

variable "policy_document" {
description = "JSON policy document"
}

variable "assume_role_policy_document" {
description = "Json policy document"
}

variable "tags" {
description = "Additional tags to add to IAM Role Resource."
type = map(any)
default = {}
}

variable "role_name" {
description = "The name of the role"
}
36 changes: 36 additions & 0 deletions managed-role/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Terraform Managed role module

This module creates an IAM role and attaches the policy to it.. It uses role and policy modules to create the resources. Refer Resources section for more details.

## Requirements

| Name | Version |
|------|---------|
| terraform | >= 0.12.26 |

## Providers

| Name | Version |
|------|---------|
| aws | n/a |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| assume\_role\_policy\_document | Json policy document | `any` | n/a | yes |
| policy\_description | A description of the policy | `string` | `""` | no |
| policy\_document | JSON policy document | `any` | n/a | yes |
| policy\_name | The name of the policy to create | `any` | n/a | yes |
| role\_name | The name of the role | `any` | n/a | yes |
| tags | Additional tags to add to IAM Role Resource. | `map(any)` | `{}` | no |

## Outputs

| Name | Description |
|------|-------------|
| policy\_arn | The arn of the policy created |
| policy\_name | The name of the policy created |
| role\_arn | The arn of the role created |
| role\_name | The name of the role created |

20 changes: 20 additions & 0 deletions managed-role/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module "role" {
source = "../resources/role"
role_name = var.role_name
assume_role_policy_document = var.assume_role_policy_document
tags = var.tags
}


module "policy" {
source = "../resources/policy"
policy_name = var.policy_name
policy_description = var.policy_description
policy_document = var.policy_document
}

resource "aws_iam_role_policy_attachment" "this" {
role = module.role.role_name
policy_arn = module.policy.policy_arn
}

22 changes: 22 additions & 0 deletions managed-role/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
output "policy_name" {
description = "The name of the policy created"
value = module.policy.policy_name
}


output "policy_arn" {
description = "The arn of the policy created"
value = module.policy.policy_arn
}


output "role_arn" {
description = "The arn of the role created"
value = module.role.role_arn
}


output "role_name" {
description = "The name of the role created"
value = module.role.role_name
}
28 changes: 28 additions & 0 deletions managed-role/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
variable "policy_name" {
description = "The name of the policy to create"
}

variable "policy_description" {
description = "A description of the policy"
default = ""
}

variable "policy_document" {
description = "JSON policy document"
}

variable "assume_role_policy_document" {
description = "Json policy document"
}

variable "tags" {
description = "Additional tags to add to IAM Role Resource."
type = map(any)
default = {}
}

variable "role_name" {
description = "The name of the role"
}


10 changes: 10 additions & 0 deletions managed-role/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 0.12.26"

required_providers {
aws = {
source : "hashicorp/aws",
required_version : ">= 3.21.0"
}
}
}
30 changes: 30 additions & 0 deletions resources/policy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Terraform Policy module

This module creates an IAM Policy with the provided policy document.
## Requirements

| Name | Version |
|------|---------|
| terraform | >= 0.12.26 |

## Providers

| Name | Version |
|------|---------|
| aws | n/a |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| policy\_description | A description of the policy | `string` | `""` | no |
| policy\_document | JSON policy document | `any` | n/a | yes |
| policy\_name | The name of the policy to create | `any` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| policy\_arn | The name of the policy created |
| policy\_name | The name of the policy created |

8 changes: 8 additions & 0 deletions resources/policy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

resource "aws_iam_policy" "this" {
name = var.policy_name
description = var.policy_description
path = "/"
policy = var.policy_document
}

10 changes: 10 additions & 0 deletions resources/policy/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
output "policy_name" {
description = "The name of the policy created"
value = aws_iam_policy.this.name
}


output "policy_arn" {
description = "The name of the policy created"
value = aws_iam_policy.this.arn
}
13 changes: 13 additions & 0 deletions resources/policy/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
variable "policy_name" {
description = "The name of the policy to create"
}

variable "policy_description" {
description = "A description of the policy"
default = ""
}

variable "policy_document" {
description = "JSON policy document"
}

10 changes: 10 additions & 0 deletions resources/policy/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 0.12.26"

required_providers {
aws = {
source : "hashicorp/aws",
required_version : ">= 3.21.0"
}
}
}
30 changes: 30 additions & 0 deletions resources/role/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Terraform Role module

This module creates an IAM Role and attaches the provided assume role policy to the role.
## Requirements

| Name | Version |
|------|---------|
| terraform | >= 0.12.26 |

## Providers

| Name | Version |
|------|---------|
| aws | n/a |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| assume\_role\_policy\_document | Json policy document | `any` | n/a | yes |
| role\_name | The name of the role | `any` | n/a | yes |
| tags | Additional tags to add to IAM Role Resource. | `map(any)` | `{}` | no |

## Outputs

| Name | Description |
|------|-------------|
| role\_arn | The arn of the policy created |
| role\_name | The arn of the policy created |

6 changes: 6 additions & 0 deletions resources/role/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "aws_iam_role" "this" {
name = var.role_name
assume_role_policy = var.assume_role_policy_document
tags = var.tags
}

10 changes: 10 additions & 0 deletions resources/role/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
output "role_arn" {
description = "The arn of the role created"
value = aws_iam_role.this.arn
}


output "role_name" {
description = "The name of the role created"
value = aws_iam_role.this.name
}
13 changes: 13 additions & 0 deletions resources/role/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
variable "assume_role_policy_document" {
description = "Json policy document"
}

variable "tags" {
description = "Additional tags to add to IAM Role Resource."
type = map(any)
default = {}
}

variable "role_name" {
description = "The name of the role that needs to be created"
}
10 changes: 10 additions & 0 deletions resources/role/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 0.12.26"

required_providers {
aws = {
source : "hashicorp/aws",
required_version : ">= 3.21.0"
}
}
}

0 comments on commit 9879f45

Please sign in to comment.