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

[New Resource] : aws_globalaccelerator_cross_account_attachment #35991

Merged
merged 36 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b10ba5e
cross account attachment resource
kathmbeck Feb 26, 2024
ec3ff8d
address feedback
kathmbeck Feb 26, 2024
74f7d3c
linter fixes
kathmbeck Feb 27, 2024
dc8b9c7
comments, changelog
kathmbeck Feb 27, 2024
6f0d6c6
lint/semgrep
kathmbeck Apr 3, 2024
afe9198
naming, alphabetize feedback
kathmbeck Apr 10, 2024
060c260
Merge branch 'main' into HEAD
ewbankkit Apr 22, 2024
b448a48
Fix tfproviderdocs 'import section code block text should contain res…
ewbankkit Apr 22, 2024
7961266
Fix markdown-lint 'MD009/no-trailing-spaces Trailing spaces [Expected…
ewbankkit Apr 22, 2024
174ff98
'internal/flex/Set' -> 'internal/types/Set'.
ewbankkit Apr 22, 2024
f2eef3f
Add 'TestSetDifference'.
ewbankkit Apr 22, 2024
aacd972
Complete 'internal/flex/Set' -> 'internal/types/Set'.
ewbankkit Apr 22, 2024
07f2d61
Add 'flex.DiffSlices'.
ewbankkit Apr 22, 2024
d5a1bf7
r/aws_globalaccelerator_cross_account_attachment: Tidy up.
ewbankkit Apr 22, 2024
50c5979
Acceptance test output:
ewbankkit Apr 22, 2024
9ba8e78
Correct CHANGELOG entry file name.
ewbankkit Apr 22, 2024
987e1b3
aws_eip: Add 'arn' attribute.
ewbankkit Apr 23, 2024
f180637
Acceptance test output:
ewbankkit Apr 23, 2024
5d275e4
r/aws_globalaccelerator_cross_account_attachment: Fixup acceptance te…
ewbankkit Apr 23, 2024
0b91099
globalaccelerator: Use AWS SDK for Go v2.
ewbankkit Apr 23, 2024
172661d
globalaccelerator: AWS SDK for Go v2 tagging codewq.
ewbankkit Apr 23, 2024
b52e889
Run 'make gen'.
ewbankkit Apr 23, 2024
4889af3
Run 'go get github.com/aws/aws-sdk-go-v2/service/globalaccelerator@v1…
ewbankkit Apr 23, 2024
2b33949
r/aws_globalaccelerator_accelerator: Migrate to AWS SDK for GO v2.
ewbankkit Apr 23, 2024
d91a0c4
d/aws_globalaccelerator_accelerator: Migrate to AWS SDK for GO v2.
ewbankkit Apr 23, 2024
5393e43
globalaccelerator: Migrate ARN helpers to AWS SDK for Go v2.
ewbankkit Apr 23, 2024
6a815b2
r/aws_globalaccelerator_listener: Migrate to AWS SDK for GO v2.
ewbankkit Apr 23, 2024
b5e99b1
r/aws_globalaccelerator_endpoint_group: Migrate to AWS SDK for GO v2.
ewbankkit Apr 23, 2024
3d4bedd
r/aws_globalaccelerator_custom_routing_listener: Migrate to AWS SDK f…
ewbankkit Apr 23, 2024
3500bd6
r/aws_globalaccelerator_custom_routing_accelerator: Migrate to AWS SD…
ewbankkit Apr 23, 2024
e88cd40
d/aws_globalaccelerator_custom_routing_accelerator: Migrate to AWS SD…
ewbankkit Apr 23, 2024
5f40b12
r/aws_globalaccelerator_custom_routing_endpoint_group: Migrate to AWS…
ewbankkit Apr 23, 2024
13e92ce
r/aws_globalaccelerator_cross_account_attachment: Migrate to AWS SDK …
ewbankkit Apr 23, 2024
ee9e525
globalaccelerator: Some clean up.
ewbankkit Apr 23, 2024
6aa0bbd
globalaccelerator: Migrate sweepers to AWS SDK for Go v2.
ewbankkit Apr 23, 2024
3577e15
globalaccelerator: Add 'NewClient'.
ewbankkit Apr 23, 2024
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
11 changes: 11 additions & 0 deletions .changelog/35991.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:new-resource
aws_globalaccelerator_cross_account_attachment
```

```release-note:enhancement
resource/aws_eip: Add `arn` attribute
```

```release-note:enhancement
data-source/aws_eip: Add `arn` attribute
```
41 changes: 23 additions & 18 deletions internal/flex/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package flex

import (
"fmt"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -413,24 +414,6 @@ func ResourceIdPartCount(id string) int {
return len(idParts)
}

type Set[T comparable] []T

// Difference find the elements in two sets that are not similar.
func (s Set[T]) Difference(ns Set[T]) Set[T] {
m := make(map[T]struct{})
for _, v := range ns {
m[v] = struct{}{}
}

var result []T
for _, v := range s {
if _, ok := m[v]; !ok {
result = append(result, v)
}
}
return result
}

// DiffStringMaps returns the set of keys and values that must be created, the set of keys
// and values that must be destroyed, and the set of keys and values that are unchanged.
func DiffStringMaps(oldMap, newMap map[string]interface{}) (map[string]*string, map[string]*string, map[string]*string) {
Expand Down Expand Up @@ -478,3 +461,25 @@ func DiffStringValueMaps(oldMap, newMap map[string]interface{}) (map[string]stri

return add, remove, unchanged
}

func DiffSlices[E any](old []E, new []E, eq func(E, E) bool) ([]E, []E, []E) {
// First, we're creating everything we have.
add := new

// Build the slices of what to remove and what is unchanged.
remove := make([]E, 0)
unchanged := make([]E, 0)
for _, e := range old {
eq := func(v E) bool { return eq(v, e) }
if !slices.ContainsFunc(new, eq) {
// Delete it!
remove = append(remove, e)
} else {
unchanged = append(unchanged, e)
// Already present, so remove from new.
add = slices.DeleteFunc(add, eq)
}
}

return add, remove, unchanged
}
59 changes: 59 additions & 0 deletions internal/flex/flex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,62 @@ func TestDiffStringValueMaps(t *testing.T) {
}
}
}

func TestDiffSlices(t *testing.T) {
t.Parallel()

type x struct {
A string
B int
}

cases := []struct {
Old, New []x
Create, Remove, Unchanged []x
}{
// Add
{
Old: []x{{A: "foo", B: 1}},
New: []x{{A: "foo", B: 1}, {A: "bar", B: 2}},
Create: []x{{A: "bar", B: 2}},
Remove: []x{},
Unchanged: []x{{A: "foo", B: 1}},
},
// Modify
{
Old: []x{{A: "foo", B: 1}},
New: []x{{A: "foo", B: 2}},
Create: []x{{A: "foo", B: 2}},
Remove: []x{{A: "foo", B: 1}},
Unchanged: []x{},
},
// Overlap
{
Old: []x{{A: "foo", B: 1}, {A: "bar", B: 2}},
New: []x{{A: "foo", B: 3}, {A: "bar", B: 2}},
Create: []x{{A: "foo", B: 3}},
Remove: []x{{A: "foo", B: 1}},
Unchanged: []x{{A: "bar", B: 2}},
},
// Remove
{
Old: []x{{A: "foo", B: 1}, {A: "bar", B: 2}},
New: []x{{A: "foo", B: 1}},
Create: []x{},
Remove: []x{{A: "bar", B: 2}},
Unchanged: []x{{A: "foo", B: 1}},
},
}
for _, tc := range cases {
c, r, u := DiffSlices(tc.Old, tc.New, func(x1, x2 x) bool { return x1.A == x2.A && x1.B == x2.B })
if diff := cmp.Diff(c, tc.Create); diff != "" {
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
}
if diff := cmp.Diff(r, tc.Remove); diff != "" {
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
}
if diff := cmp.Diff(u, tc.Unchanged); diff != "" {
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
}
}
}
3 changes: 2 additions & 1 deletion internal/framework/flex/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
itypes "github.com/hashicorp/terraform-provider-aws/internal/types"
)

func ExpandFrameworkStringSet(ctx context.Context, v basetypes.SetValuable) []*string {
Expand All @@ -20,7 +21,7 @@ func ExpandFrameworkStringSet(ctx context.Context, v basetypes.SetValuable) []*s
return output
}

func ExpandFrameworkStringValueSet(ctx context.Context, v basetypes.SetValuable) Set[string] {
func ExpandFrameworkStringValueSet(ctx context.Context, v basetypes.SetValuable) itypes.Set[string] {
var output []string

must(Expand(ctx, v, &output))
Expand Down
3 changes: 2 additions & 1 deletion internal/framework/flex/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
itypes "github.com/hashicorp/terraform-provider-aws/internal/types"
)

func TestExpandFrameworkStringSet(t *testing.T) {
Expand Down Expand Up @@ -68,7 +69,7 @@ func TestExpandFrameworkStringValueSet(t *testing.T) {

type testCase struct {
input types.Set
expected flex.Set[string]
expected itypes.Set[string]
}
tests := map[string]testCase{
"null": {
Expand Down
19 changes: 18 additions & 1 deletion internal/service/ec2/ec2_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
Expand Down Expand Up @@ -57,6 +58,10 @@ func resourceEIP() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"associate_with_private_ip": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -226,7 +231,9 @@ func resourceEIPRead(ctx context.Context, d *schema.ResourceData, meta interface
}

address := outputRaw.(*types.Address)
d.Set("allocation_id", address.AllocationId)
allocationID := aws.ToString(address.AllocationId)
d.Set("allocation_id", allocationID)
d.Set("arn", eipARN(meta.(*conns.AWSClient), allocationID))
d.Set("association_id", address.AssociationId)
d.Set("carrier_ip", address.CarrierIp)
d.Set("customer_owned_ip", address.CustomerOwnedIp)
Expand Down Expand Up @@ -405,3 +412,13 @@ func disassociateEIP(ctx context.Context, conn *ec2.Client, associationID string

return nil
}

func eipARN(c *conns.AWSClient, allocationID string) string {
return arn.ARN{
Partition: c.Partition,
Service: names.EC2,
Region: c.Region,
AccountID: c.AccountID,
Resource: "elastic-ip/" + allocationID,
}.String()
}
9 changes: 8 additions & 1 deletion internal/service/ec2/ec2_eip_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func dataSourceEIP() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"association_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -132,7 +136,9 @@ func dataSourceEIPRead(ctx context.Context, d *schema.ResourceData, meta interfa
}

if eip.Domain == types.DomainTypeVpc {
d.SetId(aws.ToString(eip.AllocationId))
allocationID := aws.ToString(eip.AllocationId)
d.SetId(allocationID)
d.Set("arn", eipARN(meta.(*conns.AWSClient), allocationID))

addressAttr, err := findEIPDomainNameAttributeByAllocationID(ctx, conn, d.Id())

Expand All @@ -146,6 +152,7 @@ func dataSourceEIPRead(ctx context.Context, d *schema.ResourceData, meta interfa
}
} else {
d.SetId(aws.ToString(eip.PublicIp))
d.Set("arn", nil)
d.Set("ptr_record", nil)
}
d.Set("association_id", eip.AssociationId)
Expand Down
1 change: 1 addition & 0 deletions internal/service/ec2/ec2_eip_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestAccEC2EIPDataSource_filter(t *testing.T) {
{
Config: testAccEIPDataSourceConfig_filter(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "id", resourceName, "id"),
resource.TestCheckResourceAttrPair(dataSourceName, "public_dns", resourceName, "public_dns"),
resource.TestCheckResourceAttrPair(dataSourceName, "public_ip", resourceName, "public_ip"),
Expand Down
1 change: 1 addition & 0 deletions internal/service/ec2/ec2_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestAccEC2EIP_basic(t *testing.T) {
Config: testAccEIPConfig_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckEIPExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttrSet(resourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "domain", "vpc"),
resource.TestCheckResourceAttr(resourceName, "ptr_record", ""),
resource.TestCheckResourceAttrSet(resourceName, "public_ip"),
Expand Down
Loading
Loading