Skip to content

Commit

Permalink
Merge pull request #39413 from hashicorp/b-lb-listener-import-arti
Browse files Browse the repository at this point in the history
elbv2/listener,target_group: Fix import differences, zero-values for absent values
  • Loading branch information
YakDriver authored Sep 20, 2024
2 parents 8357549 + 406bb69 commit bb0238c
Show file tree
Hide file tree
Showing 10 changed files with 633 additions and 371 deletions.
31 changes: 31 additions & 0 deletions .changelog/39413.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
```release-note:bug
resource/aws_lb_listener_rule: Fix several of the arguments to avoiding setting zero-values in situations where they shouldn't causing warnings and import differences
```

```release-note:bug
resource/aws_lb_target_group: Fix several of the arguments to avoiding setting zero-values in situations where they shouldn't causing warnings and import differences
```

```release-note:bug
resource/aws_lb_listener: Fix several of the arguments to avoiding setting zero-values in situations where they shouldn't causing warnings and import differences
```

```release-note:bug
resource/aws_lb_listener: Remove the limitation preventing setting both default_action.0.target_group_arn and default_action.0.forward to align with the AWS API which allows you to specify both a target group list and a top-level target group ARN if the ARNs match
```

```release-note:note
resource/aws_lb_listener: When importing a listener that has either a default action top-level target group ARN or a default action defining a forward action defining a target group with an ARN, include both in the configuration to avoid import differences
```

```release-note:bug
resource/aws_alb_listener: Fix several of the arguments to avoiding setting zero-values in situations where they shouldn't causing warnings and import differences
```

```release-note:bug
resource/aws_alb_listener: Remove the limitation preventing setting both default_action.0.target_group_arn and default_action.0.forward to align with the AWS API which allows you to specify both a target group list and a top-level target group ARN if the ARNs match
```

```release-note:note
resource/aws_alb_listener: When importing a listener that has either a default action top-level target group ARN or a default action defining a forward action defining a target group with an ARN, include both in the configuration to avoid import differences
```
61 changes: 61 additions & 0 deletions internal/acctest/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package acctest

import (
"errors"
"fmt"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

// ComposeAggregateImportStateCheckFunc lets you compose multiple ImportStateCheckFunc into
// a single ImportStateCheckFunc.
func ComposeAggregateImportStateCheckFunc(fs ...resource.ImportStateCheckFunc) resource.ImportStateCheckFunc {
return func(is []*terraform.InstanceState) error {
var result []error

for i, f := range fs {
if err := f(is); err != nil {
result = append(result, fmt.Errorf("Import check %d/%d error: %w", i+1, len(fs), err))
}
}

return errors.Join(result...)
}
}

func ImportCheckResourceAttr(key, expected string) resource.ImportStateCheckFunc {
return func(is []*terraform.InstanceState) error {
if len(is) != 1 {
return fmt.Errorf("Attribute '%s' expected 1 instance state, got %d", key, len(is))
}

rs := is[0]
if rs.Attributes[key] != expected {
return fmt.Errorf("Attribute '%s' expected %s, got %s", key, expected, rs.Attributes[key])
}
return nil
}
}

func ImportCheckResourceAttrSet(key string, set bool) resource.ImportStateCheckFunc {
return func(is []*terraform.InstanceState) error {
if len(is) != 1 {
return fmt.Errorf("Attribute '%s' expected 1 instance state, got %d", key, len(is))
}

rs := is[0]
if set && rs.Attributes[key] == "" {
return fmt.Errorf("Attribute '%s' expected to be set, got not set", key)
}

if !set && rs.Attributes[key] != "" {
return fmt.Errorf("Attribute '%s' expected to be not set, got set (%s)", key, rs.Attributes[key])
}

return nil
}
}
Loading

0 comments on commit bb0238c

Please sign in to comment.