Skip to content

Commit ac43e7b

Browse files
authored
feat: add user_policy_document parameter (#142)
1 parent 99453cc commit ac43e7b

File tree

8 files changed

+65
-61
lines changed

8 files changed

+65
-61
lines changed

.github/renovate.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"extends": [
33
"config:base",
4-
":preserveSemverRanges"
4+
":preserveSemverRanges",
5+
":rebaseStalePrs"
56
],
6-
"baseBranches": ["main", "master", "/^release\\/v\\d{1,2}$/"],
7+
"baseBranches": ["main"],
78
"labels": ["auto-update"],
89
"dependencyDashboardAutoclose": true,
910
"enabledManagers": ["terraform"],
1011
"terraform": {
11-
"ignorePaths": ["**/context.tf", "examples/**"]
12+
"ignorePaths": ["**/context.tf"]
1213
}
1314
}

.github/workflows/release-branch.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- 'docs/**'
1111
- 'examples/**'
1212
- 'test/**'
13+
- 'README.*'
1314

1415
permissions:
1516
contents: write

.github/workflows/release-published.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ permissions:
1111

1212
jobs:
1313
terraform-module:
14-
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release.yml@main
14+
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release-published.yml@main

README.md

Lines changed: 18 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ __NOTE:__ This module cannot be used to apply changes to the `mfa_delete` featur
4848
---
4949

5050
This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps.
51-
[<img align="right" title="Share via Email" src="https://docs.cloudposse.com/images/ionicons/ios-email-outline-2.0.1-16x16-999999.svg"/>][share_email]
52-
[<img align="right" title="Share on Google+" src="https://docs.cloudposse.com/images/ionicons/social-googleplus-outline-2.0.1-16x16-999999.svg" />][share_googleplus]
53-
[<img align="right" title="Share on Facebook" src="https://docs.cloudposse.com/images/ionicons/social-facebook-outline-2.0.1-16x16-999999.svg" />][share_facebook]
54-
[<img align="right" title="Share on Reddit" src="https://docs.cloudposse.com/images/ionicons/social-reddit-outline-2.0.1-16x16-999999.svg" />][share_reddit]
55-
[<img align="right" title="Share on LinkedIn" src="https://docs.cloudposse.com/images/ionicons/social-linkedin-outline-2.0.1-16x16-999999.svg" />][share_linkedin]
56-
[<img align="right" title="Share on Twitter" src="https://docs.cloudposse.com/images/ionicons/social-twitter-outline-2.0.1-16x16-999999.svg" />][share_twitter]
5751

5852

5953
[![Terraform Open Source Modules](https://docs.cloudposse.com/images/terraform-open-source-modules.svg)][terraform_modules]
@@ -103,10 +97,6 @@ We highly recommend that in your code you pin the version to the exact version y
10397
using so that your infrastructure remains stable, and update versions in a
10498
systematic way so that they do not catch you by surprise.
10599

106-
Also, because of a bug in the Terraform registry ([hashicorp/terraform#21417](https://github.com/hashicorp/terraform/issues/21417)),
107-
the registry shows many of our inputs as required when in fact they are optional.
108-
The table below correctly indicates which inputs are required.
109-
110100

111101

112102
### Create
@@ -251,13 +241,15 @@ Available targets:
251241
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.1.0 |
252242
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9.0 |
253243
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 2.0 |
244+
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.7.1 |
254245

255246
## Providers
256247

257248
| Name | Version |
258249
|------|---------|
259250
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9.0 |
260251
| <a name="provider_local"></a> [local](#provider\_local) | >= 2.0 |
252+
| <a name="provider_time"></a> [time](#provider\_time) | >= 0.7.1 |
261253

262254
## Modules
263255

@@ -286,6 +278,8 @@ Available targets:
286278
| [aws_s3_bucket_server_side_encryption_configuration.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
287279
| [aws_s3_bucket_versioning.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_versioning) | resource |
288280
| [local_file.terraform_backend_config](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
281+
| [time_sleep.wait_for_aws_s3_bucket_settings](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
282+
| [aws_iam_policy_document.aggregated_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
289283
| [aws_iam_policy_document.bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
290284
| [aws_iam_policy_document.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
291285
| [aws_iam_policy_document.replication_sts](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
@@ -334,6 +328,7 @@ Available targets:
334328
| <a name="input_s3_bucket_name"></a> [s3\_bucket\_name](#input\_s3\_bucket\_name) | S3 bucket name. If not provided, the name will be generated from the context by the label module. | `string` | `""` | no |
335329
| <a name="input_s3_replica_bucket_arn"></a> [s3\_replica\_bucket\_arn](#input\_s3\_replica\_bucket\_arn) | The ARN of the S3 replica bucket (destination) | `string` | `""` | no |
336330
| <a name="input_s3_replication_enabled"></a> [s3\_replication\_enabled](#input\_s3\_replication\_enabled) | Set this to true and specify `s3_replica_bucket_arn` to enable replication | `bool` | `false` | no |
331+
| <a name="input_source_policy_documents"></a> [source\_policy\_documents](#input\_source\_policy\_documents) | List of IAM policy documents (in JSON format) that are merged together into the generated S3 bucket policy.<br>Statements must have unique SIDs.<br>Statement having SIDs that match policy SIDs generated by this module will override them. | `list(string)` | `[]` | no |
337332
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
338333
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br>Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
339334
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
@@ -364,8 +359,6 @@ Available targets:
364359

365360
Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-aws-tfstate-backend)! (it helps us **a lot**)
366361

367-
Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =)
368-
369362

370363

371364
## Related Projects
@@ -409,10 +402,6 @@ We deliver 10x the value for a fraction of the cost of a full-time engineer. Our
409402

410403
Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure.
411404

412-
## Discourse Forums
413-
414-
Participate in our [Discourse Forums][discourse]. Here you'll find answers to commonly asked questions. Most questions will be related to the enormous number of projects we support on our GitHub. Come here to collaborate on answers, find solutions, and get ideas about the products and services we value. It only takes a minute to get started! Just sign in with SSO using your GitHub account.
415-
416405
## Newsletter
417406

418407
Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
@@ -423,7 +412,18 @@ Sign up for [our newsletter][newsletter] that covers everything on our technolog
423412

424413
[![zoom](https://img.cloudposse.com/fit-in/200x200/https://cloudposse.com/wp-content/uploads/2019/08/Powered-by-Zoom.png")][office_hours]
425414

426-
## Contributing
415+
## ✨ Contributing
416+
417+
418+
419+
This project is under active development, and we encourage contributions from our community.
420+
Many thanks to our outstanding contributors:
421+
422+
<a href="https://github.com/cloudposse/terraform-aws-tfstate-backend/graphs/contributors">
423+
<img src="https://contrib.rocks/image?repo=cloudposse/terraform-aws-tfstate-backend&max=24" />
424+
</a>
425+
426+
427427

428428
### Bug Reports & Feature Requests
429429

@@ -497,35 +497,7 @@ We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. W
497497

498498
We offer [paid support][commercial_support] on all of our projects.
499499

500-
Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.
501-
502-
503-
504-
### Contributors
505-
506-
<!-- markdownlint-disable -->
507-
| [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Maarten van der Hoef][maartenvanderhoef_avatar]][maartenvanderhoef_homepage]<br/>[Maarten van der Hoef][maartenvanderhoef_homepage] | [![Vladimir][SweetOps_avatar]][SweetOps_homepage]<br/>[Vladimir][SweetOps_homepage] | [![Chris Weyl][rsrchboy_avatar]][rsrchboy_homepage]<br/>[Chris Weyl][rsrchboy_homepage] | [![John McGehee][jmcgeheeiv_avatar]][jmcgeheeiv_homepage]<br/>[John McGehee][jmcgeheeiv_homepage] | [![Oliver L Schoenborn][schollii_avatar]][schollii_homepage]<br/>[Oliver L Schoenborn][schollii_homepage] | [![RB][nitrocode_avatar]][nitrocode_homepage]<br/>[RB][nitrocode_homepage] |
508-
|---|---|---|---|---|---|---|---|
509-
<!-- markdownlint-restore -->
510-
511-
[aknysh_homepage]: https://github.com/aknysh
512-
[aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png
513-
[osterman_homepage]: https://github.com/osterman
514-
[osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png
515-
[maartenvanderhoef_homepage]: https://github.com/maartenvanderhoef
516-
[maartenvanderhoef_avatar]: https://img.cloudposse.com/150x150/https://github.com/maartenvanderhoef.png
517-
[SweetOps_homepage]: https://github.com/SweetOps
518-
[SweetOps_avatar]: https://img.cloudposse.com/150x150/https://github.com/SweetOps.png
519-
[rsrchboy_homepage]: https://github.com/rsrchboy
520-
[rsrchboy_avatar]: https://img.cloudposse.com/150x150/https://github.com/rsrchboy.png
521-
[jmcgeheeiv_homepage]: https://github.com/jmcgeheeiv
522-
[jmcgeheeiv_avatar]: https://img.cloudposse.com/150x150/https://github.com/jmcgeheeiv.png
523-
[schollii_homepage]: https://github.com/schollii
524-
[schollii_avatar]: https://img.cloudposse.com/150x150/https://github.com/schollii.png
525-
[nitrocode_homepage]: https://github.com/nitrocode
526-
[nitrocode_avatar]: https://img.cloudposse.com/150x150/https://github.com/nitrocode.png
527-
528-
[![README Footer][readme_footer_img]][readme_footer_link]
500+
Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.[![README Footer][readme_footer_img]][readme_footer_link]
529501
[![Beacon][beacon]][website]
530502
<!-- markdownlint-disable -->
531503
[logo]: https://cloudposse.com/logo-300x69.svg
@@ -535,12 +507,10 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
535507
[jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=jobs
536508
[hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=hire
537509
[slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=slack
538-
[linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=linkedin
539510
[twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=twitter
540511
[testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=testimonial
541512
[office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=office_hours
542513
[newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=newsletter
543-
[discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=discourse
544514
[email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=email
545515
[commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=commercial_support
546516
[we_love_open_source]: https://cpco.io/we-love-open-source?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=we_love_open_source
@@ -551,11 +521,5 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
551521
[readme_footer_link]: https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=readme_footer_link
552522
[readme_commercial_support_img]: https://cloudposse.com/readme/commercial-support/img
553523
[readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-tfstate-backend&utm_content=readme_commercial_support_link
554-
[share_twitter]: https://twitter.com/intent/tweet/?text=terraform-aws-tfstate-backend&url=https://github.com/cloudposse/terraform-aws-tfstate-backend
555-
[share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-aws-tfstate-backend&url=https://github.com/cloudposse/terraform-aws-tfstate-backend
556-
[share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-aws-tfstate-backend
557-
[share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-aws-tfstate-backend
558-
[share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-aws-tfstate-backend
559-
[share_email]: mailto:?subject=terraform-aws-tfstate-backend&body=https://github.com/cloudposse/terraform-aws-tfstate-backend
560524
[beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-aws-tfstate-backend?pixel&cs=github&cm=readme&an=terraform-aws-tfstate-backend
561525
<!-- markdownlint-restore -->

docs/terraform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.1.0 |
77
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9.0 |
88
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 2.0 |
9+
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.7.1 |
910

1011
## Providers
1112

1213
| Name | Version |
1314
|------|---------|
1415
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9.0 |
1516
| <a name="provider_local"></a> [local](#provider\_local) | >= 2.0 |
17+
| <a name="provider_time"></a> [time](#provider\_time) | >= 0.7.1 |
1618

1719
## Modules
1820

@@ -41,6 +43,8 @@
4143
| [aws_s3_bucket_server_side_encryption_configuration.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
4244
| [aws_s3_bucket_versioning.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_versioning) | resource |
4345
| [local_file.terraform_backend_config](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
46+
| [time_sleep.wait_for_aws_s3_bucket_settings](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
47+
| [aws_iam_policy_document.aggregated_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
4448
| [aws_iam_policy_document.bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
4549
| [aws_iam_policy_document.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
4650
| [aws_iam_policy_document.replication_sts](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
@@ -89,6 +93,7 @@
8993
| <a name="input_s3_bucket_name"></a> [s3\_bucket\_name](#input\_s3\_bucket\_name) | S3 bucket name. If not provided, the name will be generated from the context by the label module. | `string` | `""` | no |
9094
| <a name="input_s3_replica_bucket_arn"></a> [s3\_replica\_bucket\_arn](#input\_s3\_replica\_bucket\_arn) | The ARN of the S3 replica bucket (destination) | `string` | `""` | no |
9195
| <a name="input_s3_replication_enabled"></a> [s3\_replication\_enabled](#input\_s3\_replication\_enabled) | Set this to true and specify `s3_replica_bucket_arn` to enable replication | `bool` | `false` | no |
96+
| <a name="input_source_policy_documents"></a> [source\_policy\_documents](#input\_source\_policy\_documents) | List of IAM policy documents (in JSON format) that are merged together into the generated S3 bucket policy.<br>Statements must have unique SIDs.<br>Statement having SIDs that match policy SIDs generated by this module will override them. | `list(string)` | `[]` | no |
9297
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
9398
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br>Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
9499
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |

main.tf

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ locals {
88

99
prevent_unencrypted_uploads = local.enabled && var.prevent_unencrypted_uploads
1010

11-
policy = one(data.aws_iam_policy_document.bucket_policy[*].json)
11+
policy = one(data.aws_iam_policy_document.aggregated_policy[*].json)
1212

1313
terraform_backend_config_file = format(
1414
"%s/%s",
@@ -53,6 +53,14 @@ module "bucket_label" {
5353

5454
data "aws_region" "current" {}
5555

56+
data "aws_iam_policy_document" "aggregated_policy" {
57+
count = local.enabled ? 1 : 0
58+
59+
source_policy_documents = [one(data.aws_iam_policy_document.bucket_policy[*].json)]
60+
override_policy_documents = var.source_policy_documents
61+
}
62+
63+
5664
data "aws_iam_policy_document" "bucket_policy" {
5765
count = local.enabled ? 1 : 0
5866

@@ -162,8 +170,9 @@ resource "aws_s3_bucket" "default" {
162170
resource "aws_s3_bucket_policy" "default" {
163171
count = local.bucket_enabled ? 1 : 0
164172

165-
bucket = one(aws_s3_bucket.default[*].id)
166-
policy = local.policy
173+
bucket = one(aws_s3_bucket.default[*].id)
174+
policy = local.policy
175+
depends_on = [aws_s3_bucket_public_access_block.default]
167176
}
168177

169178
resource "aws_s3_bucket_acl" "default" {
@@ -228,6 +237,16 @@ resource "aws_s3_bucket_ownership_controls" "default" {
228237
rule {
229238
object_ownership = var.bucket_ownership_enforced_enabled ? "BucketOwnerEnforced" : "BucketOwnerPreferred"
230239
}
240+
depends_on = [time_sleep.wait_for_aws_s3_bucket_settings]
241+
}
242+
243+
# Workaround S3 eventual consistency for settings objects
244+
resource "time_sleep" "wait_for_aws_s3_bucket_settings" {
245+
count = local.enabled ? 1 : 0
246+
247+
depends_on = [aws_s3_bucket_public_access_block.default, aws_s3_bucket_policy.default]
248+
create_duration = "30s"
249+
destroy_duration = "30s"
231250
}
232251

233252
module "dynamodb_table_label" {

0 commit comments

Comments
 (0)