Skip to content

Commit f9e1740

Browse files
feat: Allow override of the default tags override (#261)
Co-authored-by: Anton Babenko <[email protected]>
1 parent fccafe5 commit f9e1740

File tree

7 files changed

+52
-5
lines changed

7 files changed

+52
-5
lines changed

examples/object/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Note that this example may create resources which cost money. Run `terraform des
3737
| <a name="module_object"></a> [object](#module\_object) | ../../modules/object | n/a |
3838
| <a name="module_object_complete"></a> [object\_complete](#module\_object\_complete) | ../../modules/object | n/a |
3939
| <a name="module_object_locked"></a> [object\_locked](#module\_object\_locked) | ../../modules/object | n/a |
40+
| <a name="module_object_with_override_default_tags"></a> [object\_with\_override\_default\_tags](#module\_object\_with\_override\_default\_tags) | ../../modules/object | n/a |
4041
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | ../../ | n/a |
4142
| <a name="module_s3_bucket_with_object_lock"></a> [s3\_bucket\_with\_object\_lock](#module\_s3\_bucket\_with\_object\_lock) | ../../ | n/a |
4243

examples/object/main.tf

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ provider "aws" {
55
skip_metadata_api_check = true
66
skip_region_validation = true
77
skip_credentials_validation = true
8+
9+
default_tags {
10+
tags = {
11+
Example = "object"
12+
}
13+
}
814
}
915

1016
locals {
@@ -25,6 +31,7 @@ module "object" {
2531
Sensitive = "not-really"
2632
}
2733
}
34+
2835
module "object_complete" {
2936
source = "../../modules/object"
3037

@@ -33,7 +40,7 @@ module "object_complete" {
3340

3441
content = jsonencode({ data : "value" })
3542

36-
acl = "public-read"
43+
# acl = "public-read"
3744
storage_class = "ONEZONE_IA"
3845
force_destroy = true
3946

@@ -68,6 +75,21 @@ module "object_locked" {
6875
object_lock_retain_until_date = formatdate("YYYY-MM-DD'T'hh:00:00Z", timeadd(timestamp(), "1h")) # some time in the future
6976
}
7077

78+
module "object_with_override_default_tags" {
79+
source = "../../modules/object"
80+
81+
bucket = module.s3_bucket.s3_bucket_id
82+
key = "${random_pet.this.id}-local-override-default-tags"
83+
84+
override_default_tags = true
85+
86+
file_source = "README.md"
87+
88+
tags = {
89+
Override = "true"
90+
}
91+
}
92+
7193
##################
7294
# Extra resources
7395
##################
@@ -96,7 +118,13 @@ module "s3_bucket_with_object_lock" {
96118
bucket = "${random_pet.this.id}-with-object-lock"
97119
force_destroy = true
98120

121+
object_lock_enabled = true
99122
object_lock_configuration = {
100-
object_lock_enabled = "Enabled"
123+
rule = {
124+
default_retention = {
125+
mode = "GOVERNANCE"
126+
days = 1
127+
}
128+
}
101129
}
102130
}

modules/object/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Creates S3 bucket objects with different configurations.
88
| Name | Version |
99
|------|---------|
1010
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
11-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.75 |
11+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.24 |
1212

1313
## Providers
1414

1515
| Name | Version |
1616
|------|---------|
17-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.75 |
17+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.24 |
1818

1919
## Modules
2020

@@ -50,6 +50,7 @@ No modules.
5050
| <a name="input_object_lock_legal_hold_status"></a> [object\_lock\_legal\_hold\_status](#input\_object\_lock\_legal\_hold\_status) | The legal hold status that you want to apply to the specified object. Valid values are ON and OFF. | `string` | `null` | no |
5151
| <a name="input_object_lock_mode"></a> [object\_lock\_mode](#input\_object\_lock\_mode) | The object lock retention mode that you want to apply to this object. Valid values are GOVERNANCE and COMPLIANCE. | `string` | `null` | no |
5252
| <a name="input_object_lock_retain_until_date"></a> [object\_lock\_retain\_until\_date](#input\_object\_lock\_retain\_until\_date) | The date and time, in RFC3339 format, when this object's object lock will expire. | `string` | `null` | no |
53+
| <a name="input_override_default_tags"></a> [override\_default\_tags](#input\_override\_default\_tags) | Ignore provider default\_tags. S3 objects support a maximum of 10 tags. | `bool` | `false` | no |
5354
| <a name="input_server_side_encryption"></a> [server\_side\_encryption](#input\_server\_side\_encryption) | Specifies server-side encryption of the object in S3. Valid values are "AES256" and "aws:kms". | `string` | `null` | no |
5455
| <a name="input_source_hash"></a> [source\_hash](#input\_source\_hash) | Triggers updates like etag but useful to address etag encryption limitations. Set using filemd5("path/to/source") (Terraform 0.11.12 or later). (The value is only stored in state and not saved by AWS.) | `string` | `null` | no |
5556
| <a name="input_storage_class"></a> [storage\_class](#input\_storage\_class) | Specifies the desired Storage Class for the object. Can be either STANDARD, REDUCED\_REDUNDANCY, ONEZONE\_IA, INTELLIGENT\_TIERING, GLACIER, DEEP\_ARCHIVE, or STANDARD\_IA. Defaults to STANDARD. | `string` | `null` | no |

modules/object/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ resource "aws_s3_object" "this" {
3333

3434
tags = var.tags
3535

36+
dynamic "override_provider" {
37+
for_each = var.override_default_tags ? [true] : []
38+
39+
content {
40+
default_tags {
41+
tags = {}
42+
}
43+
}
44+
}
45+
3646
lifecycle {
3747
ignore_changes = [object_lock_retain_until_date]
3848
}

modules/object/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,9 @@ variable "source_hash" {
147147
type = string
148148
default = null
149149
}
150+
151+
variable "override_default_tags" {
152+
description = "Ignore provider default_tags. S3 objects support a maximum of 10 tags."
153+
type = bool
154+
default = false
155+
}

modules/object/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 3.75"
7+
version = ">= 5.24"
88
}
99
}
1010
}

wrappers/object/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module "wrapper" {
2323
object_lock_legal_hold_status = try(each.value.object_lock_legal_hold_status, var.defaults.object_lock_legal_hold_status, null)
2424
object_lock_mode = try(each.value.object_lock_mode, var.defaults.object_lock_mode, null)
2525
object_lock_retain_until_date = try(each.value.object_lock_retain_until_date, var.defaults.object_lock_retain_until_date, null)
26+
override_default_tags = try(each.value.override_default_tags, var.defaults.override_default_tags, false)
2627
server_side_encryption = try(each.value.server_side_encryption, var.defaults.server_side_encryption, null)
2728
source_hash = try(each.value.source_hash, var.defaults.source_hash, null)
2829
storage_class = try(each.value.storage_class, var.defaults.storage_class, null)

0 commit comments

Comments
 (0)