-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
elbv2/listener,target_group: Fix import differences, zero-values for absent values #39413
Conversation
Community NoteVoting for Prioritization
For Submitters
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
% make testacc PKG=elbv2 TESTS=TestAccELBV2Listener_forwardImport
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.7 test ./internal/service/elbv2/... -v -count 1 -parallel 20 -run='TestAccELBV2Listener_forwardImport' -timeout 360m
--- PASS: TestAccELBV2Listener_forwardImport (235.08s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/elbv2 240.222s
@@ -12,6 +12,8 @@ Provides a Load Balancer Listener resource. | |||
|
|||
~> **Note:** `aws_alb_listener` is known as `aws_lb_listener`. The functionality is identical. | |||
|
|||
~> **Note:** When importing a listener with a forward-type default action, if the default action contains a top-level target group ARN or a forward action with a target group ARN, you may need to include both in the configuration to avoid import differences. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to move this under the Import
heading?
This functionality has been released in v5.69.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Description
TL;DR
Importing setting absent values
When importing, the issue of incorrectly setting Go zero-values for absent values should be fixed for
aws_lb_listener
,aws_alb_listener
,aws_lb_target_group
, andaws_alb_target_group
. It is difficult to test for all situations so please open a new issue if you find new problems.Importing listeners with forward type default actions
During import, it's impossible to determine from AWS's response, the config, the state, or the plan whether the target group ARN was defined at the top level or within a forward action target group. AWS returns ARNs in both the default action (top-level) and in at least one forward action target group, regardless of whether a forward action target group is actually defined.
As a result, there was no clean way to fix this issue. However, as a workaround, we have removed the limitation preventing providing both
default_action.0.target_group_arn
anddefault_action.0.forward
. The AWS API allows this, stating: "You can specify both a target group list and a top-level target group ARN only if the ARNs match." As a result, for default action configurations with one target group, you can avoid import differences by defining ARNs in both places.Additional
One of the challenges we’re facing here is that what we send to AWS doesn’t always match perfectly with what AWS sends back to us. Let’s take the example of a listener’s default action.
When we send a default action that only includes
order
andtype
, AWS responds with additional information, like aforward
configuration. In most cases—during create, refresh, or update operations—we have access to the Terraform configuration and state, so we can work with this extra information and adjust things accordingly.However, during the import process, things are different. Since Terraform doesn’t have access to the configuration or state after an import (which we agree is not ideal and may be improved in future versions), it becomes difficult to handle this mismatch.
Here’s where the problem occurs: After an import, when we ask AWS for the listener’s default action, AWS sends back the
order
,type
,target_group_arn
, and aforward
configuration that also includes atarget_group_arn
. Without the original configuration or state, we’re left guessing what the config might have been so we can properly set up the state in Terraform.In most cases across the Terraform AWS provider, we can figure this out without any issues and everything matches up. But for listeners, we hit a scenario where it’s impossible to tell whether the Terraform configuration did or did not specify a
forward
. As a result, both thedefault_action
'starget_group_arn
and theforward
'starget_group_arn
are set. This matches what the API does.Our meager fix to this is to, like the API, allow setting ARNs in both places, as long as they match. This should only be necessary for configurations where 1) importing is a priority, and 2) you must avoid import differences.
Relations
Closes #37211
Closes #38861
References
Output from Acceptance Testing