Closed duganth-va closed 6 months ago
I've encountered the exact same issue also while writing an ELB module. Only encountered the problem when Terraform is creating the bucket in the same apply as the ALB / NLB. No problems if the bucket exists already.
Same exact issue as @seanturner026. I can also confirm that it worked on the second run.
Any workaround for this?
At least here on terraform 0.12.31 this happens even without the use of a dynamic
block for the access_logs
.
Both with the (broken) simplified conditional form:
resource "aws_lb" "alb" {
...
access_logs {
enabled = var.access_logs_bucket != null ? true : false
bucket = var.access_logs_bucket
prefix = var.name
}
}
As well as with the dynamic
form as a workaround for the related but different aws_lb
access_logs
issue: https://github.com/hashicorp/terraform-provider-aws/issues/2072#issuecomment-873887700
dynamic "access_logs" {
for_each = var.access_logs_bucket != null ? { enabled = true } : {}
content {
enabled = true
bucket = var.access_logs_bucket
prefix = var.name
}
}
The terraform plan
is only seeing the access_logs { enabled => ... }
parameter in the terraform plan - both the bucket
and prefix
are missing:
Terraform will perform the following actions:
# module.aws_alb.aws_lb.alb will be updated in-place
~ resource "aws_lb" "alb" {
...
~ access_logs {
~ enabled = false -> (known after apply)
}
}
And the terraform apply
produces errors for both access_logs
attributes which were missing from the plan:
Error: Provider produced inconsistent final plan
When expanding the plan for module.aws_alb.aws_lb.alb to include new values
learned so far during apply, provider "registry.terraform.io/-/aws" produced
an invalid new value for .access_logs[0].bucket: was cty.StringVal(""), but
now cty.StringVal("aws-harri-test.alb-access-logs").
This is a bug in the provider, which should be reported in the provider's own
issue tracker.
Error: Provider produced inconsistent final plan
When expanding the plan for module.aws_alb.aws_lb.alb to include new values
learned so far during apply, provider "registry.terraform.io/-/aws" produced
an invalid new value for .access_logs[0].prefix: was cty.StringVal(""), but
now cty.StringVal("aws-harri-test").
This is a bug in the provider, which should be reported in the provider's own
issue tracker.
As in the comments above, this only seems to happens when setting the bucket
from the id
attribute of an aws_s3_bucket
resource that is being created in the same terraform apply
. The second run where the referenced aws_s3_bucket
already exists during the plan stage is planned and applied correctly.
As mentioned in issue description, the below workaround do the job:
module 'aws_lb' {
...
access_logs = {
enabled = true
prefix = "my-prefix"
bucket = module.s3_logs_bucket.s3_bucket_id
}
depends_on = [module.s3_logs_bucket]
}
}
I experienced this issue using the terraform-aws-alb
module.
enabled
within the access_logs
block is interpreted based on the value not yet known before apply.
The fix was to explicitly set enabled
to true as follows:
I've attempted to reproduce this behavior with a configuration similar to that described in the original issue, and believe this has been resolved by upstream changes to Terraform core.
To allow time for feedback on the reproduction, we're going to leave this issue open for two weeks (until 2024-04-30). If no ongoing issues with the AWS provider are identified in this time, we'll close this issue as fixed upstream with https://github.com/hashicorp/terraform/pull/28424.
A reproduction is included below. Because the Terraform CLI and s3-bucket
module versions from the original report are now significantly outdated, I've instead used the latest available versions of each. This is version 1.8.0
of Terraform and 4.1.2
of the s3-bucket
module.
This section contains the configuration used for this reproduction.
This section contains the reproduction steps and relevant output.
Absent any concerns with this reproduction, we'll close this issue as fixed upstream on 2024-04-30.
Closing as fixed upstream in Terraform core.
[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.
Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
We are utilizing a Module with an ALB which exposes the ability to add
access_logs
based upon a variable. To populate the parameters thelookup
function is used on the optional parameters such asenabled
andprefix
. When the lookup function is used on theenabled
parameter thebucket
parameter is not populated in theterraform plan
.We have a work around which consists of setting the
enabled
parameter totrue
in the module.Community Note
Terraform CLI and Terraform AWS Provider Version
Terraform v0.13.5
Affected Resource(s)
Terraform Configuration Files
Calling Terraform
Module
Debug Output
https://gist.github.com/duganth-va/586335f45db17f46a48059a4d4f186b6
Expected Behavior
Actual Behavior
Running terraform plan results in the following output
Running Terraform apply results in:
Steps to Reproduce
terraform plan
terraform apply
Important Factoid
This was tested on Gov Cloud.