Skip to content

Commit

Permalink
fixes for website bucket deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaiplesa committed Apr 21, 2021
1 parent f70f215 commit ec1635b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ Available targets:
| <a name="input_webhook_filter_match_equals"></a> [webhook\_filter\_match\_equals](#input\_webhook\_filter\_match\_equals) | The value to match on (e.g. refs/heads/{Branch}) | `string` | `"refs/heads/{Branch}"` | no |
| <a name="input_webhook_target_action"></a> [webhook\_target\_action](#input\_webhook\_target\_action) | The name of the action in a pipeline you want to connect to the webhook. The action must be from the source (first) stage of the pipeline | `string` | `"Source"` | no |
| <a name="input_website_bucket_name"></a> [website\_bucket\_name](#input\_website\_bucket\_name) | Name of the S3 bucket where the website will be deployed | `string` | `""` | no |
| <a name="input_website_bucket_acl"></a> [website\_bucket\_acl](#input\_website\_bucket\_acl) | Canned ACL of the S3 bucket objects that get served as a website, can be private if using CloudFront with OAI | `string` | `"public-read"` | no |

## Outputs

Expand Down
1 change: 1 addition & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
| <a name="input_webhook_filter_match_equals"></a> [webhook\_filter\_match\_equals](#input\_webhook\_filter\_match\_equals) | The value to match on (e.g. refs/heads/{Branch}) | `string` | `"refs/heads/{Branch}"` | no |
| <a name="input_webhook_target_action"></a> [webhook\_target\_action](#input\_webhook\_target\_action) | The name of the action in a pipeline you want to connect to the webhook. The action must be from the source (first) stage of the pipeline | `string` | `"Source"` | no |
| <a name="input_website_bucket_name"></a> [website\_bucket\_name](#input\_website\_bucket\_name) | Name of the S3 bucket where the website will be deployed | `string` | `""` | no |
| <a name="input_website_bucket_acl"></a> [website\_bucket\_acl](#input\_website\_bucket\_acl) | Canned ACL of the S3 bucket objects that get served as a website, can be private if using CloudFront with OAI | `string` | `"public-read"` | no |

## Outputs

Expand Down
14 changes: 11 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ resource "aws_iam_policy" "s3" {
policy = join("", data.aws_iam_policy_document.s3.*.json)
}

data "aws_s3_bucket" "website" {
count = local.enabled ? 1 : 0
bucket = var.website_bucket_name
}

data "aws_iam_policy_document" "s3" {
count = local.enabled ? 1 : 0

Expand All @@ -136,12 +141,15 @@ data "aws_iam_policy_document" "s3" {
"s3:GetObjectVersion",
"s3:GetBucketVersioning",
"s3:PutObject",
"s3:PutObjectAcl",
]

resources = [
join("", aws_s3_bucket.default.*.arn),
"arn:aws:s3:::elasticbeanstalk*",
"${join("", aws_s3_bucket.default.*.arn)}/*",
"arn:aws:s3:::elasticbeanstalk*"
join("", aws_s3_bucket.default.*.arn),
"${join("", data.aws_s3_bucket.website.*.arn)}/*",
join("", data.aws_s3_bucket.website.*.arn)
]

effect = "Allow"
Expand Down Expand Up @@ -306,7 +314,7 @@ resource "aws_codepipeline" "default" {
configuration = {
BucketName = var.website_bucket_name
Extract = "true"
CannedACL = "public-read"
CannedACL = var.website_bucket_acl
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,9 @@ variable "website_bucket_name" {
default = ""
description = "Name of the S3 bucket where the website will be deployed"
}

variable "website_bucket_acl" {
type = string
default = "public-read"
description = "Canned ACL of the S3 bucket objects that get served as a website, can be private if using CloudFront with OAI"
}

0 comments on commit ec1635b

Please sign in to comment.