Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes and enhancements combined into a single breaking release #202

Merged
merged 13 commits into from
Aug 26, 2023

Conversation

aknysh
Copy link
Member

@aknysh aknysh commented Aug 24, 2023

Breaking Changes

Terraform version 1.3.0 or later is now required.

policy input removed

The deprecated policy input has been removed. Use source_policy_documents instead.

Convert from

policy = data.aws_iam_policy_document.log_delivery.json

to

source_policy_documents = [data.aws_iam_policy_document.log_delivery.json]

Do not use list modifiers like sort, compact, or distinct on the list, or it will trigger an Error: Invalid count argument. The length of the list must be known at plan time.

Logging configuration converted to list

To fix #182, the logging input has been converted to a list. If you have a logging configuration, simply surround it with brackets.

Replication rules brought into alignment with Terraform resource

Previously, the s3_replication_rules input had some deviations from the aws_s3_bucket_replication_configuration Terraform resource. Via the use of optional attributes, the input now closely matches the resource while providing backward compatibility, with a few exceptions.

  • Replication source_selection_criteria.sse_kms_encrypted_objects was documented as an object with one member, enabled, of type bool. However, it only worked when set to the string "Enabled". It has been replaced with the resource's choice of status of type String.
  • Previously, Replication Time Control could not be set directly. It was implicitly enabled by enabling Replication Metrics. We preserve that behavior even though we now add a configuration block for replication_time. To enable Metrics without Replication Time Control, you must set replication_time.status = "Disabled".

These are not changes, just continued deviations from the resources:

  • existing_object_replication cannot be set.
  • token to allow replication to be enabled on an Object Lock-enabled bucket cannot be set.

what

  • Remove local local.source_policy_documents and deprecated variable policy (because of that, pump the module to a major version)
  • Convert lifecycle_configuration_rules and s3_replication_rules from loosely typed objects to fully typed objects with optional attributes.
  • Use local bucket_id variable
  • Remove comments suppressing Bridgecrew rules
  • Update tests to Golang 1.20

why

explanation

Any list manipulation functions should not be used in count since it can lead to the error:

│ Error: Invalid count argument

│   on ./modules/s3_bucket/main.tf line 462, in resource "aws_s3_bucket_policy" "default":
│  462:   count      = local.enabled && (var.allow_ssl_requests_only || var.allow_encrypted_uploads_only || length(var.s3_replication_source_roles) > 0 || length(var.privileged_principal_arns) > 0 || length(local.source_policy_documents) > 0) ? 1 : 0

│ The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to
│ first apply only the resources that the count depends on.

Using the local like this

source_policy_documents = var.policy != "" && var.policy != null ? concat([var.policy], var.source_policy_documents) : var.source_policy_documents

would not work either if var.policy depends on apply-time resources from other TF modules.

General rules:

  • When using for_each, the map keys have to be known at plan time (the map values are not required to be know at plan time)

  • When using count, the length of the list must be know at plan time, the items inside the list are not. That does not mean that the list must be static with the length known in advance, the list can be dynamic and come from a remote state or data sources which Terraform evaluates first during plan, it just can’t come from other resources (which are only known after apply)

  • When using count, no list manipulating functions can be used in count - it will lead to the The "count" value depends on resource attributes that cannot be determined until apply error in some cases

@aknysh aknysh added the patch A minor, backward compatible change label Aug 24, 2023
@aknysh aknysh requested a review from Nuru August 24, 2023 00:38
@aknysh aknysh requested review from a team as code owners August 24, 2023 00:38
@aknysh aknysh requested review from Gowiem and korenyoni August 24, 2023 00:38
@aknysh
Copy link
Member Author

aknysh commented Aug 24, 2023

/terratest

Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bridgecrew has found errors in this PR ⬇️

test/src/go.mod Show resolved Hide resolved
@aknysh
Copy link
Member Author

aknysh commented Aug 24, 2023

/terratest

@aknysh
Copy link
Member Author

aknysh commented Aug 24, 2023

/terratest

@aknysh
Copy link
Member Author

aknysh commented Aug 24, 2023

/terratest

@aknysh
Copy link
Member Author

aknysh commented Aug 24, 2023

/terratest

@aknysh aknysh changed the title Remove concat function from local.source_policy_documents Remove local.source_policy_documents and deprecated variable policy Aug 25, 2023
@aknysh
Copy link
Member Author

aknysh commented Aug 25, 2023

/terratest

@aknysh aknysh added major Breaking changes (or first stable release) and removed patch A minor, backward compatible change labels Aug 25, 2023
@aknysh
Copy link
Member Author

aknysh commented Aug 25, 2023

/terratest

@aknysh
Copy link
Member Author

aknysh commented Aug 25, 2023

/terratest

@Nuru
Copy link
Contributor

Nuru commented Aug 26, 2023

/terratest

@Nuru Nuru changed the title Remove local.source_policy_documents and deprecated variable policy Bug fixes and enhancements combined into a single breaking release Aug 26, 2023
Nuru
Nuru previously approved these changes Aug 26, 2023
main.tf Show resolved Hide resolved
main.tf Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
@Nuru
Copy link
Contributor

Nuru commented Aug 26, 2023

/terratest

@Nuru Nuru self-requested a review August 26, 2023 04:31
}))
access_control_translation = optional(object({
owner = string
}))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was enabled in this PR

prefix = optional(string)
status = optional(string, "Enabled")
# delete_marker_replication { status } had been flattened for convenience
delete_marker_replication_status = optional(string, "Disabled")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major Breaking changes (or first stable release)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use generated bucket name as logging bucket Cannot add lifecycle rule to expire delete markers
3 participants