Skip to content

Commit dfd9041

Browse files
author
Steven Nemetz
committed
Add new example to sho wcreating an IAM policy for s3 buckets
1 parent 3b1c2ec commit dfd9041

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

examples/policy/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Example: Managing multiple S3 buckets and create policy for them

examples/policy/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module "s3" {
2+
source = "../../"
3+
names = ["bucket-1", "bucket2", "bucket_3"]
4+
environment = "${var.environment}"
5+
organization = "${var.organization}"
6+
}
7+
8+
data "aws_iam_policy_document" "s3" {
9+
statement {
10+
actions = ["s3:*"]
11+
effect = "Allow"
12+
resources = ["${formatlist("%s/*", module.s3.arns)}"]
13+
}
14+
}

examples/policy/outputs.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
output "arns" {
2+
description = "List of AWS S3 Bucket ARNs"
3+
value = "${module.s3.arns}"
4+
}
5+
6+
output "domain_names" {
7+
description = "List of AWS S3 Bucket Domain Names"
8+
value = "${module.s3.domain_names}"
9+
}
10+
11+
output "hosted_zone_ids" {
12+
description = "List of AWS S3 Bucket Hosted Zone IDs"
13+
value = "${module.s3.hosted_zone_ids}"
14+
}
15+
16+
output "ids" {
17+
description = "List of AWS S3 Bucket IDs"
18+
value = "${module.s3.ids}"
19+
}
20+
21+
output "names" {
22+
description = "List of AWS S3 Bucket Names"
23+
value = "${module.s3.names}"
24+
}
25+
26+
output "regions" {
27+
description = "List of AWS S3 Bucket Regions"
28+
value = "${module.s3.regions}"
29+
}
30+
31+
// Unique to this example
32+
output "policy" {
33+
value = "${data.aws_iam_policy_document.s3.json}"
34+
}

examples/policy/provider.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = "${var.region}"
3+
}

examples/policy/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "environment" {
2+
default = "dev"
3+
}
4+
5+
variable "organization" {
6+
default = "testorg"
7+
}
8+
9+
variable "region" {
10+
default = "us-west-2"
11+
}

0 commit comments

Comments
 (0)