Ignore Deployed Artifacts
Adds ignore_changes for the artifact pointer a deployment pipeline rewrites on Lambda functions and ECS services. The next plan stops rolling the deployed version back.
When to use this rule
Use this when: Something other than Terraform deploys the code: a CI pipeline uploads the Lambda zip or container image, or a deployer publishes ECS task definition revisions.
Do not use this when: Terraform builds the artifact itself (create_package = true in the Lambda module), builds the container image, or publishes the ECS task definition revisions. Ignoring the pointer would pin the service to a stale revision.
Why this rule exists
When a pipeline deploys code by uploading a new zip or image, or by publishing a new task definition revision, Terraform's state still holds the previous pointer. The next plan reads the live value as drift and proposes putting the old version back.
The fix is ignore_changes on exactly those attributes, and a lifecycle block cannot be passed into an upstream module as a variable.
Related Terraform and OpenTofu issues
| Repository | Issue | Title |
|---|---|---|
| hashicorp/terraform | #27360 | A method to override configuration and meta arguments within a module |
| hashicorp/terraform | #24188 | Support for dynamic blocks and meta-arguments |
| hashicorp/terraform-provider-aws | #19583 | Provider produced inconsistent final plan / an invalid new value for .tags_all |
Limitations this rule answers
Per-module pages under Workarounds where this rule is the answer, each with the native workaround first and the diff the rule makes:
- ECS: Terraform reverts the task definition my pipeline just deployed
- Lambda: Terraform keeps reverting my Lambda code to an old version
Affected resources
| Resource | Service | Why |
|---|---|---|
aws_lambda_function | AWS Lambda | The zip in S3, its object version, its hash, or the container image a pipeline deploys |
aws_ecs_service | Amazon ECS | The task definition revision a deployer publishes |
What this rule does
Adds a lifecycle { ignore_changes = [...] } block to each matching resource. Terraform and OpenTofu will ignore external changes to the listed attributes on subsequent plans.
Ignored attributes: s3_key, s3_object_version, source_code_hash, image_uri
Adds a lifecycle { ignore_changes = [...] } block to each matching resource. Terraform and OpenTofu will ignore external changes to the listed attributes on subsequent plans.
Ignored attributes: task_definition
Before and after
Before (upstream module):
resource "aws_lambda_function" "this" {
# ... resource configuration ...
tags = var.tags
}After (with Ignore Deployed Artifacts applied):
resource "aws_lambda_function" "this" {
# ... resource configuration ...
tags = var.tags
lifecycle {
ignore_changes = [s3_key, s3_object_version, source_code_hash, image_uri]
}
}Before (upstream module):
resource "aws_lambda_function" "this" {
# ... resource configuration ...
tags = var.tags
}After (with Ignore Deployed Artifacts applied):
resource "aws_lambda_function" "this" {
# ... resource configuration ...
tags = var.tags
lifecycle {
ignore_changes = [task_definition]
}
}The only change is the rule transformation. All existing arguments, outputs, and module behavior remain identical.
Real-world scenario
A deployment pipeline published a new task definition revision on Friday. Monday's routine apply rolled the service back to the revision in Terraform state, because the service's task_definition was still managed.
The example above is illustrative. To see this rule run for real, open it in the
Rules Playground β it applies lifecycle_ignore_deployed_artifacts to a
reviewed upstream module that actually declares the resources this rule targets,
and shows the diff the registry would serve. No account needed.
Known limits
- Lambda: only
s3_key,s3_object_version,source_code_hashandimage_uriby default; ECS: onlytask_definition. Each list is a parameter and an organization can set it to[]to contribute nothing for that resource type. - Only
aws_lambda_functionandaws_ecs_service. Aliases, published Lambda versions and ECS task definitions themselves are not touched. - Does not deploy anything. It only stops Terraform from reverting what the deployer wrote.
- Only
.tfand.tofufiles are read. Modules written in JSON syntax (.tf.json,.tofu.json) are left untouched. - Only the module's own directory and its first-level
modules/*submodules are processed. Modules that this module calls by source URL are separate downloads and are handled on their own request.
Default configuration
These are the values the rule ships with. They are not settable from a module source URL: ?rules= carries rule names only, so a per-request enable uses exactly the defaults below. Your organization sets them per rule, in its Baseline or in a ruleset, from the Operational Rules page; see Baseline rules and rulesets.
| Parameter | Type | Default | Description |
|---|---|---|---|
lambda_ignore_changes | list(string) | ["s3_key", "s3_object_version", "source_code_hash", "image_uri"] | Attributes naming the deployed Lambda artifact (zip in S3, its version, its hash, or the container image). Override to [] to contribute nothing to the merged set |
lambda_resource_types | list(string) | ["aws_lambda_function"] | Resource types carrying the Lambda artifact pointer |
ecs_service_ignore_changes | list(string) | ["task_definition"] | Attributes naming the deployed ECS task definition revision. Assumes an external deployer publishes revisions; if Terraform publishes them this pins the service to a stale revision. Override to [] to contribute nothing to the merged set |
ecs_service_resource_types | list(string) | ["aws_ecs_service"] | Resource types carrying the ECS task definition pointer |
The rule's definition
The HCL this rule is written in - its parameters, their shipped defaults, and the transformers it runs - is published at lifecycle_ignore_deployed_artifacts, alongside every other selectable rule.
How to enable
On a framework host, per request:
Add ?rules=lifecycle_ignore_deployed_artifacts to your HTTPS module source, using the id exactly as written.
module "example" {
source = "https://soc2.compliance.tf/terraform-aws-modules/s3-bucket/aws?version=5.0.0&rules=lifecycle_ignore_deployed_artifacts"
}A ?rules= list is either all bare names, which replace your organization's rules for that download, or all - prefixed names, which subtract from them. Mixing the two is refused with a 400 rather than silently treated as a replacement. To add this rule on top of your organization's rules instead, use ?add_rules=lifecycle_ignore_deployed_artifacts; a bare ?rules= list cannot be combined with it, because a bare list already replaced the set there was something to add to.
The + add prefix was removed. It reached the registry only when written %2B, and a literal + in a query string decodes to a space everywhere, so ?rules=+lifecycle_ignore_deployed_artifacts arrived as a bare name with a leading space β one step from silently replacing your organization's rules. Any +, in either spelling, is now a 400 naming ?add_rules=.
On your organization's host:
Add the rule to the organization's Baseline, which applies to every module served from the bare organization form <alias>.compliance.tf/<namespace>/<name>/<provider>, or to a named ruleset that one module selects with ?ruleset=<name> on the HTTPS form of that address. A project environment (<alias>.compliance.tf/<project>/<env>/<module>) serves the rules frozen in its bound snapshot instead: there the rule goes into the config draft and reaches the environment by promotion. On both organization forms ?rules= and ?add_rules= are refused with a 400 β including the subtractive - prefix β rather than dropped, so you cannot mistake an ignored override for an applied one. Change the configuration, not the URL. See Baseline rules and rulesets for the configuration flow, and registry resolution for how the address forms differ.
Break-glass path
On a framework host, add ?rules=-lifecycle_ignore_deployed_artifacts to the module source URL and run terraform init -upgrade to fetch a copy without this rule. The copy in .terraform/modules/ stays until the next upgrade, so remove the override when you are done. On your organization's host the parameter is refused with a 400 rather than ignored. The rule comes from the organization's configuration: a Baseline rule applies to every module served from the bare organization form, so an admin disables it for the duration of the operation, or keeps it out of the Baseline and in a ruleset that only the modules needing it select. On a project environment the posture is the bound snapshot and its waivers. See Baseline rules and rulesets.
Failure modes
| Scenario | Result |
|---|---|
| Rule targets a module with no matching resource types | No-op. Module is delivered unchanged and the manifest records not_applicable. |
| Terraform is also the deployer | A new artifact set through Terraform is ignored on the next plan and never applied. Do not enable the rule for that module. |
The resource already carries an ignore_changes list | The list is kept and the attributes are merged in; nothing already ignored is removed. |
Terraform and OpenTofu compatible
This rule works with both Terraform (1.x+) and OpenTofu (1.6+). It reads ordinary HCL, and anything it changes stays ordinary HCL, so the module behaves the same under either tool.
Help us improve this page
Operational Rules are a new feature. We'd love your feedback on this rule page β what's useful, what's missing, what's confusing. Share feedback.