Skip to content

Commit

Permalink
Add new example to show how to manage access policies
Browse files Browse the repository at this point in the history
This new example provides an example showing how to create a group to grant write access to the content bucket which could be used for the developers to manage the content.
  • Loading branch information
jonathanio committed Nov 12, 2017
1 parent 37d0691 commit c6a9caa
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/policies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Example Usage

The example in this directory is the recommended minimum needed to setup this
module (i.e. `name` and `hostname`).

## Important

This module will create an encrypted (i.e. HTTPS) endpoint in CloudFront using
[Amazon Certificate Manager](https://aws.amazon.com/certificate-manager/). ACM
cannot be automated at this time as it requires manual steps in the approval
of the domain name before it can be added into the account. Please therefore
setup the certificate for the domain name you require (and any aliases you may
include as well) by following the
[Getting Started](http://docs.aws.amazon.com/acm/latest/userguide/gs.html) guide
in the AWS Documentation.

## Usage

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

Note that this example may create resources which can cost money (logs stored
within S3, for example). Run `terraform destroy` when you don't need these
resources.
2 changes: 2 additions & 0 deletions examples/policies/aws.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Pull out useful data resources for later processing */
data "aws_caller_identity" "current" {}
10 changes: 10 additions & 0 deletions examples/policies/groups.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "aws_iam_group" "content_upload" {
name = "WebsiteDevelopers"
}

resource "aws_iam_group_policy" "content_upload" {
name = "WebsiteDeveloperAccess"
group = "${aws_iam_group.content_upload.id}"

policy = "${data.aws_iam_policy_document.content_upload.json}"
}
15 changes: 15 additions & 0 deletions examples/policies/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
provider "aws" {
region = "eu-west-2"
}

module "website" {
source = "../../"

name = "my-first-website"
hostname = "example.com"

tags {
Domain = "example.com"
Owner = "[email protected]"
}
}
15 changes: 15 additions & 0 deletions examples/policies/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
output "hostname" {
value = "${module.website.hostname}"
}

output "s3_bucket_name" {
value = "${module.website.s3_bucket_name}"
}

output "cloudfront_distribution_id" {
value = "${module.website.cloudfront_distribution_id}"
}

output "cloudfront_distribution_hostname" {
value = "${module.website.cloudfront_distribution_hostname}"
}
50 changes: 50 additions & 0 deletions examples/policies/policies.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
data "aws_iam_policy_document" "content_upload" {
statement {
sid = "AllowS3WebsiteWriteAccessCurrentUser"
effect = "Allow"

principals {
type = "AWS"

identifiers = [
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/$${aws:username}",
]
}

actions = [
"s3:DeleteObject",
"s3:DeleteObjectTagging",
"s3:Get*",
"s3:PutObject",
"s3:PutObjectAcl",
"s3:PutObjectTagging",
"s3:RestoreObject",
]

resources = [
"arn:aws:s3:::${module.website.s3_bucket_name}/*",
]
}

statement {
sid = "AllowS3WebsiteBucketAccessCurrentUser"
effect = "Allow"

principals {
type = "AWS"

identifiers = [
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/$${aws:username}",
]
}

actions = [
"s3:ListBucket",
"s3:ListBucketVersions",
]

resources = [
"arn:aws:s3:::${module.website.s3_bucket_name}",
]
}
}

0 comments on commit c6a9caa

Please sign in to comment.