Skip to content

Commit e581075

Browse files
authored
Merge pull request #282 from kmcquade/fix/GH-281-terraform-0.13-support
Adds support for Terraform 0.13
2 parents 8997dee + 78db609 commit e581075

File tree

12 files changed

+24
-66
lines changed

12 files changed

+24
-66
lines changed

README.md

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ IAM Least Privilege Policy Generator.
1919
- [Cheat sheets](#cheat-sheets)
2020
* [Policy Writing cheat sheet](#policy-writing-cheat-sheet)
2121
* [IAM Database Query Cheat Sheet](#iam-database-query-cheat-sheet)
22+
* [Local Initialization (Optional)](#local-initialization--optional-)
2223
- [Other Usage](#other-usage)
2324
* [Commands](#commands)
2425
* [Python Library usage](#python-library-usage)
@@ -441,54 +442,7 @@ cat examples/yml/actions.yml | docker run -i --rm kmcquade/policy_sentry:latest
441442

442443
### Terraform
443444

444-
The Terraform module is published and maintained [here](https://github.com/kmcquade/terraform-aws-policy-sentry).
445-
446-
* Prerequisites:
447-
- Install Policy Sentry (v0.7.2 or higher)
448-
- Install Terraform (v0.12.8 or higher)
449-
450-
* Create the `main.tf` in your directory with the following contents:
451-
452-
```hcl
453-
module "policy_sentry_demo" {
454-
source = "github.com/kmcquade/terraform-aws-policy-sentry"
455-
name = var.name
456-
read_access_level = var.read_access_level
457-
write_access_level = var.write_access_level
458-
list_access_level = var.list_access_level
459-
tagging_access_level = var.tagging_access_level
460-
permissions_management_access_level = var.permissions_management_access_level
461-
wildcard_only_actions = var.wildcard_only_actions
462-
minimize = var.minimize
463-
}
464-
```
465-
466-
* Copy and paste the contents of the `variables.tf` file [here](https://github.com/kmcquade/terraform-aws-policy-sentry/blob/master/examples/demo/variables.tf) into your directory.
467-
468-
* Create a `terraform.tfvars` file in your directory with the following contents:
469-
470-
terraform.tfvars:
471-
```hcl
472-
name = "PolicySentryTest"
473-
474-
list_access_level = [
475-
"arn:aws:s3:::example-org",
476-
]
477-
478-
read_access_level = [
479-
"arn:aws:kms:us-east-1:123456789012:key/shaq"
480-
]
481-
482-
write_access_level = [
483-
"arn:aws:kms:us-east-1:123456789012:key/shaq"
484-
]
485-
```
486-
487-
* Run `terraform apply` once to create the JSON policy file.
488-
489-
* Run `terraform apply` **again** (from the same directory) to create the IAM policy.
490-
491-
For the full example, including GIFs depicting real output, see the README for the Terraform module [here](https://github.com/kmcquade/terraform-aws-policy-sentry).
445+
The Terraform module is published and maintained [here](https://github.com/salesforce/policy_sentry/tree/master/terraform_module).
492446

493447
## References
494448

terraform_module/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# terraform-aws-policy-sentry
1+
# Policy Sentry Terraform Module
22

33
Builds secure IAM Policies with resource constraints. For more information on Policy Sentry, see [the documentation](https://policy-sentry.readthedocs.io/en/latest/).
44

55
## Prerequisites
66

77
* You must have Policy Sentry 0.10.0 installed beforehand and it must be executable from your `$PATH`. Follow the installation instructions [here](https://policy-sentry.readthedocs.io/en/latest/user-guide/installation.html)
8-
* This module currently requires Terraform 0.12.8
8+
* This module requires Terraform 0.12.8 or higher. It has been tested through 0.13.5.
99

1010
## Usage
1111

@@ -69,7 +69,7 @@ write_access_level = [
6969

7070
| Name | Version |
7171
|------|---------|
72-
| terraform | ~> 0.12.8 |
72+
| terraform | >= 0.12.8 |
7373
| aws | ~> 2.48.0 |
7474
| external | ~> 1.2 |
7575
| local | ~> 1.3 |
@@ -85,12 +85,14 @@ No provider.
8585
| Name | Description | Type | Default | Required |
8686
|------|-------------|------|---------|:--------:|
8787
| description | The description to include for the IAM policy. | `string` | `"Generated by Policy Sentry"` | no |
88+
| exclude\_actions | Exclude actions from the output by specifying them here. Accepts wildcards, like kms:Delete\* | `list(string)` | `[]` | no |
8889
| list\_access\_level | Provide a list of Amazon Resource Names (ARNs) that your role needs LIST access to. | `list(string)` | `[]` | no |
89-
| minimize | If set to true, it will minimize the size of the IAM Policy file. Defaults to false. | `bool` | `false` | no |
90+
| minimize | If set to true, it will minimize the size of the IAM Policy file. Defaults to TRUE. | `bool` | `true` | no |
9091
| name | The name of the rendered policy file (no file extension). | `string` | n/a | yes |
9192
| permissions\_management\_access\_level | Provide a list of Amazon Resource Names (ARNs) that your role needs PERMISSIONS MANAGEMENT access to. | `list(string)` | `[]` | no |
9293
| read\_access\_level | Provide a list of Amazon Resource Names (ARNs) that your role needs READ access to. | `list(string)` | `[]` | no |
9394
| region | The AWS region for these resources. Defaults to us-east-1 | `string` | `"us-east-1"` | no |
95+
| skip\_resource\_constraints | Skip resource constraint requirements by listing individual actions here, like s3:GetObject. | `list(string)` | `[]` | no |
9496
| tagging\_access\_level | Provide a list of Amazon Resource Names (ARNs) that your role needs TAGGING access to. | `list(string)` | `[]` | no |
9597
| wildcard\_only\_list\_service | To generate a list of AWS service actions that (1) are at the LIST access level and (2) do not support resource constraints, list the service prefix here. | `list(string)` | `[]` | no |
9698
| wildcard\_only\_permissions\_management\_service | To generate a list of AWS service actions that (1) are at the PERMISSIONS MANAGEMENT access level and (2) do not support resource constraints, list the service prefix here. | `list(string)` | `[]` | no |
@@ -126,6 +128,3 @@ pre-commit run -a
126128
## Todo
127129
* Publish this on Terraform module registry
128130

129-
## License
130-
131-
Copyright: © 2020 Kinnaird McQuade

terraform_module/demo/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module "policy_sentry_demo" {
1313
}
1414

1515
terraform {
16-
required_version = "~> 0.12.8"
16+
required_version = ">= 0.12.8"
1717
}
1818

1919
output "iam_policy_arn" {
@@ -23,5 +23,5 @@ output "iam_policy_arn" {
2323

2424
output "iam_policy_document" {
2525
description = "The policy document, decoded."
26-
value = jsondecode(module.policy_sentry_demo.iam_policy_document)
26+
value = module.policy_sentry_demo.iam_policy_document
2727
}

terraform_module/demo/terraform.tfvars

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ write_access_level = [
1414
skip_resource_constraints = ["s3:GetObject"]
1515

1616
exclude_actions = ["kms:Delete*"]
17+
18+
# minimize = true

terraform_module/iam-policies/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module "policies" {
1818

1919
| Name | Version |
2020
|------|---------|
21-
| terraform | ~> 0.12.8 |
21+
| terraform | >= 0.12.8 |
2222
| aws | ~> 2.48.0 |
2323
| template | ~> 2.1.2 |
2424

terraform_module/iam-policies/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = "~> 0.12.8"
2+
required_version = ">= 0.12.8"
33
}
44

55
provider "aws" {

terraform_module/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ output "iam_policy_path" {
2020

2121
output "iam_policy_document" {
2222
description = "The policy document."
23-
value = module.create_iam.iam_policy_document
23+
value = jsondecode(module.create_iam.iam_policy_document)
2424
}

terraform_module/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = "~> 0.12.8"
2+
required_version = ">= 0.12.8"
33
}
44

55
provider "aws" {

terraform_module/ps-template/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This generates the JSON policy file with Policy Sentry.
77

88
| Name | Version |
99
|------|---------|
10-
| terraform | ~> 0.12.8 |
10+
| terraform | >= 0.12.8 |
1111
| local | ~> 1.3 |
1212

1313
## Providers
@@ -21,11 +21,13 @@ This generates the JSON policy file with Policy Sentry.
2121

2222
| Name | Description | Type | Default | Required |
2323
|------|-------------|------|---------|:--------:|
24+
| exclude\_actions | Exclude actions from the output by specifying them here. Accepts wildcards, like kms:Delete\* | `list(string)` | `[]` | no |
2425
| list\_access\_level | Provide a list of Amazon Resource Names (ARNs) that your role needs LIST access to. | `list(string)` | `[]` | no |
2526
| minimize | If set to true, it will minimize the size of the IAM Policy file. Defaults to false. | `bool` | `false` | no |
2627
| name | The name of the rendered policy file (no file extension). | `string` | n/a | yes |
2728
| permissions\_management\_access\_level | Provide a list of Amazon Resource Names (ARNs) that your role needs PERMISSIONS MANAGEMENT access to. | `list(string)` | `[]` | no |
2829
| read\_access\_level | Provide a list of Amazon Resource Names (ARNs) that your role needs READ access to. | `list(string)` | `[]` | no |
30+
| skip\_resource\_constraints | Skip resource constraint requirements by listing individual actions here, like s3:GetObject. | `list(string)` | `[]` | no |
2931
| tagging\_access\_level | Provide a list of Amazon Resource Names (ARNs) that your role needs TAGGING access to. | `list(string)` | `[]` | no |
3032
| wildcard\_only\_list\_service | To generate a list of AWS service actions that (1) are at the LIST access level and (2) do not support resource constraints, list the service prefix here. | `list(string)` | `[]` | no |
3133
| wildcard\_only\_permissions\_management\_service | To generate a list of AWS service actions that (1) are at the PERMISSIONS MANAGEMENT access level and (2) do not support resource constraints, list the service prefix here. | `list(string)` | `[]` | no |

terraform_module/ps-template/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ resource "local_file" "template" {
3434
}
3535

3636
data "external" "policy" {
37-
program = concat(local.command, ["--input-file", local_file.template.filename])
37+
program = concat(local.command, ["--input-file", local_file.template.filename])
38+
depends_on = [local_file.template]
3839
}
3940

0 commit comments

Comments
 (0)