This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jarden-digital/feature/JSONpolicy
Thanks @shikhaFNZC
- Loading branch information
Showing
19 changed files
with
306 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
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 @@ | ||
terraform.tfvars |
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,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 | ||
} |
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,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" | ||
} |
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,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 | | ||
|
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,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 | ||
} | ||
|
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,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 | ||
} |
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,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" | ||
} | ||
|
||
|
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,10 @@ | ||
terraform { | ||
required_version = ">= 0.12.26" | ||
|
||
required_providers { | ||
aws = { | ||
source : "hashicorp/aws", | ||
required_version : ">= 3.21.0" | ||
} | ||
} | ||
} |
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,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 | | ||
|
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,8 @@ | ||
|
||
resource "aws_iam_policy" "this" { | ||
name = var.policy_name | ||
description = var.policy_description | ||
path = "/" | ||
policy = var.policy_document | ||
} | ||
|
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,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 | ||
} |
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,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" | ||
} | ||
|
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,10 @@ | ||
terraform { | ||
required_version = ">= 0.12.26" | ||
|
||
required_providers { | ||
aws = { | ||
source : "hashicorp/aws", | ||
required_version : ">= 3.21.0" | ||
} | ||
} | ||
} |
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,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 | | ||
|
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,6 @@ | ||
resource "aws_iam_role" "this" { | ||
name = var.role_name | ||
assume_role_policy = var.assume_role_policy_document | ||
tags = var.tags | ||
} | ||
|
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,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 | ||
} |
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,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" | ||
} |
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,10 @@ | ||
terraform { | ||
required_version = ">= 0.12.26" | ||
|
||
required_providers { | ||
aws = { | ||
source : "hashicorp/aws", | ||
required_version : ">= 3.21.0" | ||
} | ||
} | ||
} |