hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.09k forks source link

[Bug]: aws_lb_listener_rule reads in Weighted Forward actions when they're not defined in HCL #28129

Open leslie-alldridge opened 1 year ago

leslie-alldridge commented 1 year ago

Terraform Core Version

1.3.5

AWS Provider Version

4.40.0

Affected Resource(s)

lb_listener_rule

Expected Behavior

We don't define any forward rules as they're Optional

Actual Behavior

We see Terraform has saved forward rules in the statefile and fails to clear them out safely on the next plan + apply.

We contacted AWS Support and they confirmed CodeDeploy has changed as of about a week ago.

Relevant Error/Panic Output Snippet

- forward {
        - stickiness {
        - duration = 0 -> null
        - enabled  = false -> null
        }
       - target_group {
           - arn    = "arn:aws:elasticloadbalancing:ap-southeast-2:xxx:targetgroup/xxx-t/123" -> null
           - weight = 0 -> null
         }
       - target_group {
           - arn    = "arn:aws:elasticloadbalancing:ap-southeast-2:xxx:targetgroup/xxx/123" -> null
           - weight = 100 -> null
         }
     }
 }

Error:

Error: modifying ELBv2 Listener (arn:aws:elasticloadbalancing:ap-southeast-2:xxx:listener/app/xxx-api/123/123): ValidationError: A target group ARN must be specified

### Terraform Configuration Files

resource "aws_lb_listener" "ssl" { load_balancer_arn = aws_lb.web.arn port = var.listener_port_ssl_test protocol = "HTTPS" certificate_arn = data.terraform_remote_state.acm.outputs ssl_policy = var.listener_ssl_policy

default_action { target_group_arn = var.target_group_arn type = "forward" }

lifecycle { ignore_changes = [default_action.0.target_group_arn] } }



### Steps to Reproduce

You will need to manage target groups in Terraform and then carry out a BlueGreen CodeDeploy deployment for your service. 

CodeDeploy will create two forward rules one being 0% and the other 100%.

On your next plan and apply in Terraform it'll fail and you'll be stuck unless you ignore changes on the forward rules.

### Debug Output

_No response_

### Panic Output

_No response_

### Important Factoids

_No response_

### References

_No response_

### Would you like to implement a fix?

No
github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

hknoa1729 commented 1 year ago

@leslie-alldridge Any update on this issue. I have 20 plus ECS services and I use code deploy with blue green to update service but no clue, why sometime it showing Target group ARN change to null.

hknoa1729 commented 1 year ago

@leslie-alldridge I found that whole forward object get added by codedeploy and it's not in terraform so If I add below lifecycle rules, then it works. Would it be valid way?

lifecycle { ignore_changes = [ default_action[0].target_group_arn, default_action[0].forward ] }

leslie-alldridge commented 1 year ago

Yes that's what I used as well