Skip to content
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

Merged
merged 18 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading